Search code examples
mqttiot

Can MQTT be used to set data for an IoT device?


I know MQTT uses publish/subscribe, meaning all clients can pub/sub to any topic and all clients have to be connected to an MQTT broker.

Is it also good practice to use MQTT to set data for an IoT device?

Let's imagine the IoT device is a smart light which can be controlled via a web app. The web app will subscribe for the r/g/b values and the intensity and then visualize the values in the app.

But is it also good practice to set data via MQTT? Meaning the web app will then publish to the topic /deviceID/set/r/255 (or something like this) and only the IoT device subscribes to the topic /deviceID/set/#.

If this is not common practice what are the options? Do we have to implement multiple protocols for one IoT device?


Solution

  • It's perfectly valid to send configuration values to devices via MQTT as you describe. Just make sure that there's strong validation for these values to avoid any abuse or security issues.