MQTT Communication
Smart Factory
MQTTCommunication.h File Reference

The Connection-class is used as interface. More...

#include "Arduino.h"
#include "CommunicationConfiguration.h"
#include <CircularBuffer.h>
#include "Network/Network.h"
#include "myJSON/myJSON.h"
#include "myMQTT/myMQTT.h"
Include dependency graph for MQTTCommunication.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Communication
 The Connection-class provides the interface. More...
 

Functions

void callback (char *topic, byte *payload, unsigned int length)
 If the client is used to subscribe to topics, a callback function must be provided in the constructor. his function is called when new messages arrive at the client. More...
 

Variables

myJSON _myjson
 Declare a global variable from typ myJSON so it can be accessed in callback. More...
 
CircularBuffer< myJSONStr, MAX_JSON_MESSAGES_SAVED_buffer
 Declares a global Circular Buffer of type myJSONStr with max Elements of MAX_JSON_MESSAGES_SAVED. More...
 

Detailed Description

The Connection-class is used as interface.

Author
Luca Mazzoleni (luca..nosp@m.mazz.nosp@m.oleni.nosp@m.@hsr.nosp@m..ch)
Version
1.0 - added Connection-Implementation - Luca Mazzoleni (luca..nosp@m.mazz.nosp@m.oleni.nosp@m.@hsr.nosp@m..ch) - 2019-04-16
Date
2019-04-09
Todo:
Split the Code into two Repos: SmartFactory_Communication-Sortic
and SmartFactory_MQTTCommunication-Basis to simplify modular use.

Definition in file MQTTCommunication.h.

Function Documentation

◆ callback()

void callback ( char *  topic,
byte *  payload,
unsigned int  length 
)

If the client is used to subscribe to topics, a callback function must be provided in the constructor. his function is called when new messages arrive at the client.

Internally, the client uses the same buffer for both inbound and outbound messages. After the callback function returns, or if a call to either publish or subscribe is made from within the callback function, the topic and payload values passed to the function will be overwritten. The application should create its own copy of the values if they are required beyond this.

https://pubsubclient.knolleary.net/api.html#callback

This Function is global because you need to access it from a diffrent class and pass it as pointer. This would be possible if it's static but then all function which get called in callback need to be static too.

Parameters
topic- the topic the message arrived on (const char[])
payload- the message payload (byte array)
length- the length of the message payload (unsigned int)
Todo:
Change global implementation of callback. Maybe with static?

Definition at line 32 of file MQTTCommunication.cpp.

Variable Documentation

◆ _buffer

CircularBuffer<myJSONStr, MAX_JSON_MESSAGES_SAVED> _buffer

Declares a global Circular Buffer of type myJSONStr with max Elements of MAX_JSON_MESSAGES_SAVED.

When declaring your buffer you should specify the data type it must handle and the buffer capacity: those two parameters will influence the memory consumed by the buffer. https://github.com/rlogiacco/CircularBuffer

Declares a global Circular Buffer of type myJSONStr with max Elements of MAX_JSON_MESSAGES_SAVED.

Definition at line 26 of file MQTTCommunication.cpp.

◆ _myjson

myJSON _myjson

Declare a global variable from typ myJSON so it can be accessed in callback.

Declare a global variable from typ myJSON so it can be accessed in callback.