-
-
Notifications
You must be signed in to change notification settings - Fork 112
FAQ6: Troubleshoot CoAP messages
For real-time updates in ShellyForHASS, CoAP messages must work in your network.
Every Shelly device sending CoAP messages when a state change and also regularly every 10-20 seconds. ShellyForHASS reads those messages and updates the device state in HA.
In HA every Shelly entry have a protocol attribute that shows what protocols used. If you see CoAP-msg in the list everything is working as it should and you have real-time updates working.
CoAP messages are UDP packages sent on port 5683 to the multicast address 224.0.1.187.
To test if you receive those messages on your HA computer you can use tcpdump.
tcpdump host 224.0.1.187
If this work you will see messages like this:
15:39:28.742201 IP shellydimmer-f3997d.5683 > 224.0.1.187.5683: UDP, length 182
15:39:28.886704 IP shellyht-58ecba.5683 > 224.0.1.187.5683: UDP, length 79
15:39:29.074122 IP shellyrgbw2-2bb0b3.5683 > 224.0.1.187.5683: UDP, length 137
15:39:30.260087 IP shelly1-1d8e16.5683 > 224.0.1.187.5683: UDP, length 64
If you did not get any result you can try this to listen on all interfaces:
tcpdump host -i any 224.0.1.187
If you can't see those messages from tcpdump it is because your AP, routers or switches blocking them. There is a protocol IGMP (Internet Group Management Protocol) that is used by routers to know how to forward multicasts. If IGMP snooping is disabled on the router the multicast should flood to all ports. If it is enabled the router listens to IP_ADD_MEMBERSHIP messages to know if there is a client waiting for the multicasts. So if the tcpdump not working it can depend on this and you can try the python script below that sending a IP_ADD_MEMBERSHIP request to the router. If the script not receiving any messages you can try the tcpdump after and see if you can see any messages there.
If you see those messages from tcpdump you know CoAP messages are received by HA computer. But you don't know if your firewall is open and let HA receive the messages.
To test if HA can receive the packages you can use the following python script. It send a IP_ADD_MEMBERSHIP request to the router and printing all CoAP messages received:
import socket
import struct
UDP_IP = "224.0.1.187"
UDP_PORT = 5683
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', UDP_PORT))
mreq = struct.pack("=4sl", socket.inet_aton(UDP_IP), socket.INADDR_ANY)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
while True:
data = sock.recv(10240)
print(data)
You can also try to enter your ip-address in the bind command: sock.bind(('1.2.3.4', UDP_PORT))
If this not working you can try to disable your firewall temporarily or open UDP port 5683 for incoming traffic. If you have multiple network interface on your HA computer you can try to modify the file above to use the right interface. There is lot of examples of this if you google "python IP_ADD_MEMBERSHIP".
If you using docker you can also try this script in HA docker container.
Join our Facebook group ShellyForHASS for support and information.