![]() |
flux sdk
v01.02.02-3-g292b3a7
Embedded C++ SDK
|
One of the key features of the Flux Framework is it's simplified access to IoT service providers and servers. This document outlines how output from a Flux/DataLogger device is sent to an MQTT Broker.
The following is covered by this document:
MQTT connectivity allows data generated by the DataLogger/Flux framework to be published to an MQTT Broker under a user configured topic. MQTT is an extremely flexible and low overhead data protocol that is widely used in the IoT field.
The general use pattern for MQTT is that data is published to a topic on a MQTT broker. The data is then sent to any MQTT client that has subscribed to the specified topic.
A Flux Framework application (DataLogger IoT) supports MQTT connections, allowing an end user to enter the parameters for the particular MQTT Broker for the application to publish data to. When the application outputs data to the broker, the Flux framework publishes the available information to the specified "topic" with the payload that is a JSON document.
Data is published to the MQTT broker as a JSON object, which contains a collection of sub-object. Each sub-object represents a data source in the Flux framework (sensor), and contains the current readings from that source.
The following is an n example of the data posted - note, this representation was "pretty printed" for readability.
To connect to a MQTT Broker, the following information is needed:
These values are set using the standard Flux/DataLogger methods - the interactive menu system, or a JSON file.
When the menu system for the MQTT connection is presented, the following options are displayed:
The options are:
At a minimum, the Port, Server Name and Topic need to be set. What parameters are required depends on the settings of the broker being used.
If a secure connection is being used with the MQTT broker, use the
MQTT Secure Client
option of the Framework/Application. This option supports secure connectivity.
The
Buffer Size
option is dynamic by default, adapting to the size of the payload being sent. If runtime memory is a concern, set this value to a static size that supports the device operation.
Once all these values are set, the system will publish data to the specified MQTT Broker, following the JSON information structure noted earlier in this document.
If a JSON file is being used as an option to import settings into the Flux framework application/DataLogger, the following entries are used for the MQTT IoT connection:
Where:
Enabled
- set to true to enable the connectionPort
- Set to the broker portServer
- The MQTT broker serverMQTT Topic
- The topic to publish toClient Name
- optional client nameBuffer Size
- internal transfer buffer sizeUsername
- Broker user name if being usedPassword
- Broker password if being usedUse of a MQTT connection is fairly straightforward - just requiring the entry of broker details into the connection settings.
To test the connection, you need a MQTT broker available. A quick method to setup a broker is by installing the mosquitto
package on a Raspberry Pi computer. Our basic MQTT Tutorial provides some basic setup for a broker. This MQTT Broker Tutorial has more details, covering the setup needed for modern mosquitto configurations.
And once the broker is setup, the messages published by the IoT sensor are visible using the mosquitto_sub
command as outlined. For example to view messages posted to a the topic "/datalogger/logger1", the following command is used:
This assumes the MQTT broker is running on the same machine, and using the default port number.
To add an MQTT IoT device as a destination for the output of a Flux Framework based system, the application being created needs the following:
For this example, we show out to connect the output of a data logger in the framework to the MQTT IoT device.
First - add an MQTT IoT framework to your object
During the setup of the framework - at initialization, the following steps finish the basic setup of the MQTT object.