Here is a quick overview, if anyone is interested I'll spend some time writing a tutorial.
1/ MQTT-SN
MQTT-SN can be seen as a lightweight MQTT protocol; practically speaking, it usually comes in the form on a gateway to a traditional MQTT broker.
Full specifications here:
This protocol is based on UDP.
On my side, I decided to use EMQX, a MQTT broker including the MQTT-SN gateway.
2/ UDP limitations on Loxone
Loxone has the following limitation on UDP usage: you can send an UDP message but you cannot receive a reply.
So the first problem I had to fix was how to setup a bidirectional UDP communication between Loxone and MQTT-SN, and for that I have used socat on my router.
Three lines:
(1) socat -u UDP4-LISTEN:7000,reuseaddr UDP-SENDTO:192.168.10.56:1883,sp=7010,reuseaddr&
(2) sleep 1
(3) socat -u UDP4-LISTEN:7010,reuseaddr,fork,max-children=1 UDP-SENDTO:192.168.10.131:7002&
Line #1 accepts UDP packets on the Gateway on UDP port 7000, and forwards them to the MQTT-SN UDP port, and defines the source port to some value, here 7010
Line #2 gives socat a breath before the second command
Line #3 accepts UDP packets on the UDP port mentioned on 1 (7010), and forward them to Loxone (192.168.10.131 in my case), on port 7002
(side note: I also use socat to integrate with my KNX router, without the need of that $$$$$$ Loxone KNX module:
socat UDP4-RECV:3671,bind=224.0.23.12,ip-add-membership=224.0.23.12:br3,reuseaddr UDP4-SENDTO:192.168.10.131:5555,ip-multicast-ttl=8 &)
3/ Protocol setup on Loxone
As seen on the picture, pretty simple:
- when Loxone starts, it first disconnect the previous connection with MQTT-SN, if any
- then, it connects to the MQTT-SN server and send a ping every X seconds
- and finally, it subscribes to the selected topics (one single topic on the picture).
One note on the topics: because of MQTT-SN specifications, you won't receive publications with the complete topic name, but rather a topic ID. So, on EMQX, you have to associate each topic you want to subscribe to, to a topic ID. For my example, I have selected topic 1 / ebusd_av/b7v00/z1RoomTemp.
Then on Loxone, you subscribe to topic 1.
4/ MQTT consumption on Loxone
Just open a Virtual UDP input with the port you have selected in step 2 on socat (7002 in my example), and parse the data, et voilà, I receive the temperature of my dining room every time it is published on MQTT.
Kommentar