jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Disconnect after +/- 2 days #18

Closed jeroen84 closed 4 years ago

jeroen84 commented 4 years ago

Hello, I am using the free@home API quiet some time now, and basically since the beginning I experience disconnection from the sysapp after approximately 2 to 3 days. During the 2 to 3 days HA fires quiet some events to the sysapp, so I think it has nothing to do with inactivity. A restart of HA does the fix. In case of disconnect, the API respnses with slixmpp.xmlstream.xmlstream.NotConnectedError error.

Do any of you experience similar issues? I am thinking of adding a disconnect event handler, but first want to know if this could be fixed without coding.

jheling commented 4 years ago

Hello, I don't have the problem with the disconnect. Maybe the is something in your network that breaks the connection. The only problem I encountered whas that after a week or so the messages of the devices stopped comming back from the sysap. By defining a seperate user for each instance of HA (pi test, pi production_), it does not seem to happen anymore. Maybe a 'disconnect event handler' makes the api more robust.

crtee commented 4 years ago

I'm getting the same error after upgrading the SysAP firmware to the newest 2.3.0. Restarting HA fixes at least the connection problem for like 10 minutes, but there seems to be more broken than just that with the new Firmware.

jheling commented 4 years ago

I have just checked my version of the SysAP firmware and it is 2.2.4. Probably the problems started with a later version.

kaisten commented 4 years ago

Unfortunately I am facing the issues with the new version of the SysAP. Haven't had the time to investigate. Will try to flash the old firmware again

jeroen84 commented 4 years ago

Thanks, @jheling. I will first create separate users and debug. Nevertheless, a disconnect event handler does make the API more reliable. Let me get in direct contact with you for some questions regarding the structure of the code before starting to write.

As a side note, I am using version 2.2.4 of the sysap. Wondering what the issues are with 2.3.0.

jheling commented 4 years ago

@jeroen84, Ok, you can reach me with helingj at google mail.
@crtee,@kaisten. If you run the get-master-message.py in a normal python session, does the NotConnectedError also appear after a while?

kaisten commented 4 years ago

@jheling @jeroen84, thanks for assisting here is my output

INFO JID set to: xxx@bj.... INFO Rpc callback jhe ERROR Error handling {jabber:client}iq stanza Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 987, in _spawn_event handler.run(stanza) File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/handler/callback.py", line 76, in run self._pointer(payload) File "/usr/local/lib/python3.7/site-packages/slixmpp/stanza/iq.py", line 212, in callback_success callback(result) File "get-master-message.py", line 180, in rpc_callback args = xml2py(iq['rpc_query']['method_response']['params']) File "/usr/local/lib/python3.7/site-packages/slixmpp/plugins/xep_0009/binding.py", line 95, in xml2py for param in params.findall('{%s}param' % namespace): AttributeError: 'NoneType' object has no attribute 'findall' ERROR 'NoneType' object has no attribute 'findall' Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 987, in _spawn_event handler.run(stanza) File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/handler/callback.py", line 76, in run self._pointer(payload) File "/usr/local/lib/python3.7/site-packages/slixmpp/stanza/iq.py", line 212, in callback_success callback(result) File "get-master-message.py", line 180, in rpc_callback args = xml2py(iq['rpc_query']['method_response']['params']) File "/usr/local/lib/python3.7/site-packages/slixmpp/plugins/xep_0009/binding.py", line 95, in xml2py for param in params.findall('{%s}param' % namespace): AttributeError: 'NoneType' object has no attribute 'findall' ERROR not-allowed: WARNING You should catch IqError exceptions

jheling commented 4 years ago

@kaisten Have you used the latest version of get-master-message.py? Yesterday I uploaded a new version.

crtee commented 4 years ago

@jheling here's my debug output, using newest get-master-message.py:

