The SmartFactroy_MQTTCommunication is an modular part of the SmartFactory project.
MQTTCommunication establishes a WLAN-connection and allows you to connect
with an MQTT-Broker to send and receive message.
Incomming messages need to be in a known JSON-format and will be converted into a struct.
These messages-structs are stored in a circular-buffer.
- The SmartFactory project
- Tools and technologies
- Documentation
- FAQ's
- ToDo's
- Contributors
- Changelog
- License
SmartFactory_MQTTCommunication is part of the SmartFactory-project. It provides a library with basic MQTT-Communication functions.
Other SmartFactory-components are:
A possible implementation of the SmartFactory-project can be seen in the Sortic-showcase:
The associated repositorys are:
SmartFactory-Sortic
SmartFactory_Box-Sortic
SmartFactory_Vehicle-Sortic
SmartFactory_Vehicle-Basis
SmartFactory_MQTTCommunication
The Source-code is written in C++. To achieve this project, the following tools and technologies were used.
Doxygen is used for the documentation of the source code.
An intorduction to Doxygen and how to install it can be found in the ArdFSM-Repo.
The used IDE is VSCode with the PlatformIO-extension.
MQTT (Message Queuing Telemetry Transport) is a lightweight publish-subscribe messaging protocol and requires a broker to relay the messages. It's used for M2M (machine-to-machine) communication.
An MQTT-system always consist of a broker and one or multiple clients, which can be either subscriber or publisher.
[Image: MQTT101 - Eclispe Foundation]
A client can subscribe and publish to one or multiple topics. Topics are organized in a tree similar to a folder-structure in Windows. Here's an example of how such a topic-tree and published message can look like:
This images also illustrates the scalability of MQTT appropriately.
For more Infos about MQTT and MQTT-topics check out the MQTT-Wiki on Github.
[Source: Wiki:MQTT, MQTT ]
A circular buffer or a ring-buffer uses an buffer with fixed Size. If the buffer is full the oldest element gets overwritten.
[Image: Wiki: Circular buffer]
This code needs a WLAN-shield to function properly.
It's tested with a Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500 from Adafruit.
All functions and files are documented on the GitHub-Page with Doxygen
Click on the image to open doxygen-documentation.
External libraries:
Click on the image to open doxygen-documentation.
The MQTTCommunication.h-file serves as interface. It provides the functions for:
- Network-connection
- MQTT-functionalities
- access the message-storage (circular buffer)
In the CommunicationConfiguration.h-file are all important settings defined:
- WLAN SSID
- WLAN password
- WLAN Shield pins
- MQTT Broker IP
- JSON parse size
- Cirrcular Buffer size
In the myJSONStr.h-file is defined how the JSON-message and hence the struct looks like.
This is how the JSON-message (received as String) can look like:
{
"id": "hostname",
"topic": "topic/topic",
"status": "driving",
"sector": "transit",
"line": 1,
"ack":"hostname",
"req":"hostname",
"cargo":"beer",
"token":false;
"error":false
}
And the corresponding struct in which the message gets parsed:
struct myJSONStr {
String id = "hostname";
String topic = "topic/topic";
String status = "driving";
String sector = "transit";
int line = 1;
String ack = "hostname";
String req = "hostname";
String cargo = "beer";
bool token = false;
bool error = false;
};
All you need to do is add the GitHub-Link to this Repo under lib_deps in your platformio.ini File and you're set up. All dependencies are downloaded automatic.
All the Configuration data is stored in the CommunicationConfiguration.h file and can be edited there.
Incoming messages need to be in a know JSON-Format which is defined in* myJSONStr.h* and needs to match the implementation in myJSON::parsingJSONToStruct. If you would like to change this format you need to adapt both files.
The open ToDo's can be found in the Documentation on the GitHub-Page
- Split the code in 2 repos: MQTTCommunication-Sortic and MQTTCommunication in order to increase reusability.
- Luca Mazzoleni
- Luciano Bettinaglio
V 1.0 - Release BA FS19 - Luca Mazzoleni
MIT License