EnigmaIOT  0.9.8
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 setClock ()
 Synchronizes time over NTP to check certifitate expiration time. 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 = NULL
 Configuration field for MQTT server address. More...
 
AsyncWiFiManagerParameter * mqttPortParam = NULL
 Configuration field for MQTT server port. More...
 
AsyncWiFiManagerParameter * mqttUserParam = NULL
 Configuration field for MQTT server user name. More...
 
AsyncWiFiManagerParameter * mqttPassParam = NULL
 Configuration field for MQTT server password. More...
 
EnigmaIOTRingBuffer< mqtt_queue_item_tmqtt_queue
 
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 85 of file GwOutput_mqtt.h.

Constructor & Destructor Documentation

◆ GwOutput_MQTT()

GwOutput_MQTT::GwOutput_MQTT ( )
inline

Constructor to initialize MQTT client.

Definition at line 169 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 484 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 203 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 166 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 43 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 507 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 101 of file GwOutput_mqtt.cpp.

◆ loop()

void GwOutput_MQTT::loop ( )
virtual

Should be called regularly for module management.

Implements GatewayOutput_generic.

Definition at line 433 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 678 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 696 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 382 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 574 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 551 of file GwOutput_mqtt.cpp.

◆ popMQTTqueue()

void GwOutput_MQTT::popMQTTqueue ( )
protected

Deletes next item in the queue.

Definition at line 515 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 456 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 235 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 59 of file GwOutput_mqtt.cpp.

◆ setClock()

void GwOutput_MQTT::setClock ( )
protected

Synchronizes time over NTP to check certifitate expiration time.

Definition at line 467 of file GwOutput_mqtt.cpp.

Member Data Documentation

◆ espClient

WiFiClient GwOutput_MQTT::espClient
protected

TCP client.

Definition at line 104 of file GwOutput_mqtt.h.

◆ mqtt_client

PubSubClient GwOutput_MQTT::mqtt_client
protected

MQTT client.

Definition at line 106 of file GwOutput_mqtt.h.

◆ mqtt_queue

EnigmaIOTRingBuffer<mqtt_queue_item_t> GwOutput_MQTT::mqtt_queue
protected

Definition at line 93 of file GwOutput_mqtt.h.

◆ mqttgw_config

mqttgw_config_t GwOutput_MQTT::mqttgw_config
protected

MQTT server configuration data.

Definition at line 95 of file GwOutput_mqtt.h.

◆ mqttPassParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttPassParam = NULL
protected

Configuration field for MQTT server password.

Definition at line 90 of file GwOutput_mqtt.h.

◆ mqttPortParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttPortParam = NULL
protected

Configuration field for MQTT server port.

Definition at line 88 of file GwOutput_mqtt.h.

◆ mqttServerParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttServerParam = NULL
protected

Configuration field for MQTT server address.

Definition at line 87 of file GwOutput_mqtt.h.

◆ mqttUserParam

AsyncWiFiManagerParameter* GwOutput_MQTT::mqttUserParam = NULL
protected

Configuration field for MQTT server user name.

Definition at line 89 of file GwOutput_mqtt.h.

◆ shouldSaveConfig

bool GwOutput_MQTT::shouldSaveConfig = false
protected

Flag to indicate if configuration should be saved.

Definition at line 96 of file GwOutput_mqtt.h.


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