Question

I am trying to build a realtime mqtt applicationthat sends data from mobile devices to a backend that handles that data. How can I best implement an identification in these mqtt streams? I mean, how can I know what data is from which device/user? Should I make multiple streams or should I put a variable in the stream that identifies the user?

Was it helpful?

Solution

From what you are describing I would recommend to use a single topic for each mobile device.

  • devices/device1/data
  • devices/device1/status
  • devices/device2/data
  • devices/device2/status

When you do so, it is easy to get all data with a subscribe to devices/+/data. You can also use devices/+ directly if your client is only publishing data and you are not interested in other stuff. In you webbrowser or broker (see my answer to your other question) you get the message and you can determine with the topic, which client sent the message.

Another step to make the scenario more secure would be to allow device1 only to publish to devices/device1/#. This can be implemented through a plugin in the MQTT broker. An example for how easy it can be to implement such a plugin is shown here for the HiveMQ broker.

Hope this helps, Chris

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top