I am creating a system based on a Thread-network in Python. I want to use pyzmq as my messaging foundation (especially the PUB/SUB). I am using a Raspberry Pi 4 with Debian GNU/Linux 11 (bullseye), the Thread Border Router implemantation from Goolge (OpenThread / OTBR) an the nRF52840 DK from Nordic Semiconductor as my Thread-antenna.
I can ping the interface from other Thread-devices and I can use it by directly binding a socket to it. But as soon as I try to bind a ZMQ socket to it, I get the error "No such device (addr='tcp://wpan0:5556')
".
ZMQ can bind without a problem to other interfaces of the Raspberry Pi (for example wlan0
or eth0
)
I tried to bind a ZMQ Socket like this:
self.ctx = zmq.Context()
self.xpub_sock = self.ctx.socket(zmq.XPUB)
self.xpub_sock.bind("tcp://" + self.ip + ":" + self.subport)
I tried to use wpan0 as a parameter for self.ip and also the IPv6 address of the wpan0
interface, both lead to the same error:
Traceback (most recent call last):
File "/home/pi/DAHS-MAS/zmqMessagingTest.py", line 35, in <module>
psp = PubSubProxy("wpan0", "5556", "5555", nodefinder)
File "/home/pi/DAHS-MAS/proxy.py", line 15, in __init__
self.xpub_sock.bind("tcp://" + self.ip + ":" + self.subport)
File "/usr/local/lib/python3.9/dist-packages/zmq/sugar/socket.py", line 302, in bind
super().bind(addr)
File "zmq/backend/cython/socket.pyx", line 564, in zmq.backend.cython.socket.Socket.bind
File "zmq/backend/cython/checkrc.pxd", line 28, in zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: No such device (addr='tcp://wpan0:5556')
When I directly create and bind a network socket on the wpan0 interface it works, so I expected that zmq will handle the interface without a problem.
It seems, I forgot to set the socket to IPv6, like this:
self.xpub_sock.setsockopt(zmq.IPV6, 1)
So if anyone is ever having a similar problem, with an interface that has ONLY IPv6 addresses, check again if you set the zmq.IPV6 constant on your created socket!