Is it possible to get deviceid from publisher and use this as a variable in a topic in a bridge configuration?
frodecat opened this issue · 2 comments
Hi,
If you want to forward an incoming message to another broker when using bridge configuration, there is a variable called "node" which you can use in the forwarding path. The "node" will give the name of the current Emqx broker.
But is it possible to get the actual deviceid(name) of the IoT device who published a message to the broker and use this variable in the forwarding topic path?
The Azure IoT Hub has this mandatory path for incoming mqtt messages: "devices/deviceid/messages/events". If the IoT devicename was "myIoTdevice" then it would be "devices/myIoTdevice/messages/events".
It would be incredibly helpful if it was possible to read the incoming deviceid and put that in this forwarding path. In example: "/devices/${deviceid}/messages/events". Then we could forward to the correct device in the Azure IoT bridge.
Instead now we have to use only one specific device and let all devices messages going to the Emqx mqtt broker bridge be truncated to this single iot-device name at the Azure IoT Hub and then have to sort out the correct device from the message in some backend afterwards.
Thanks,
Frode
You can probably use the wildcard. Either "/devices/+/messages/events" or "/devices/#".
You can probably use the wildcard. Either "/devices/+/messages/events" or "/devices/#".
Thank you for replying! Yes, that should theoretically solve my initial question.
However I forgot about the Azure authentication part. Now I use a single device in Azure IoT Hub and bridge towards that using clientid, username and certificate (could probably go with password instead of client certificate). But this authentication is only for this single device. So I can only truncate all messages through this 1 device and I can only listen for messages from this single device due to not having permission for the other devices.
So the big question is how Emqx can bridge to Azure IoT in such a way that it can forward messages to the many individual IoT Hub devices and not just to 1 device.
Maybe the access policy "iothubowner" could be used, but since this is more of a user/password thing and not a physical device, what would I put as "deviceid" ? I have tried several combinations of deviceid, user and password, but have yet to be able to get the bridge to authenticate using iothubowner.
Is there anyone who has managed to configure this? Emqx bridge to Azure IoT Hub and transparently sending messages to the correct devices and not just to 1 device ?
Thanks,
Frode