Native MQTT support on Onesait Platform
Another of the improvements that we have incorporated in version 5.0.0-Renegade of the Platform has been to support the MQTT protocol natively; that is, we allow communication through MQTT topics with the security of the Platform.
Up until now, the Platform’s Digital Broker only supported MQTT through the embedded MQTT Broker, by accessing through our SSAP messaging protocol that masks the base protocol (REST, WebSockets, MQTT, etc.).
Let’s see how you can use it.
Platform Configuration
The first step will be to access the Develop > My entities menu.
To enable the option of creating an MQTT topic, you can use either a new Entity or an existing one. Whatever the case, you will have to go to the «Advanced Settings» tab of the Entity and select the option «Allows to create an MQTT ingest topic for the Entity». When selecting it, a text box will be enabled so that you can customize the MQTT topic, where the name of the entity will be automatically added at the end.
The next step is create a Digital Client and give your Entity permissions -at least to write- to be able to insert data through the topic that you have just created.
MQTT client configuration
When connecting the MQTT client, you must configure the username and password that will correspond to the digital client/token that you have defined in the Platform.
Once the client is connected, you can:
- Publish messages on the topic associated with the entity: taking into account that the message that is published must be in JSON format and comply with the entity’s schema, otherwise the data will not be stored.
- Subscribe to the topic /<entity_topic>/<client_id>: the Platform will publish in this topic the responses to the publications:
- If the data has been inserted correctly, the ID of the data inserted in the Entity will be returned through this topic.
- If there has been some type of error in the insertion, the corresponding error message will be returned through this topic.
Below is a brief example of what an MQTT client would look like with the configuration described above: