moroen / IKEA-Tradfri-plugin

A Python plugin for Domoticz to controll IKEA Gateway
68 stars 23 forks source link

Issues with the API? Connection Timed out #102

Open Logonz opened 4 years ago

Logonz commented 4 years ago

It seems like the library has stopped working, i still get a response on setting of API but listing doesn't seem to return expected data. I had it running a raspberry pi that used the py library and then moved it to a regular server instead using coapcmd. It stopped working on both systems so it seems to stem from a deeper issue. I put in some printing to try and find the location of the issue.

Im setting the API key on startup of the docker container if that is causing any issues.

Log 1/2 is in coapcmd_api.py row 43-44 Log 3/4 is in device.py row 329-331-ish The 2 firsts are partially working startups but the third one is most common and the forth is a listing On the last one it seems to get the correct messages from the devicelisting but not the response from the item

**** Setting API Transport to coapcmd ****
domoticz             | **** Setting IP and API key ****
domoticz             | API-Key: PUafdfe
domoticz             | IP: 192.168.1.35
domoticz             | {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | **** Listing gateway connections ****
domoticz             | 15001
domoticz             | e3255e0b2f97dc3e605e993121 h4aykW5FiUm coaps://192.168.1.35:5684/15001
domoticz             | {'Status': 'ok', 'Result': '[65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]'}
domoticz             | [65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]
domoticz             | e3255e0c3e605e993121 h4aJTFiUm coaps://192.168.1.35:5684/15001
domoticz             | {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | 15001
domoticz             | e3255e0b2e993121 h4ayTFiUm coaps://192.168.1.35:5684/15001
domoticz             | {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | [custom-init] startup.sh: exited 0
domoticz             | [cont-init.d] 99-custom-files: exited 0.
domoticz             | [cont-init.d] done.

domoticz             | [custom-init] startup.sh: executing...
domoticz             | **** Setting API Transport to coapcmd ****
domoticz             | **** Setting IP and API key ****
domoticz             | API-Key: PUafcmfe
domoticz             | IP: 192.168.1.35
domoticz             | {'Status': 'ok', 'Result': '{"9091":"J3UqqeEdgRHMvYjj","9029":"1.10.0036"}'}
domoticz             | **** Listing gateway connections ****
domoticz             | Log3 15001
domoticz             | Log1 9dfe8a8045f4a5 J3UqqHMvYjj coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'ok', 'Result': '[65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]'}
domoticz             | Log4 [65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]
domoticz             | Log1 9dfe87be8045f4a5 J3UqMvYjj coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | Log3 15001
domoticz             | Log1 9dfe8a8045f4a5 J3UqqeHMvYjj coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'ok', 'Result': '[65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]'}
domoticz             | Log4 [65548,65540,65549,65542,65541,65547,65545,65538,65544,65536]
domoticz             | Log1 9dfe87bd2da9da8045f4a5 J3UqqMvYjj coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | [custom-init] startup.sh: exited 0
domoticz             | [cont-init.d] 99-custom-files: exited 0.

domoticz             | [cont-init.d] 99-custom-files: executing...
domoticz             | [custom-init] files found in /config/custom-cont-init.d executing
domoticz             | [custom-init] startup.sh: executing...
domoticz             | **** Setting API Transport to coapcmd ****
domoticz             | **** Setting IP and API key ****
domoticz             | API-Key: PUafXdcmfe
domoticz             | IP: 192.168.1.35
domoticz             | {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | **** Listing gateway connections ****
domoticz             | Log3 15001
domoticz             | Log1 25f069bf72365b4eba480 DWICgmcII coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | Log3 15001
domoticz             | Log1 25f069467265b4eba480 DWICmcII coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'HandshakeError', 'Result': ''}
domoticz             | Connection timed out
domoticz             | [custom-init] startup.sh: exited 0
domoticz             | [cont-init.d] 99-custom-files: exited 0.
domoticz             | [cont-init.d] done.

domoticz             | **** Listing gateway connections ****
domoticz             | Log3 15001
domoticz             | Log1 bbbbbab0a245ac8a8b eCTwiNSoVug coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'ok', 'Result': '[65545,65538,65547,65542,65541,65544,65549,65536,65540,65548]'}
domoticz             | Log4 [65545,65538,65547,65542,65541,65544,65549,65536,65540,65548]
domoticz             | Log1 bbbbbae5c0a245ac8a8b eCTwNSoVug coaps://192.168.1.35:5684/15001
domoticz             | Log2 {'Status': 'ok', 'Result': '[65545,65538,65547,65542,65541,65544,65549,65536,65540,65548]'}
domoticz             | Log1 bbbbbabe5c0a245ac8a8b eCTwiNSoVug coaps://192.168.1.35:5684/15001/65545
domoticz             | Log2 {'Status': 'HandshakeError', 'Result': ''}
moroen commented 4 years ago

Handshake errors usually means that the IDENT/PSK pair has been invalidated. I've no idea why the gateway suddenly invalidates one or more pairs, but it happens. This is not only an issue for this plugin, but also for the official IKEA app... Also see #99

So the first thing to do is to try generating a new IDENT/PSK-pair:

$ python3 plugin.py config IP MASTERKEY

If this doesn't work, make sure that the gateway IP is correct, and that you're able to ping the gateway. If it still fails, let me know and I'll investigate further!

Logonz commented 4 years ago

It seems that it is not working through docker and coapcmd, and i can't install py3coap because of CGO issues and the dockercontainer i am using due to alpine linux.

But it does work on my raspberry pi that use py3coap... which is very strange.

If you have any ideas on what to test i can try and figure out the issue. I am a senior programmer by trade so can even try and debug the issue but it would be nice to be pointed in a direction on where to start to look.

moroen commented 4 years ago

Does coapcmd work on your Pi as well? If it does, I would guess it might have something to do with the port configuration of the docker image? Can you ping the gateway from within the docker image? Have you tried using coapcmd directly on a command line in the docker image?

$ ./coapcmd get --ident IDENT --key KEY coaps://IP:5684/15001

You can use the ident/key from your working pi, you'll find the config in: /home/pi/.config/tradfri/gateway.json

NomNomSu commented 3 years ago

I may have similar issue but in my case it is not possible to connect on raspberry with pycoap. IP address is correct and pinging it gives me results, security key also is correct yet all the time there is connection timeout when trying command python3 plugin.py config IP KEY.

moroen commented 3 years ago

It works on my Raspberry, using the latest raspbian image, using both coapcmd and py3coap. Have you tried the precompiled binary of coapcmd?