EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
GwOutput_MQTT Class Reference

#include <GwOutput_mqtt.h>

Inheritance diagram for GwOutput_MQTT:
GatewayOutput_generic

Public Member Functions

 GwOutput_MQTT ()
 Constructor to initialize MQTT client. More...
 
void configManagerStart (EnigmaIOTGatewayClass *enigmaIotGw)
 Called when wifi manager starts config portal. More...
 
void configManagerExit (bool status)
 Called when wifi manager exits config portal. More...
 
bool begin ()
 Starts output module. More...
 
bool loadConfig ()
 Loads output module configuration. More...
 
bool outputControlSend (char *address, uint8_t *data, size_t length)
 Send control data from nodes. More...
 
bool newNodeSend (char *address, uint16_t node_id)
 Send new node notification. More...
 
bool nodeDisconnectedSend (char *address, gwInvalidateReason_t reason)
 Send node disconnection notification. More...
 
bool outputDataSend (char *address, char *data, size_t length, GwOutput_data_type_t type=data)
 Send data from nodes. More...
 
void loop ()
 Should be called regularly for module management. More...
 
- Public Member Functions inherited from GatewayOutput_generic
void setDlCallback (onDlData_t cb)
 Set data processing function. More...
 

Protected Member Functions

bool saveConfig ()
 Saves output module configuration. More...
 
void reconnect ()
 This is called anytime MQTT client is disconnected. More...
 
bool addMQTTqueue (const char *topic, char *payload, size_t len, bool retain=false)
 Add MQTT message to queue. More...
 
mqtt_queue_item_tgetMQTTqueue ()
 Gets next item in the queue. More...
 
void popMQTTqueue ()
 Deletes next item in the queue. More...
 
bool publishMQTT (const char *topic, const char *payload, size_t len, bool retain=false)
 Publishes data over MQTT. More...
 

Static Protected Member Functions

static void onDlData (char *topic, uint8_t *data, unsigned int len)
 Function that processes downlink data from network to node. More...
 

Protected Attributes

AsyncWiFiManagerParameter * mqttServerParam
 Configuration field for MQTT server address. More...
 
AsyncWiFiManagerParameter * mqttPortParam
 Configuration field for MQTT server port. More...
 
AsyncWiFiManagerParameter * mqttUserParam
 Configuration field for MQTT server user name. More...
 
AsyncWiFiManagerParameter * mqttPassParam
 Configuration field for MQTT server password. More...
 
std::queue< mqtt_queue_item_t * > mqtt_queue
 Output MQTT messages queue. It acts as a FIFO queue. More...
 
mqttgw_config_t mqttgw_config
 MQTT server configuration data. More...
 
bool shouldSaveConfig = false
 Flag to indicate if configuration should be saved. More...
 
WiFiClient espClient
 TCP client. More...
 
PubSubClient mqtt_client
 MQTT client. More...
 
- Protected Attributes inherited from GatewayOutput_generic
EnigmaIOTGatewayClassenigmaIotGateway
 Pointer to EnigmaIOT gateway instance. More...
 
onDlData_t downlinkCb
 downlink processing function handle More...
 

Additional Inherited Members

- Public Attributes inherited from GatewayOutput_generic
String netName
 EnigmaIOT network name. More...
 
String clientId
 MQTT clientId. More...
 
String gwTopic
 MQTT topic for gateway. More...
 

Detailed Description

Definition at line 77 of file GwOutput_mqtt.h.

Constructor & Destructor Documentation

◆ GwOutput_MQTT()

GwOutput_MQTT::GwOutput_MQTT ( )
inline

Constructor to initialize MQTT client.

Definition at line 160 of file GwOutput_mqtt.h.

Member Function Documentation

◆ addMQTTqueue()

bool GwOutput_MQTT::addMQTTqueue ( const char *  topic,
char *  payload,
size_t  len,
bool  retain = false 
)
protected

Add MQTT message to queue.

Parameters
topicMQTT message topic
payloadMQTT message payload
lenMQTT payload length
retainMessage retain flag

Definition at line 460 of file GwOutput_mqtt.cpp.

◆ begin()

bool GwOutput_MQTT::begin ( )
virtual

Starts output module.

Returns
Returns true if successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 204 of file GwOutput_mqtt.cpp.

◆ configManagerExit()

void GwOutput_MQTT::configManagerExit ( bool  status)
virtual

Called when wifi manager exits config portal.

Parameters
statustrue if configuration was successful

Implements GatewayOutput_generic.

Definition at line 167 of file GwOutput_mqtt.cpp.

◆ configManagerStart()

void GwOutput_MQTT::configManagerStart ( EnigmaIOTGatewayClass enigmaIotGw)
virtual

Called when wifi manager starts config portal.

Parameters
enigmaIotGwPointer to EnigmaIOT gateway instance

Implements GatewayOutput_generic.

Definition at line 44 of file GwOutput_mqtt.cpp.

◆ getMQTTqueue()

mqtt_queue_item_t * GwOutput_MQTT::getMQTTqueue ( )
protected