DEBUG SEND: <iq id="9ce38b4f-a2b7-415a-91a7-f418e60a2f76-3" type="set" to="mrha@busch-jaEger.de/rpc" from="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@busch-jaeger.de/res-325-787428745-2044591730"><query xmlns="jabber:iq:rpc"><methodCall><methodName>RemoteInterface.getAll</methodName><params><param><value><string>de</string></value></param><param><value><i4>4</i4></value></param><param><value><i4>0</i4></value></param><param><value><i4>0</i4></value></param></params></methodCall></query></iq> DEBUG RECV: <iq id="9ce38b4f-a2b7-415a-91a7-f418e60a2f76-3" to="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@busch-jaeger.de/res-325-787428745-2044591730" from="mrha@busch-jaEger.de/rpc" type="error"><error type="cancel"><not-allowed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq> INFO Rpc callback jhe DEBUG SEND: <iq id="9ce38b4f-a2b7-415a-91a7-f418e60a2f76-3" to="mrha@busch-jaeger.de/rpc" type="error"><error type="cancel"><undefined-condition xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Slixmpp got into trouble.</text></error></iq> ERROR Error handling {jabber:client}iq stanza Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 987, in _spawn_event handler.run(stanza) File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/handler/callback.py", line 76, in run self._pointer(payload) File "/usr/local/lib/python3.7/site-packages/slixmpp/stanza/iq.py", line 212, in callback_success callback(result) File "get-master-message.py", line 180, in rpc_callback args = xml2py(iq['rpc_query']['method_response']['params']) File "/usr/local/lib/python3.7/site-packages/slixmpp/plugins/xep_0009/binding.py", line 95, in xml2py for param in params.findall('{%s}param' % namespace): AttributeError: 'NoneType' object has no attribute 'findall' ERROR 'NoneType' object has no attribute 'findall' Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/xmlstream.py", line 987, in _spawn_event handler.run(stanza) File "/usr/local/lib/python3.7/site-packages/slixmpp/xmlstream/handler/callback.py", line 76, in run self._pointer(payload) File "/usr/local/lib/python3.7/site-packages/slixmpp/stanza/iq.py", line 212, in callback_success callback(result) File "get-master-message.py", line 180, in rpc_callback args = xml2py(iq['rpc_query']['method_response']['params']) File "/usr/local/lib/python3.7/site-packages/slixmpp/plugins/xep_0009/binding.py", line 95, in xml2py for param in params.findall('{%s}param' % namespace): AttributeError: 'NoneType' object has no attribute 'findall' ERROR not-allowed: WARNING You should catch IqError exceptions DEBUG RECV: <iq id="stz36105" from="busch-jaeger.de" to="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@busch-jaeger.de/res-325-787428745-2044591730" type="get"><ping xmlns="urn:xmpp:ping" /></iq> DEBUG SEND: <iq id="stz36105" to="busch-jaeger.de" type="error"><error type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">No handlers registered for this request.</text></error></iq>

crtee commented 4 years ago

I was able to fix my disconnects (firmware 2.3.0) by adding self.register_plugin('xep_0199', {'keepalive': True, 'frequency': 60}) to the plugin list, this also fixes the last errror message in my debug output above. The resulting output:

DEBUG SEND: <iq id="stz36482" to="busch-jaeger.de" type="result" /> DEBUG RECV: <iq id="stz36502" from="busch-jaeger.de" to="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@busch-jaeger.de/res-325-471745961-1117229101" type="get"><ping xmlns="urn:xmpp:ping" /></iq> DEBUG Pinged by busch-jaeger.de DEBUG SEND: <iq id="stz36502" to="busch-jaeger.de" type="result" /> DEBUG Scheduled event: Whitespace Keepalive DEBUG SEND: DEBUG Scheduled event: Ping keepalive DEBUG Keepalive ping... DEBUG Pinging busch-jaeger.de DEBUG SEND: <iq id="aa394e5a-a959-4bd1-acf8-607508cb7880-5" type="get" to="busch-jaeger.de"><ping xmlns="urn:xmpp:ping" /></iq> DEBUG RECV: <iq id="aa394e5a-a959-4bd1-acf8-607508cb7880-5" to="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX@busch-jaeger.de/res-325-471745961-1117229101" from="busch-jaeger.de" type="result" /> DEBUG Pinged busch-jaeger.de, RTT: 0.011437654495239258 DEBUG Keepalive RTT: 0.011437654495239258

jheling commented 4 years ago

Nice, yesterday while digging through the documentation and sources of slixmmp, I saw that the ping, had a keepalive option. I'm glad it works. This evening, I will add it to the main branch.

kaisten commented 4 years ago

@jheling yes I did. It seems for me there is a api change with "findall". I will have a look again when i am back home

jheling commented 4 years ago

I have added the ping (xep_0199) line to pfreeathome.py in the master branch. I hope all the problems with the 2.3.0 firmware are now over.