MQTT Communication
Smart Factory
Communication Class Reference

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

#include <MQTTCommunication.h>

Collaboration diagram for Communication:

Public Member Functions

 Communication (String Hostname)
 Construct a new Communication object. More...
 
void init ()
 Initializes the Hard- and Software for WLAN and MQTT-Connection. More...
 
bool loop ()
 This should be called regularly to allow the client to process incoming messages and maintain its connection to the server. More...
 
void printNetworkInfo ()
 
bool subscribe (const String topic)
 subsribes to MQTT topic on Server More...
 
bool unsubscribe (const String topic)
 unsubsribes from MQTT topic on Server More...
 
bool publishMessage (const String topic, const String msg)
 handles outgoing MQTT messages to Server More...
 
myJSONStr last ()
 Retriev data from the Tail (oldest Element) of the Buffer. More...
 
myJSONStr getElement (int x)
 Get the Element object. More...
 
myJSONStr pop ()
 Retriev data from the Tail (oldest Element) of the Buffer. More...
 
bool isEmpty ()
 Check if the Buffer is empty. More...
 
myJSONStr first ()
 Retriev data from the Head (newest Element) of the Buffer. More...
 
myJSONStr shift ()
 Retriev data from the Head (newest Element) of the Buffer. More...
 
int size ()
 returns the number of elements currently stored in the buffer More...
 
void clear ()
 resets the whole buffer to its initial state More...
 

Private Attributes

String pHostname
 
WiFiClient pClient = WiFiClient()
 instance of WiFiClient More...
 
Network pNetwork
 instance of Network More...
 
myMQTT pMymqtt
 instance of myMQTT More...
 
void(* funcPointer )(char *, unsigned char *, unsigned int) = callback
 functionpointer to callback-function More...
 

Detailed Description

The Connection-class provides the interface.

Definition at line 71 of file MQTTCommunication.h.

Constructor & Destructor Documentation

◆ Communication()

Communication::Communication ( String  Hostname)

Construct a new Communication object.

Definition at line 80 of file MQTTCommunication.cpp.

Member Function Documentation

◆ clear()

void Communication::clear ( )
inline

resets the whole buffer to its initial state

Definition at line 240 of file MQTTCommunication.h.

◆ first()

myJSONStr Communication::first ( )
inline

Retriev data from the Head (newest Element) of the Buffer.

This operation is non destructiv and the element will NOT be removed from the buffer Reading from an empty buffer is forbidden!!

Returns
myJSONStr - The Element at the Head

Definition at line 213 of file MQTTCommunication.h.

◆ getElement()

myJSONStr Communication::getElement ( int  x)
inline

Get the Element object.

Parameters
x-
Returns
myJSONStr -

Definition at line 181 of file MQTTCommunication.h.

◆ init()

void Communication::init ( )
inline

Initializes the Hard- and Software for WLAN and MQTT-Connection.

Definition at line 84 of file MQTTCommunication.h.

◆ isEmpty()

bool Communication::isEmpty ( )
inline

Check if the Buffer is empty.

Returns
true - if no data is stored in the buffer
false - if data is stored in the buffer

Definition at line 202 of file MQTTCommunication.h.

◆ last()

myJSONStr Communication::last ( )
inline

Retriev data from the Tail (oldest Element) of the Buffer.

This operation is non destructiv and the element will NOT be removed from the buffer Reading from an empty buffer is forbidden!!

Returns
myJSONStr - The Element at the Tail

Definition at line 171 of file MQTTCommunication.h.

◆ loop()

bool Communication::loop ( )
inline

This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.

Returns
true - he client is still connected
false - the client is no longer connected

Definition at line 97 of file MQTTCommunication.h.

◆ pop()

myJSONStr Communication::pop ( )
inline

Retriev data from the Tail (oldest Element) of the Buffer.

Cause the element being read to be removed from the buffer Reading from an empty buffer is forbidden!!

Returns
myJSONStr - The Element at the Tail

Definition at line 192 of file MQTTCommunication.h.

◆ printNetworkInfo()

void Communication::printNetworkInfo ( )
inline

Definition at line 106 of file MQTTCommunication.h.

◆ publishMessage()

bool Communication::publishMessage ( const String  topic,
const String  msg 
)
inline

handles outgoing MQTT messages to Server

Checks if the Board is connected to a newtork and reconects if not

Beware though that the default packet size supported by the PubSub client is 128 bytes. You can increase this limit by editing the value lof MQTT_MAX_PACKET_SIZE in PubSubClient.h

Parameters
topic- the topic to publish to (const char[])
msg- the message to publish (const char[])
Returns
true - publish succed
false - publish failes

Definition at line 157 of file MQTTCommunication.h.

◆ shift()

myJSONStr Communication::shift ( )
inline

Retriev data from the Head (newest Element) of the Buffer.

Cause the element being read to be removed from the buffer Reading from an empty buffer is forbidden!!

Returns
myJSONStr - The Element at the Head

Definition at line 223 of file MQTTCommunication.h.

◆ size()

int Communication::size ( )
inline

returns the number of elements currently stored in the buffer

Returns
int - Currently sotred elements

Definition at line 232 of file MQTTCommunication.h.

◆ subscribe()

bool Communication::subscribe ( const String  topic)
inline

subsribes to MQTT topic on Server

Checks if the Board is connected to a newtork and reconects if not Check if the client is connected to the server if not call connectToMQTT()

Parameters
topic- the topic to subscribe to (const char[])
Returns
true - sending the subscribe succeeded. The request completes asynchronously.
false - sending the subscribe failed, either connection lost, or message too large.

Definition at line 122 of file MQTTCommunication.h.

◆ unsubscribe()

bool Communication::unsubscribe ( const String  topic)
inline

unsubsribes from MQTT topic on Server

Checks if the Board is connected to a newtork and reconects if not Check if the client is connected to the server

Parameters
topic- the topic to unsubscribe from (const char[])
Returns
true - sending the unsubscribe succeeded. The request completes asynchronously.
false - sending the unsubscribe failed, either connection lost, or message too large.

Definition at line 137 of file MQTTCommunication.h.

Member Data Documentation

◆ funcPointer

void(* Communication::funcPointer) (char *, unsigned char *, unsigned int) = callback
private

functionpointer to callback-function

Definition at line 260 of file MQTTCommunication.h.

◆ pClient

WiFiClient Communication::pClient = WiFiClient()
private

instance of WiFiClient

Definition at line 246 of file MQTTCommunication.h.

◆ pHostname

String Communication::pHostname
private

Definition at line 245 of file MQTTCommunication.h.

◆ pMymqtt

◆ pNetwork

Network Communication::pNetwork
private

The documentation for this class was generated from the following files: