flespi MQTT channel protocol by Gurtam is used to receive messages directly from MQTT broker.
Expected MQTT message payload should be a valid JSON object or an array with objects. Each message should be identified by an ident value either placed into the message JSON payload or into the topic of the incoming message. In the first case, you can set another field to use as an ident in the channel configuration. In the second case, you can use a specific topic component as an ident value.
Other JSON object attributes like "timestamp", "position.latitude", "position.longitude" are optional. Check other protocols for suggested attribute names and values. The value of "timestamp" property (if present) should be a number with Unix time, or UTC time string in full ISO 8601 format (YYYY-MM-DDThh:mm:ss). You may configure custom parameters conversion scheme in the channel configuration.
To use flespi MQTT broker as a central hub between IoT devices, smart sensors or custom platforms publishers and channel subscriber, follow these steps:
- Come up with a unique topic where you will publish messages, e.g. messages/[device].
- Create a flespi token with either no ACL or with MQTT ACL only and possibility to publish to messages/+. Use this token to connect publishers to flespi MQTT broker.
- Create another flespi token with either no ACL or with MQTT ACL only and possibility to subscribe to messages/+. Use this token to connect subscribers to flespi MQTT broker.
- You can test both tokens directly from the flespi MQTT Board tool: one page with the first token will publish messages and another page should subscribe to # and receive them.
- Then create a channel with MQTT protocol and configure it to connect to flespi MQTT broker: URI=mqtt.flespi.io:1883, username=2nd-token, topic=messages/+.
- Enable/start the channel and check in the Toolbox that you have no errors.
- Now you can publish messages from the first web-page or directly from your smart sensors, and the messages will appear in the channel and operate according to standard flespi telematics message pipeline — stored in the device, re-published, streamed, etc.
You can use just one token with no ACL for simplicity for both publisher and subscriber. Please look into the tokens ACL article for more information.
You may also use MQTT protocol to subscribe to messages from another flespi channel — just subscribe it to the correct topic, e.g. flespi/message/gw/#. See flespi MQTT API for more information.
You can now declare a custom naming scheme for the parameters in the MQTT message thus making it possible to adapt the naming notation to any format preferable for your project.