littleyoda / Home-Assistant-Tripower-X-MQTT

Script which reads out the current measured values of an inverter of the SMA Tripower x (STP XX-50) series and makes them available via MQTT Home Assistant.
The Unlicense
10 stars 3 forks source link

After 4 month: "[Errno 111] Connection refused" #6

Open Trashmee opened 1 year ago

Trashmee commented 1 year ago

Hi,

your script has worked like a charm for multiple month. Since yesterday I noticed missing updates in HomeAssistant. sma2mqtt 'restarts' itself every minute (and has been doing so).

When starting manually it seems like the http interface is not responding? https to the WebUI works fine, but I would not know how to restart the WebServer in the SMA w/o a full powercyle, which I would like to avoid.

I'm not aware if this is due to an SMA update breaking functionalliy - or the service hanging inside the SMA inverter.

Have you seen such behavior? Any clue to to recover? I'll stop the script overnight and see if recovery happens.

 /usr/bin/python3 /sma2mqtt/sma2mqtt.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 203, in _new_conn
    sock = connection.create_connection(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    raise err
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 395, in request
    self.endheaders()
  File "/usr/lib64/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib64/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/lib64/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 243, in connect
    self.sock = self._new_conn()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 218, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f856807cd60>: Failed to establish a new connection: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.177.30', port=80): Max retries exceeded with url: /api/v1/token (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f856807cd60>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/sma2mqtt/sma2mqtt.py", line 62, in <module>
    x = requests.post(loginurl, data = postdata, timeout=5)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.177.30', port=80): Max retries exceeded with url: /api/v1/token (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f856807cd60>: Failed to establish a new connection: [Errno 111] Connection refused'))
Trashmee commented 1 year ago

In here the only helpful comment seems to indicate that indeed a power cycle of the inverter would help. https://github.com/home-assistant/core/issues/84375

#  wget http://192.168.177.30/api/v1/token
--2023-08-02 17:29:17--  http://192.168.177.30/api/v1/token
Connecting to 192.168.177.30:80... failed: Connection refused.

#  ping -c 2 192.168.177.30
PING 192.168.177.30 (192.168.177.30) 56(84) bytes of data.
64 bytes from 192.168.177.30: icmp_seq=1 ttl=63 time=0.449 ms
64 bytes from 192.168.177.30: icmp_seq=2 ttl=63 time=0.500 ms
littleyoda commented 1 year ago

Could you try https instead of http?

Trashmee commented 1 year ago

Yes, did that but didn't mention, sorry:

This one works:

https://192.168.177.30 -> 
https://192.168.177.30/webui/Plant:1/dashboard

This one just runs into a timeout:

https://192.168.177.30/api/v1/token
No webpage was found for the web address: https://192.168.177.30/api/v1/token
Trashmee commented 1 year ago
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

This one feels familar (invalid certificate when pointing the script to https) - maybe i worked around that last time & the container got rebuild... ? I'll try to work around the certificate issue tonight.

Trashmee commented 1 year ago

Yes - issues seems my old brain. I think i had the same issue initially.

Talking to myself & your attention helped - thanks!

littleyoda commented 1 year ago

I can confirm that I now also have the error. Maybe an update of the firmware by SMA. I'll have a look at it in the next few days.

littleyoda commented 1 year ago

please try the new version.

It looks like SMA has deactivated the http access with the latest firmware version. I have now switched to https.

BTW: My inverter was updated 5 days ago. grafik

Trashmee commented 1 year ago

How did you handle the private SSL certificate? I'll check out - thanks for your quick support!

littleyoda commented 1 year ago

SSL/TLS checks deactivated. Not a great solution, but acceptable for me for connections in the local network.