mqtt

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 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.

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.

Below is the list of parameters that can appear in the messages received by the channel via mqtt protocol. In most parameters, the name consists of tags split by dots: tag1.tag2.tag3.tag4... Each tag defines a certain area of an application, e.g. any parameter that contains mileage data has the 'mileage' tag in the name and any parameter related to fuel control contains the 'fuel' tag. By default JSON fields of the message received by a channel via this protocol can only contain the below-specified parameters. Any additional parameter will be prefixed by the "custom" tag, e.g. "custom.unspecified-name".

Name Type Unit Description
channel.id number ID of channel that received a message
custom Any custom parameter
device.id number ID of device that received a message
device.name string Name of device that received a message
device.type.id number ID of device type of device that received a message
ident string Device unique identificator and optional password
protocol.id number ID of protocol
server.timestamp number seconds Timestamp when server received a message
timestamp number seconds Message timestamp
No results found.