|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
11 #ifndef _GWOUTPUT_MQTT_h
12 #define _GWOUTPUT_MQTT_h
14 #if defined(ARDUINO) && ARDUINO >= 100
21 #include <ESPAsyncWiFiManager.h>
23 #include <PubSubClient.h>
27 #include <WiFiClientSecure.h>
29 #include <WiFiClient.h>
32 #define MQTT_BUFFER_SIZE 2048
35 #define GET_VERSION "get/version"
36 #define GET_VERSION_ANS "result/version"
37 #define GET_SLEEP "get/sleeptime"
38 #define GET_SLEEP_ANS "result/sleeptime"
39 #define SET_SLEEP "set/sleeptime"
40 #define SET_OTA "set/ota"
41 #define SET_OTA_ANS "result/ota"
42 #define SET_IDENTIFY "set/identify"
43 #define SET_RESET_CONFIG "set/reset"
44 #define SET_RESET_ANS "result/reset"
45 #define GET_RSSI "get/rssi"
46 #define GET_RSSI_ANS "result/rssi"
47 #define GET_NAME "get/name"
48 #define SET_NAME "set/name"
49 #define GET_NAME_ANS "result/name"
50 #define SET_USER_DATA "set/data"
51 #define GET_USER_DATA "get/data"
52 #define RESTART_NOTIF "restart"
53 #define NODE_DATA "data"
54 #define LOST_MESSAGES "debug/lostmessages"
55 #define NODE_STATUS "status"
56 #define GW_STATUS "/gateway/status"
57 #define SET_RESTART_MCU "set/restart"
101 BearSSL::X509List certificate;
105 #endif // SECURE_MQTT
135 bool addMQTTqueue (
const char* topic,
char* payload,
size_t len,
bool retain =
false);
155 bool publishMQTT (
const char* topic,
const char* payload,
size_t len,
bool retain =
false);
163 static void onDlData (
char* topic, uint8_t*
data,
unsigned int len);
171 #if defined ESP8266 && defined SECURE_MQTT
172 certificate (DSTroot_CA),
215 bool newNodeSend (
char* address, uint16_t node_id);
235 #if SUPPORT_HA_DISCOVERY
244 bool rawMsgSend (
const char* topic,
char* payload,
size_t len,
bool retain);
255 #endif // _GWOUTPUT_MQTT_h
bool nodeDisconnectedSend(char *address, gwInvalidateReason_t reason)
Send node disconnection notification.
void configManagerStart(EnigmaIOTGatewayClass *enigmaIotGw)
Called when wifi manager starts config portal.
AsyncWiFiManagerParameter * mqttPassParam
Configuration field for MQTT server password.
bool newNodeSend(char *address, uint16_t node_id)
Send new node notification.
Main gateway class. Manages communication with nodes and sends data to upper layer.
EnigmaIOTRingBuffer< mqtt_queue_item_t > mqtt_queue
Generic Gateway output module template.
void reconnect()
This is called anytime MQTT client is disconnected.
static void onDlData(char *topic, uint8_t *data, unsigned int len)
Function that processes downlink data from network to node.
AsyncWiFiManagerParameter * mqttPortParam
Configuration field for MQTT server port.
bool begin()
Starts output module.
void popMQTTqueue()
Deletes next item in the queue.
AsyncWiFiManagerParameter * mqttServerParam
Configuration field for MQTT server address.
void loop()
Should be called regularly for module management.
bool outputDataSend(char *address, char *data, size_t length, GwOutput_data_type_t type=data)
Send data from nodes.
constexpr auto MAX_MQTT_TOPIC_LEN
mqttgw_config_t mqttgw_config
MQTT server configuration data.
void setClock()
Synchronizes time over NTP to check certifitate expiration time.
bool shouldSaveConfig
Flag to indicate if configuration should be saved.
constexpr auto CONFIG_FILE
MQTT outout configuration file name.
void configManagerExit(bool status)
Called when wifi manager exits config portal.
mqtt_queue_item_t * getMQTTqueue()
Gets next item in the queue.
enum GwOutput_data_type GwOutput_data_type_t
bool outputControlSend(char *address, uint8_t *data, size_t length)
Send control data from nodes.
const time_t STATUS_SEND_PERIOD
GwOutput_MQTT()
Constructor to initialize MQTT client.
AsyncWiFiManagerParameter * mqttUserParam
Configuration field for MQTT server user name.
WiFiClient espClient
TCP client.
bool addMQTTqueue(const char *topic, char *payload, size_t len, bool retain=false)
Add MQTT message to queue.
constexpr auto MAX_MQTT_PLD_LEN
PubSubClient mqtt_client
MQTT client.
bool saveConfig()
Saves output module configuration.
static const size_t MAX_MQTT_QUEUE_SIZE
Maximum number of MQTT messages to be sent.
Library to build a gateway for EnigmaIoT system.
gwInvalidateReason_t
Key invalidation reason definition.
bool loadConfig()
Loads output module configuration.
bool publishMQTT(const char *topic, const char *payload, size_t len, bool retain=false)
Publishes data over MQTT.