Warning: The gateway is not symetric ! Read below:
Your UDP message must be JSON formatted in this way:
{
"t":"<MQTT topic you want to publish to>"
"p": <your JSON escaped payload>
}
The gateway will relay your payload to the specified topic in a transparent fashion. Messages details (source port, ip) are not provided here to avoid tampering with the payload.
As MQTT protocol doesnt have a request/response conception, we also provide a way to reply to a message by wraping the source port and message payload and relaying to to topic "/IP/udp2mqtt".
To relay MQTT messages to UDP, you must explicitly send your MQTT message to topic "/IP/mqtt2udp". Your MQTT message must be JSON formatted in this way :
{
"payload":"<MQTT topic you want to publish to>"
"dst_port": <UDP destination port>
}
If you specify src_port instead of dst_port, it will use src_port+1 as a destination port.
Using two distinct ports allows using broadcasts for both thing->server and server->thing and still be able to differentiate both traffic type.
Please take a look at https://github.com/dzavalishin/mqtt_udp - a complete UDP based implementation of MQTT-based protocol