Gets next item in the queue.

Returns
Next MQTT message to be sent

Definition at line 483 of file GwOutput_mqtt.cpp.

◆ loadConfig()

bool GwOutput_MQTT::loadConfig ( )
virtual

Loads output module configuration.

Returns
Returns true if load was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 102 of file GwOutput_mqtt.cpp.

◆ loop()

void GwOutput_MQTT::loop ( )
virtual

Should be called regularly for module management.

Implements GatewayOutput_generic.

Definition at line 414 of file GwOutput_mqtt.cpp.

◆ newNodeSend()

bool GwOutput_MQTT::newNodeSend ( char *  address,
uint16_t  node_id 
)
virtual

Send new node notification.

Parameters
addressNode Address
node_idNode Id
Returns
Returns true if sending was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 624 of file GwOutput_mqtt.cpp.

◆ nodeDisconnectedSend()

bool GwOutput_MQTT::nodeDisconnectedSend ( char *  address,
gwInvalidateReason_t  reason 
)
virtual

Send node disconnection notification.

Parameters
addressNode Address
reasonDisconnection reason code
Returns
Returns true if sending was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 642 of file GwOutput_mqtt.cpp.

◆ onDlData()

void GwOutput_MQTT::onDlData ( char *  topic,
uint8_t *  data,
unsigned int  len 
)
staticprotected

Function that processes downlink data from network to node.

Parameters
topicTopic that indicates message type
dataMessage payload
lenPayload length

Definition at line 364 of file GwOutput_mqtt.cpp.

◆ outputControlSend()

bool GwOutput_MQTT::outputControlSend ( char *  address,
uint8_t *  data,
size_t  length 
)
virtual

Send control data from nodes.

Parameters
addressNode Address
dataMessage data buffer
lengthData buffer length
Returns
Returns true if sending was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 533 of file GwOutput_mqtt.cpp.

◆ outputDataSend()

bool GwOutput_MQTT::outputDataSend ( char *  address,
char *  data,
size_t  length,
GwOutput_data_type_t  type = data 
)
virtual

Send data from nodes.

Parameters
addressNode Address
dataMessage data buffer
lengthData buffer length
typeType of message
Returns
Returns true if sending was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 510 of file GwOutput_mqtt.cpp.

◆ popMQTTqueue()

void GwOutput_MQTT::popMQTTqueue ( )
protected

Deletes next item in the queue.

Definition at line 491 of file GwOutput_mqtt.cpp.

◆ publishMQTT()

bool GwOutput_MQTT::publishMQTT ( const char *  topic,
const char *  payload,
size_t  len,
bool  retain = false 
)
protected

Publishes data over MQTT.

Parameters
topicTopic that indicates message type
payloadMessage payload data
lenPayload length
retaintrue if message should be retained

Definition at line 431 of file GwOutput_mqtt.cpp.

◆ reconnect()

void GwOutput_MQTT::reconnect ( )
protected

This is called anytime MQTT client is disconnected.

It tries to connect to MQTT broker. After reconnection is done it resubscribes to network topics. It waits for connection and times out after 5 seconds

Definition at line 231 of file GwOutput_mqtt.cpp.

◆ saveConfig()

bool GwOutput_MQTT::saveConfig ( )
protectedvirtual

Saves output module configuration.

Returns
Returns true if save was successful. false otherwise

Implements GatewayOutput_generic.

Definition at line 60 of file GwOutput_mqtt.cpp.

Member Data Documentation

◆ espClient

WiFiClient GwOutput_MQTT::espClient
protected

TCP client.

Definition at line 95 of file GwOutput_mqtt.h.

◆ mqtt_client

PubSubClient GwOutput_MQTT::mqtt_client
protected

MQTT client.

Definition at line 97 of file GwOutput_mqtt.h.

◆ mqtt_queue

std::queue<mqtt_queue_item_t*> GwOutput_MQTT::mqtt_queue
protected

Output MQTT messages queue. It acts as a FIFO queue.

Definition at line 84 of file GwOutput_mqtt.h.

◆ mqttgw_config

mqttgw_config_t GwOutput_MQTT::mqttgw_config
protected

MQTT server configuration data.

Definition at line 86 of file GwOutput_mqtt.h.

◆ mqttPassParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttPassParam
protected

Configuration field for MQTT server password.

Definition at line 82 of file GwOutput_mqtt.h.

◆ mqttPortParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttPortParam
protected

Configuration field for MQTT server port.

Definition at line 80 of file GwOutput_mqtt.h.

◆ mqttServerParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttServerParam
protected

Configuration field for MQTT server address.

Definition at line 79 of file GwOutput_mqtt.h.

◆ mqttUserParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttUserParam
protected

Configuration field for MQTT server user name.

Definition at line 81 of file GwOutput_mqtt.h.

◆ shouldSaveConfig

bool GwOutput_MQTT::shouldSaveConfig = false
protected

Flag to indicate if configuration should be saved.

Definition at line 87 of file GwOutput_mqtt.h.


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