EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
EnigmaIOTGatewayMQTT.ino
Go to the documentation of this file.
1 
12 #include <Arduino.h>
13 
14 #define MQTT_MAX_PACKET_SIZE 2048
15 #include <PubSubClient.h>
16 #ifdef SECURE_MQTT
17 #include <WiFiClientSecure.h>
18 #else
19 #include <WiFiClient.h>
20 #endif // SECURE_MQTT
21 
22 #include <GwOutput_generic.h>
23 #include "GwOutput_mqtt.h"
24 
25 #ifdef ESP32
26 #include <WiFi.h>
27 #include <AsyncTCP.h> // Comment to compile for ESP8266
28 #include <Update.h>
29 #include <SPIFFS.h>
30 #include "esp_system.h"
31 #include "esp_event.h"
32 #include "esp_tls.h"
33 #include <ESPmDNS.h>
34 #include "soc/soc.h" // Disable brownout problems
35 #include "soc/rtc_cntl_reg.h" // Disable brownout problems
36 #elif defined(ESP8266)
37 #include <ESP8266WiFi.h>
38 //#include <ESPAsyncTCP.h> // Comment to compile for ESP32
39 #include <ESP8266mDNS.h>
40 #include <Hash.h>
41 #include <SPI.h>
42 #endif // ESP32
43 
44 #include <ArduinoOTA.h>
45 
46 #include <CayenneLPP.h>
47 #include <FS.h>
48 
49 #include <EnigmaIOTGateway.h>
50 #include <helperFunctions.h>
51 #include <debug.h>
52 #include <espnow_hal.h>
53 #include <Curve25519.h>
54 #include <ChaChaPoly.h>
55 #include <Poly1305.h>
56 #include <SHA256.h>
57 #include <ArduinoJson.h>
58 #include <DNSServer.h>
59 #include <ESPAsyncWebServer.h>
60 #include <ESPAsyncWiFiManager.h>
61 
62 //#define MEAS_TEMP // Temperature measurement for Gateway monitoring using DS18B20
63 
64 #ifdef MEAS_TEMP
65 #include <DallasTemperature.h>
66 #include <OneWire.h>
67 const time_t statusPeriod = 300 * 1000;
68 const int DS18B20_PIN = 16;
69 const int DS18B20_PREC = 12;
70 OneWire ow (DS18B20_PIN);
71 DallasTemperature ds18b20 (&ow);
72 DeviceAddress dsAddress;
73 float temperature;
74 #endif
75 
76 #ifndef LED_BUILTIN
77 #define LED_BUILTIN 5
78 #endif // BUILTIN_LED
79 
80 #define BLUE_LED LED_BUILTIN
81 #define RED_LED LED_BUILTIN
82 
83 #ifdef ESP32
84 TimerHandle_t connectionLedTimer;
85 #elif defined(ESP8266)
86 ETSTimer connectionLedTimer;
87 #endif // ESP32
88 
90 boolean connectionLedFlashing = false;
91 
92 void flashConnectionLed (void* led) {
93  //digitalWrite (*(int*)led, !digitalRead (*(int*)led));
94  digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN));
95 }
96 
97 void startConnectionFlash (int period) {
98 #ifdef ESP32
99  if (!connectionLedFlashing) {
100  connectionLedFlashing = true;
101  connectionLedTimer = xTimerCreate ("led_flash", pdMS_TO_TICKS (period), pdTRUE, (void*)0, flashConnectionLed);
102  xTimerStart (connectionLedTimer, 0);
103  }
104 #elif defined (ESP8266)
105  ets_timer_disarm (&connectionLedTimer);
106  if (!connectionLedFlashing) {
107  connectionLedFlashing = true;
108  ets_timer_arm_new (&connectionLedTimer, period, true, true);
109  }
110 #endif // ESP32
111 }
112 
114 #ifdef ESP32
115  if (connectionLedFlashing) {
116  connectionLedFlashing = false;
117  xTimerStop (connectionLedTimer, 0);
118  xTimerDelete (connectionLedTimer, 0);
119  }
120 #elif defined(ESP8266)
121  if (connectionLedFlashing) {
122  connectionLedFlashing = false;
123  ets_timer_disarm (&connectionLedTimer);
124  digitalWrite (connectionLed, LED_OFF);
125  }
126 #endif // ESP32
127 }
128 
130  // Port defaults to 3232
131  // ArduinoOTA.setPort(3232);
132 
133  // Hostname defaults to esp3232-[MAC]
134  ArduinoOTA.setHostname (EnigmaIOTGateway.getNetworkName ());
135 
136  // No authentication by default
137  ArduinoOTA.setPassword (EnigmaIOTGateway.getNetworkKey (true));
138 
139  // Password can be set with it's md5 value as well
140  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
141  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
142 
143  ArduinoOTA.onStart ([]() {
144  if (ArduinoOTA.getCommand () == U_FLASH) {
145  DEBUG_WARN ("Start updating sketch");
146  } else {// U_SPIFFS
147  DEBUG_WARN ("Start updating filesystem");
148  // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
149  }
150  });
151  ArduinoOTA.onEnd ([]() {
152  DEBUG_WARN ("OTA Finished");
153  });
154  ArduinoOTA.onProgress ([](unsigned int progress, unsigned int total) {
155  static bool printed = false;
156  unsigned int percent = progress / (total / 100);
157  digitalWrite (BLUE_LED, !digitalRead (BLUE_LED));
158  if (!(percent % 1)) {
159  //Serial.print ('.');
160  }
161  if (!(percent % 20) && !printed && percent != 0) {
162  DEBUG_WARN (" %d%%\n", percent);
163  printed = true;
164  } else if (percent % 20) {
165  printed = false;
166  }
167  if (progress == total) {
168  DEBUG_WARN ("OTA transfer finished");
169  }
170  });
171  ArduinoOTA.onError ([](ota_error_t error) {
172  DEBUG_WARN ("OTA Error[%u]: ", error);
173  if (error == OTA_AUTH_ERROR) { DEBUG_WARN ("OTA Auth Failed"); }
174  else if (error == OTA_BEGIN_ERROR) { DEBUG_WARN ("OTA Begin Failed"); }
175  else if (error == OTA_CONNECT_ERROR) { DEBUG_WARN ("OTA Connect Failed"); }
176  else if (error == OTA_RECEIVE_ERROR) { DEBUG_WARN ("OTA Receive Failed"); }
177  else if (error == OTA_END_ERROR) { DEBUG_WARN ("OTA End Failed"); }
178  });
179 
180  ArduinoOTA.begin ();
181 }
182 
183 void wifiManagerExit (boolean status) {
185 }
186 
189 }
190 
191 void processRxControlData (char* macStr, uint8_t* data, uint8_t length) {
192  if (data) {
193  GwOutput.outputControlSend (macStr, data, length);
194  }
195 }
196 
197 void processRxData (uint8_t* mac, uint8_t* buffer, uint8_t length, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char* nodeName = NULL) {
198  uint8_t* addr = mac;
199  size_t pld_size = 0;
200  const int PAYLOAD_SIZE = 1024; // Max MQTT payload in PubSubClient library normal operation.
201 
202  char payload[PAYLOAD_SIZE];
203 
204  char mac_str[ENIGMAIOT_ADDR_LEN * 3];
205  mac2str (addr, mac_str);
206 
207  if (control) {
208  processRxControlData (nodeName ? nodeName : mac_str, buffer, length);
209  return;
210  }
211  //char* netName = EnigmaIOTGateway.getNetworkName ();
212  if (payload_type == CAYENNELPP) {
213  DEBUG_INFO ("CayenneLPP message");
214  const int capacity = JSON_ARRAY_SIZE (25) + 25 * JSON_OBJECT_SIZE (4);
215  DynamicJsonDocument jsonBuffer (capacity);
216  JsonArray root = jsonBuffer.createNestedArray ();
217  CayenneLPP cayennelpp (MAX_DATA_PAYLOAD_SIZE);
218 
219  cayennelpp.decode ((uint8_t*)buffer, length, root);
220  uint8_t error = cayennelpp.getError ();
221  if (error != LPP_ERROR_OK) {
222  DEBUG_ERROR ("Error decoding CayenneLPP data: %d", error);
223  return;
224  }
225  pld_size = serializeJson (root, payload, PAYLOAD_SIZE);
226  } else if (payload_type == MSG_PACK) {
227  DEBUG_INFO ("MsgPack message");
228  const int capacity = JSON_ARRAY_SIZE (25) + 25 * JSON_OBJECT_SIZE (4);
229  DynamicJsonDocument jsonBuffer (capacity);
230  DeserializationError error = deserializeMsgPack (jsonBuffer, buffer, length);
231  if (error != DeserializationError::Ok) {
232  DEBUG_ERROR ("Error decoding MSG Pack data: %s", error.c_str ());
233  return;
234  }
235  pld_size = serializeJson (jsonBuffer, payload, PAYLOAD_SIZE);
236  } else if (payload_type == RAW) {
237  DEBUG_INFO ("RAW message");
238  if (length <= PAYLOAD_SIZE) {
239  memcpy (payload, buffer, length);
240  pld_size = length;
241  } else { // This will not happen but may lead to errors in case of using another physical transport
242  memcpy (payload, buffer, PAYLOAD_SIZE);
243  pld_size = PAYLOAD_SIZE;
244  }
245  }
246 
247  GwOutput.outputDataSend (nodeName ? nodeName : mac_str, payload, pld_size);
248  DEBUG_INFO ("Published data message from %s, length %d: %s, Encoding 0x%02X", nodeName ? nodeName : mac_str, pld_size, payload, payload_type);
249  if (lostMessages > 0) {
250  pld_size = snprintf (payload, PAYLOAD_SIZE, "%u", lostMessages);
251  GwOutput.outputDataSend (nodeName ? nodeName : mac_str, payload, pld_size, GwOutput_data_type::lostmessages);
252  DEBUG_INFO ("Published MQTT from %s: %s", nodeName ? nodeName : mac_str, payload);
253  }
254  pld_size = snprintf (payload, PAYLOAD_SIZE, "{\"per\":%e,\"lostmessages\":%u,\"totalmessages\":%u,\"packetshour\":%.2f}",
255  EnigmaIOTGateway.getPER ((uint8_t*)mac),
256  EnigmaIOTGateway.getErrorPackets ((uint8_t*)mac),
257  EnigmaIOTGateway.getTotalPackets ((uint8_t*)mac),
258  EnigmaIOTGateway.getPacketsHour ((uint8_t*)mac));
259  GwOutput.outputDataSend (nodeName ? nodeName : mac_str, payload, pld_size, GwOutput_data_type::status);
260  DEBUG_INFO ("Published MQTT from %s: %s", nodeName ? nodeName : mac_str, payload);
261 }
262 
263 void onDownlinkData (uint8_t* address, char* nodeName, control_message_type_t msgType, char* data, unsigned int len) {
264  uint8_t* buffer;
265  unsigned int bufferLen = len;
267 
268  if (nodeName) {
269  DEBUG_INFO ("DL Message for %s. Type 0x%02X", nodeName, msgType);
270  } else {
271  DEBUG_INFO ("DL Message for " MACSTR ". Type 0x%02X", MAC2STR (address), msgType);
272  }
273  DEBUG_DBG ("Data: %.*s Length: %d", len, data, len);
274 
275  if (msgType == USERDATA_GET || msgType == USERDATA_SET) {
276  const int capacity = JSON_ARRAY_SIZE (25) + 25 * JSON_OBJECT_SIZE (4);
277  DynamicJsonDocument json (capacity);
278  DeserializationError error = deserializeJson (json, data, len, DeserializationOption::NestingLimit (3));
279  if (error == DeserializationError::Ok) {
280  DEBUG_INFO ("JSON Message. Result %s", error.c_str ());
281  bufferLen = measureMsgPack (json) + 1; // Add place for \0
282  buffer = (uint8_t*)malloc (bufferLen);
283  bufferLen = serializeMsgPack (json, (char*)buffer, bufferLen);
284  encoding = MSG_PACK;
285  } else {
286  DEBUG_INFO ("Not JSON Message. Error %s", error.c_str ());
287  bufferLen++; // Add place for \0
288  buffer = (uint8_t*)malloc (bufferLen);
289  sprintf ((char*)buffer, "%.*s", len, data);
290  encoding = RAW;
291  }
292  } else {
293  bufferLen = len + 1;
294  buffer = (uint8_t*)calloc (sizeof (uint8_t), bufferLen);
295  memcpy (buffer, data, len);
296  }
297 
298 
299  if (!EnigmaIOTGateway.sendDownstream (address, (uint8_t*)buffer, bufferLen, msgType, encoding, nodeName)) {
300  if (nodeName) {
301  DEBUG_WARN ("Error sending esp_now message to %s", nodeName);
302  } else {
303  DEBUG_WARN ("Error sending esp_now message to " MACSTR, MAC2STR (address));
304  }
305  } else {
306  DEBUG_DBG ("Esp-now message sent or queued correctly");
307  }
308 
309  free (buffer);
310 }
311 
312 void newNodeConnected (uint8_t* mac, uint16_t node_id, char* nodeName = NULL) {
313 
314  //Serial.printf ("New node connected: %s\n", macstr);
315 
316  if (nodeName) {
317  if (!GwOutput.newNodeSend (nodeName, node_id)) {
318  DEBUG_WARN ("Error sending new node %s", nodeName);
319  } else {
320  DEBUG_DBG ("New node %s message sent", nodeName);
321  }
322  } else {
323  char macstr[ENIGMAIOT_ADDR_LEN * 3];
324  mac2str (mac, macstr);
325  if (!GwOutput.newNodeSend (macstr, node_id)) {
326  DEBUG_WARN ("Error sending new node %s", macstr);
327  } else {
328  DEBUG_DBG ("New node %s message sent", macstr);
329  }
330  }
331 
332 }
333 
334 void nodeDisconnected (uint8_t* mac, gwInvalidateReason_t reason) {
335  char macstr[ENIGMAIOT_ADDR_LEN * 3];
336  mac2str (mac, macstr);
337  //Serial.printf ("Node %s disconnected. Reason %u\n", macstr, reason);
338  if (!GwOutput.nodeDisconnectedSend (macstr, reason)) {
339  DEBUG_WARN ("Error sending node disconnected %s reason %d", macstr, reason);
340  } else {
341  DEBUG_DBG ("Node %s disconnected message sent. Reason %d", macstr, reason);
342  }
343 }
344 
345 //#ifdef ESP32
346 //void EnigmaIOTGateway_handle (void * param) {
347 // for (;;) {
348 // EnigmaIOTGateway.handle ();
349 // vTaskDelay (0);
350 // }
351 //}
352 //
353 //void GwOutput_handle (void* param) {
354 // for (;;) {
355 // GwOutput.loop ();
356 // vTaskDelay (0);
357 // }
358 //}
359 //
360 //TaskHandle_t xEnigmaIOTGateway_handle = NULL;
361 //TaskHandle_t gwoutput_handle = NULL;
362 //#endif // ESP32
363 
364 void setup () {
365  Serial.begin (115200); Serial.println (); Serial.println ();
366 
367 #ifdef ESP32
368 // Turn-off the 'brownout detector' to avoid random restarts during wake up,
369 // normally due to bad quality regulator on board
370  WRITE_PERI_REG (RTC_CNTL_BROWN_OUT_REG, 0);
371 #endif
372 
373 #ifdef ESP8266
374  ets_timer_setfn (&connectionLedTimer, flashConnectionLed, (void*)&connectionLed);
375 #elif defined ESP32
376 
377 #endif
378  pinMode (LED_BUILTIN, OUTPUT);
379  digitalWrite (LED_BUILTIN, LED_OFF);
380  startConnectionFlash (100);
381 
382 #ifdef MEAS_TEMP
383  ds18b20.begin ();
384  if (ds18b20.getDeviceCount () > 0) {
385  ds18b20.getAddress (dsAddress, 0);
386  DEBUG_INFO ("DS18B20 address: %02X %02X %02X %02X %02X %02X %02X %02X",
387  dsAddress[0], dsAddress[1], dsAddress[2], dsAddress[3],
388  dsAddress[4], dsAddress[5], dsAddress[6], dsAddress[7]);
389  } else {
390  DEBUG_WARN ("No DS18B20 found");
391  }
392  ds18b20.setWaitForConversion (false);
393  ds18b20.setResolution (DS18B20_PREC);
394 #endif // MEAS_TEMP
395 
396  if (!GwOutput.loadConfig ()) {
397  DEBUG_WARN ("Error reading config file");
398  }
399 
408 
409  WiFi.mode (WIFI_AP_STA);
410  WiFi.begin ();
411 
413 
416 
417  DEBUG_INFO ("STA MAC Address: %s", WiFi.macAddress ().c_str ());
418  DEBUG_INFO ("AP MAC Address: %s", WiFi.softAPmacAddress ().c_str ());
419  DEBUG_INFO ("BSSID Address: %s", WiFi.BSSIDstr ().c_str ());
420 
421  DEBUG_INFO ("IP address: %s", WiFi.localIP ().toString ().c_str ());
422  DEBUG_INFO ("WiFi Channel: %d", WiFi.channel ());
423  DEBUG_INFO ("WiFi SSID: %s", WiFi.SSID ().c_str ());
424  DEBUG_INFO ("Network Name: %s", EnigmaIOTGateway.getNetworkName ());
425 
427  GwOutput.begin ();
428 
430 
431 #ifdef ESP32
432  //xTaskCreate (EnigmaIOTGateway_handle, "handle", 10000, NULL, 1, &xEnigmaIOTGateway_handle);
433  //xTaskCreatePinnedToCore (EnigmaIOTGateway_handle, "handle", 4096, NULL, 0, &xEnigmaIOTGateway_handle, 1);
434  //xTaskCreatePinnedToCore (GwOutput_handle, "gwoutput", 10000, NULL, 2, &gwoutput_handle, 1);
435 #endif
436 }
437 
438 #ifdef MEAS_TEMP
439 void sendStatus (float temperature) {
440  const size_t capacity = JSON_OBJECT_SIZE (1) + JSON_OBJECT_SIZE (3) + 30;;
441  size_t len;
442  char* payload;
443 
444  DynamicJsonDocument doc (capacity);
445 
446  JsonObject status = doc.createNestedObject ("status");
447  status["temp"] = temperature;
449  status["mem"] = ESP.getFreeHeap ();
450 
451  len = measureJson (doc) + 1;
452  payload = (char*)malloc (len);
453  serializeJson (doc,(char*)payload,len);
454  char addr[] = "gateway";
455  GwOutput.outputDataSend (addr, payload, len-1);
456  free (payload);
457 }
458 #endif // MEAS_TEMP
459 
460 void loop () {
461  GwOutput.loop ();
463  ArduinoOTA.handle ();
464 
465 #ifdef MEAS_TEMP
466  static bool tempRequested = false;
467  static time_t lastTempTime;
468 
469  if (ds18b20.validAddress (dsAddress)) {
470  if (millis () - lastTempTime > statusPeriod && !tempRequested) {
471  ds18b20.requestTemperatures ();
472  DEBUG_WARN ("Temperature requested");
473  lastTempTime = millis ();
474  tempRequested = true;
475  }
476  if (tempRequested) {
477  if (ds18b20.isConversionComplete ()) {
478  temperature = ds18b20.getTempC (dsAddress);
479  sendStatus (temperature);
480  DEBUG_WARN ("Temperature: %f", temperature);
481  tempRequested = false;
482  }
483  }
484  }
485 #endif // MEAS_TEMP
486 }
EnigmaIOTGatewayClass::onWiFiManagerExit
void onWiFiManagerExit(onWiFiManagerExit_t handle)
Register callback to be called on wifi manager exit.
Definition: EnigmaIOTGateway.h:429
EnigmaIOTGatewayClass::getActiveNodesNumber
int getActiveNodesNumber()
Gets number of active nodes.
Definition: EnigmaIOTGateway.h:624
processRxControlData
void processRxControlData(char *macStr, uint8_t *data, uint8_t length)
Definition: EnigmaIOTGatewayMQTT.ino:191
BLUE_LED
#define BLUE_LED
Definition: EnigmaIOTGatewayMQTT.ino:80
GatewayOutput_dummy::loadConfig
bool loadConfig()
Loads output module configuration.
Definition: GwOutput_dummy.cpp:39
connectionLed
const int connectionLed
Definition: EnigmaIOTGatewayMQTT.ino:89
RED_LED
#define RED_LED
Definition: EnigmaIOTGatewayMQTT.ino:81
USERDATA_SET
@ USERDATA_SET
Definition: NodeList.h:58
newNodeConnected
void newNodeConnected(uint8_t *mac, uint16_t node_id, char *nodeName=NULL)
Definition: EnigmaIOTGatewayMQTT.ino:312
EnigmaIOTGatewayClass::onNodeDisconnected
void onNodeDisconnected(onNodeDisconnected_t handler)
Defines a function callback that will be called every time a node is disconnected.
Definition: EnigmaIOTGateway.h:597
GatewayOutput_dummy::configManagerStart
void configManagerStart(EnigmaIOTGatewayClass *enigmaIotGw)
Called when wifi manager starts config portal.
Definition: GwOutput_dummy.cpp:31
wifiManagerStarted
void wifiManagerStarted()
Definition: EnigmaIOTGatewayMQTT.ino:187
EnigmaIOTGatewayClass::onDataRx
void onDataRx(onGwDataRx_t handler)
Defines a function callback that will be called on every downlink data message that is received from ...
Definition: EnigmaIOTGateway.h:500
MAX_DATA_PAYLOAD_SIZE
static const int MAX_DATA_PAYLOAD_SIZE
Maximun payload size for data packets.
Definition: EnigmaIoTconfig.h:48
GwOutput_generic.h
Generic Gateway output module template.
GatewayOutput_dummy::nodeDisconnectedSend
bool nodeDisconnectedSend(char *address, gwInvalidateReason_t reason)
Send node disconnection notification.
Definition: GwOutput_dummy.cpp:73
LED_BUILTIN
#define LED_BUILTIN
Definition: EnigmaIOTGatewayMQTT.ino:77
EnigmaIOTGatewayClass::configWiFiManager
bool configWiFiManager()
Starts configuration AP and web server and gets settings from it.
Definition: EnigmaIOTGateway.cpp:443
stopConnectionFlash
void stopConnectionFlash()
Definition: EnigmaIOTGatewayMQTT.ino:113
RAW
@ RAW
Definition: EnigmaIOTGateway.h:51
ENIGMAIOT_ADDR_LEN
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
Definition: EnigmaIoTconfig.h:14
EnigmaIOTGatewayClass::getNetworkName
char * getNetworkName()
Gets EnigmaIOT network name.
Definition: EnigmaIOTGateway.h:400
GwOutput
GatewayOutput_dummy GwOutput
Definition: GwOutput_dummy.cpp:29
GatewayOutput_dummy::begin
bool begin()
Starts output module.
Definition: GwOutput_dummy.cpp:48
flashConnectionLed
void flashConnectionLed(void *led)
Definition: EnigmaIOTGatewayMQTT.ino:92
setup
void setup()
Definition: EnigmaIOTGatewayMQTT.ino:364
ENIGMAIOT
@ ENIGMAIOT
Definition: EnigmaIOTGateway.h:58
EnigmaIOTGatewayClass::setRxLed
void setRxLed(uint8_t led, time_t onTime=FLASH_LED_TIME)
Sets a LED to be flashed every time a message is received.
Definition: EnigmaIOTGateway.cpp:50
EnigmaIOTGatewayClass::handle
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
Definition: EnigmaIOTGateway.cpp:787
processRxData
void processRxData(uint8_t *mac, uint8_t *buffer, uint8_t length, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char *nodeName=NULL)
Definition: EnigmaIOTGatewayMQTT.ino:197
loop
void loop()
Definition: EnigmaIOTGatewayMQTT.ino:460
EnigmaIOTGatewayClass::setTxLed
void setTxLed(uint8_t led, time_t onTime=FLASH_LED_TIME)
Sets a LED to be flashed every time a message is transmitted.
Definition: EnigmaIOTGateway.cpp:43
GatewayOutput_dummy::loop
void loop()
Should be called often for module management.
Definition: GwOutput_dummy.cpp:54
mac2str
char * mac2str(const uint8_t *mac, char *buffer)
Debug helper function that generates a string that represent a MAC address.
Definition: helperFunctions.cpp:84
USERDATA_GET
@ USERDATA_GET
Definition: NodeList.h:57
gatewayPayloadEncoding_t
gatewayPayloadEncoding_t
Definition: EnigmaIOTGateway.h:50
nodeDisconnected
void nodeDisconnected(uint8_t *mac, gwInvalidateReason_t reason)
Definition: EnigmaIOTGatewayMQTT.ino:334
EnigmaIOTGatewayClass::getTotalPackets
uint32_t getTotalPackets(uint8_t *address)
Gets total packets sent by node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1309
EnigmaIOTGatewayClass::onNewNode
void onNewNode(onNewNode_t handler)
Defines a function callback that will be called every time a node gets connected or reconnected.
Definition: EnigmaIOTGateway.h:568
EnigmaIOTGateway
EnigmaIOTGatewayClass EnigmaIOTGateway
Definition: EnigmaIOTGateway.cpp:1747
GatewayOutput_dummy::newNodeSend
bool newNodeSend(char *address, uint16_t node_id)
Send new node notification.
Definition: GwOutput_dummy.cpp:68
MSG_PACK
@ MSG_PACK
Definition: EnigmaIOTGateway.h:54
GwOutput_mqtt.h
MQTT Gateway output module.
MACSTR
#define MACSTR
Definition: helperFunctions.cpp:82
GatewayOutput_dummy::outputControlSend
bool outputControlSend(char *address, uint8_t *data, size_t length)
Send control data from nodes.
Definition: GwOutput_dummy.cpp:63
GatewayOutput_dummy::configManagerExit
void configManagerExit(bool status)
Called when wifi manager exits config portal.
Definition: GwOutput_dummy.cpp:44
LED_OFF
#define LED_OFF
Definition: enigmaiot_led_flasher.ino:40
data
@ data
Definition: GwOutput_generic.h:23
Espnow_hal
Espnow_halClass Espnow_hal
Singleton instance of ESP-NOW class.
Definition: espnow_hal.cpp:20
EnigmaIOTGatewayClass::sendDownstream
bool sendDownstream(uint8_t *mac, const uint8_t *data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t payload_type=RAW, char *nodeName=NULL)
Starts a downstream data message transmission.
Definition: EnigmaIOTGateway.cpp:325
EnigmaIOTGatewayClass::getErrorPackets
uint32_t getErrorPackets(uint8_t *address)
Gets number of errored packets of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1315
lostmessages
@ lostmessages
Definition: GwOutput_generic.h:24
onDownlinkData
void onDownlinkData(uint8_t *address, char *nodeName, control_message_type_t msgType, char *data, unsigned int len)
Definition: EnigmaIOTGatewayMQTT.ino:263
connectionLedFlashing
boolean connectionLedFlashing
Definition: EnigmaIOTGatewayMQTT.ino:90
EnigmaIOTGatewayClass::getPacketsHour
double getPacketsHour(uint8_t *address)
Gets packet rate sent by node that has a specific address, in packets per hour.
Definition: EnigmaIOTGateway.cpp:1321
helperFunctions.h
Auxiliary function definition.
GatewayOutput_dummy::outputDataSend
bool outputDataSend(char *address, char *data, size_t length, GwOutput_data_type_t type=data)
Send data from nodes.
Definition: GwOutput_dummy.cpp:58
EnigmaIOTGateway.h
Library to build a gateway for EnigmaIoT system.
gwInvalidateReason_t
gwInvalidateReason_t
Key invalidation reason definition.
Definition: EnigmaIOTGateway.h:64
control_message_type_t
enum control_message_type control_message_type_t
EnigmaIOTGatewayClass::getPER
double getPER(uint8_t *address)
Gets packet error rate of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1299
arduinoOTAConfigure
void arduinoOTAConfigure()
Definition: EnigmaIOTGatewayMQTT.ino:129
CAYENNELPP
@ CAYENNELPP
Definition: EnigmaIOTGateway.h:52
EnigmaIOTGatewayClass::getNetworkKey
char * getNetworkKey(bool plain=false)
Gets hashed EnigmaIOT network key.
Definition: EnigmaIOTGateway.h:408
EnigmaIOTGatewayClass::begin
void begin(Comms_halClass *comm, uint8_t *networkKey=NULL, bool useDataCounter=true)
Initalizes communication basic data and starts accepting node registration.
Definition: EnigmaIOTGateway.cpp:667
EnigmaIOTGatewayClass::onWiFiManagerStarted
void onWiFiManagerStarted(onWiFiManagerStarted_t handle)
Register callback to be called on wifi manager start.
Definition: EnigmaIOTGateway.h:437
espnow_hal.h
ESP-NOW communication system abstraction layer. To be used on ESP8266 or ESP32 platforms.
wifiManagerExit
void wifiManagerExit(boolean status)
Definition: EnigmaIOTGatewayMQTT.ino:183
status
@ status
Definition: GwOutput_generic.h:25
debug.h
Auxiliary functions for debugging over Serial.
GatewayOutput_dummy::setDlCallback
void setDlCallback(onDlData_t cb)
Set data processing function.
Definition: GwOutput_dummy.h:109
startConnectionFlash
void startConnectionFlash(int period)
Definition: EnigmaIOTGatewayMQTT.ino:97