Skip to content

The SmartFactroy_MQTTCommunication is an modular part of the SmartFactory Project. It establishes a WLAN-Communication with an MQTT-Broker and allows you to send and receive Messages.

License

Notifications You must be signed in to change notification settings

LMazzole/SmartFactory_MQTTCommunication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmartFactory_MQTTCommunication

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.

Table of contents

The SmartFactory project

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

Tools and technologies

The Source-code is written in C++. To achieve this project, the following tools and technologies were used.

Doxygen

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.

VSCode PlatformIO

The used IDE is VSCode with the PlatformIO-extension.

MQTT

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 ]

Circular buffer

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]

Documentation

Hardware

This code needs a WLAN-shield to function properly.
It's tested with a Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500 from Adafruit.

Software

All functions and files are documented on the GitHub-Page with Doxygen

Dependency graph

Click on the image to open doxygen-documentation.

External libraries:

Collaboration diagram

Click on the image to open doxygen-documentation.

Important functions and files

MQTTCommunication.h

The MQTTCommunication.h-file serves as interface. It provides the functions for:

  • Network-connection
  • MQTT-functionalities
  • access the message-storage (circular buffer)

CommunicationConfiguration.h

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

myJSONStr.h

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;
};

FAQ's

I'd like to use this code in my project. What do I need to know?

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.

Where can I change the configurations like MQTT-Broker IP and WLAN-Credentials?

All the Configuration data is stored in the CommunicationConfiguration.h file and can be edited there.

I'd like to change the incoming JSON-Message. How can I do that?

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.

ToDo's

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.

Contributors

Changelog

V 1.0 - Release BA FS19 - Luca Mazzoleni

License

MIT License

About

The SmartFactroy_MQTTCommunication is an modular part of the SmartFactory Project. It establishes a WLAN-Communication with an MQTT-Broker and allows you to send and receive Messages.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published