EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
EnigmaIOTGateway.h
Go to the documentation of this file.
1 
9 #ifndef _ENIGMAIOTGATEWAY_h
10 #define _ENIGMAIOTGATEWAY_h
11 
12 #if defined(ARDUINO) && ARDUINO >= 100
13 #include "Arduino.h"
14 #else
15 #include "WProgram.h"
16 #endif
17 #include "EnigmaIoTconfig.h"
18 #include "NodeList.h"
19 #include "Filter.h"
20 #include "Comms_hal.h"
21 #include <ESPAsyncWebServer.h>
22 #include <ESPAsyncWiFiManager.h>
23 #include <DNSServer.h>
24 #include <queue>
25 
26 #include "helperFunctions.h"
27 
28 #define LED_ON LOW
29 #define LED_OFF !LED_ON
30 
35  SENSOR_DATA = 0x01,
39  CONTROL_DATA = 0x03,
41  CLOCK_REQUEST = 0x05,
42  CLOCK_RESPONSE = 0x06,
43  NODE_NAME_SET = 0x07,
45  CLIENT_HELLO = 0xFF,
46  SERVER_HELLO = 0xFE,
47  INVALIDATE_KEY = 0xFB
48 };
49 
51  RAW = 0x00,
52  CAYENNELPP = 0x81,
53  PROT_BUF = 0x82,
54  MSG_PACK = 0x83,
55  BSON = 0x84,
56  CBOR = 0x85,
57  SMILE = 0x86,
58  ENIGMAIOT = 0xFF
59 };
60 
65  UNKNOWN_ERROR = 0x00,
67  //WRONG_EXCHANGE_FINISHED = 0x02, /**< KeyExchangeFinished message received was invalid. Probably this means an error on shared key */
68  WRONG_DATA = 0x03,
70  KEY_EXPIRED = 0x05
71 };
72 
73 #if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32
74 #include <functional>
75 typedef std::function<void (uint8_t* mac, uint8_t* buf, uint8_t len, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char* nodeName)> onGwDataRx_t;
76 typedef std::function<void (uint8_t* mac, uint16_t node_id, char* nodeName)> onNewNode_t;
77 typedef std::function<void (uint8_t* mac, gwInvalidateReason_t reason)> onNodeDisconnected_t;
78 typedef std::function<void (boolean status)> onWiFiManagerExit_t;
79 typedef std::function<void (void)> onWiFiManagerStarted_t;
80 #else
81 typedef void (*onGwDataRx_t)(uint8_t* mac, uint8_t* data, uint8_t len, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char* nodeName);
82 typedef void (*onNewNode_t)(uint8_t* mac, uint16_t node_id, char* nodeName);
83 typedef void (*onNodeDisconnected_t)(uint8_t* mac, gwInvalidateReason_t reason);
84 typedef void (*onWiFiManagerExit_t)(boolean status);
85 typedef void (*onWiFiManagerStarted_t)(void);
86 #endif
87 
88 typedef struct {
89  uint8_t channel = DEFAULT_CHANNEL;
90  uint8_t networkKey[KEY_LENGTH];
91  char networkName[NETWORK_NAME_LENGTH];
93 
94 typedef struct {
95  uint8_t addr[ENIGMAIOT_ADDR_LEN];
97  size_t len;
99 
104 template <typename Telement>
106 protected:
107  int maxSize;
108  int numElements = 0;
109  int readIndex = 0;
110  int writeIndex = 0;
111  Telement* buffer;
112 
113 public:
118  EnigmaIOTRingBuffer <Telement> (int range) : maxSize (range) {
119  buffer = new Telement[maxSize];
120  }
121 
126  int size () { return numElements; }
127 
132  bool isFull () { return numElements == maxSize; }
133 
138  bool empty () { return (numElements == 0); }
139 
145  bool push (Telement* item) {
146  bool wasFull = isFull ();
147  DEBUG_DBG ("Add element. Buffer was %s\n", wasFull ? "full" : "not full");
148  DEBUG_DBG ("Before -- > ReadIdx: %d. WriteIdx: %d. Size: %d\n", readIndex, writeIndex, numElements);
149  memcpy (&(buffer[writeIndex]), item, sizeof (Telement));
150  //Serial.printf ("Copied: %d bytes\n", sizeof (Telement));
151  writeIndex++;
152  if (writeIndex >= maxSize) {
153  writeIndex %= maxSize;
154  }
155  if (wasFull) { // old value is no longer valid
156  readIndex++;
157  if (readIndex >= maxSize) {
158  readIndex %= maxSize;
159  }
160  } else {
161  numElements++;
162  }
163  DEBUG_DBG ("After -- > ReadIdx: %d. WriteIdx: %d. Size: %d\n", readIndex, writeIndex, numElements);
164  return !wasFull;
165  }
166 
171  bool pop () {
172  bool wasEmpty = empty ();
173  DEBUG_DBG ("Remove element. Buffer was %s\n", wasEmpty ? "empty" : "not empty");
174  DEBUG_DBG ("Before -- > ReadIdx: %d. WriteIdx: %d. Size: %d\n", readIndex, writeIndex, numElements);
175  if (!wasEmpty) {
176  readIndex++;
177  if (readIndex >= maxSize) {
178  readIndex %= maxSize;
179  }
180  numElements--;
181  }
182  DEBUG_DBG ("After -- > ReadIdx: %d. WriteIdx: %d. Size: %d\n", readIndex, writeIndex, numElements);
183  return !wasEmpty;
184  }
185 
190  Telement* front () {
191  DEBUG_DBG ("Read element. ReadIdx: %d. WriteIdx: %d. Size: %d\n", readIndex, writeIndex, numElements);
192  if (!empty ()) {
193  return &(buffer[readIndex]);
194  } else {
195  return NULL;
196  }
197  }
198 };
199 
205 protected:
207  bool flashTx = false;
208  volatile bool flashRx = false;
212  int8_t txled = -1;
213  int8_t rxled = -1;
214  unsigned long txLedOnTime;
215  unsigned long rxLedOnTime;
219  bool useCounter = true;
221  //char networkKey[KEY_LENGTH]; ///< @brief Temporary store for textual network key
223 #ifdef ESP32
224  portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED;
225 #endif
227 
229 
230  AsyncWebServer* server;
231  DNSServer* dns;
232  AsyncWiFiManager* wifiManager;
235 
239  static void doSave (void);
240 
247  bool serverHello (const uint8_t* key, Node* node);
248 
257  bool processClientHello (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t* buf, size_t count, Node* node);
258 
267  bool processClockRequest (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t* buf, size_t count, Node* node);
268 
274  bool clockResponse (Node* node);
275 
283 
293  bool processDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node, bool encrypted = true);
294 
303  bool processUnencryptedDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
304 
314  bool downstreamDataMessage (Node* node, const uint8_t* data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t encoding = ENIGMAIOT);
315 
324  bool processControlMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
325 
334  bool processNodeNameSet (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
335 
342  bool nodeNameSetRespose (Node* node, int8_t error);
343 
352  void manageMessage (const uint8_t* mac, uint8_t* buf, uint8_t count);
353 
360  static void rx_cb (uint8_t* mac_addr, uint8_t* data, uint8_t len);
361 
368  static void tx_cb (uint8_t* mac_addr, uint8_t status);
369 
375  void getStatus (uint8_t* mac_addr, uint8_t status);
376 
381  bool loadFlashData ();
382 
387  bool saveFlashData ();
388 
389 public:
394  bool getShouldSave ();
395 
400  char* getNetworkName () {
401  return gwConfig.networkName;
402  }
403 
408  char* getNetworkKey (bool plain = false) {
409  if (plain)
410  return (char*)(plainNetKey);
411  else
412  return (char*)(gwConfig.networkKey);
413  }
414 
419  void addWiFiManagerParameter (AsyncWiFiManagerParameter* p) {
420  if (wifiManager) {
421  wifiManager->addParameter (p);
422  }
423  }
424 
431  }
432 
439  }
440 
445  bool configWiFiManager ();
446 
453  void begin (Comms_halClass* comm, uint8_t* networkKey = NULL, bool useDataCounter = true);
454 
459  void handle ();
460 
466  void setTxLed (uint8_t led, time_t onTime = FLASH_LED_TIME);
467 
473  void setRxLed (uint8_t led, time_t onTime = FLASH_LED_TIME);
474 
500  void onDataRx (onGwDataRx_t handler) {
501  notifyData = handler;
502  }
503 
509  double getPER (uint8_t* address);
510 
516  uint32_t getTotalPackets (uint8_t* address);
517 
523  uint32_t getErrorPackets (uint8_t* address);
524 
530  double getPacketsHour (uint8_t* address);
531 
541  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);
542 
568  void onNewNode (onNewNode_t handler) {
569  notifyNewNode = handler;
570  }
571 
598  notifyNodeDisconnection = handler;
599  }
600 
607  bool addInputMsgQueue (const uint8_t* addr, const uint8_t* msg, size_t len);
608 
614 
618  void popInputMsgQueue ();
619 
625  return nodelist.countActiveNodes ();
626  }
627 
633  return &nodelist;
634  }
635 
636 };
637 
639 
640 #endif
641 
BSON
@ BSON
Definition: EnigmaIOTGateway.h:55
EnigmaIOTGatewayClass::onWiFiManagerExit
void onWiFiManagerExit(onWiFiManagerExit_t handle)
Register callback to be called on wifi manager exit.
Definition: EnigmaIOTGateway.h:429
EnigmaIOTRingBuffer::readIndex
int readIndex
Pointer to next item to be read.
Definition: EnigmaIOTGateway.h:109
EnigmaIOTGatewayClass::flashRx
volatile bool flashRx
true if Rx LED should flash
Definition: EnigmaIOTGateway.h:208
CLOCK_RESPONSE
@ CLOCK_RESPONSE
Definition: EnigmaIOTGateway.h:42
EnigmaIOTGatewayClass::getActiveNodesNumber
int getActiveNodesNumber()
Gets number of active nodes.
Definition: EnigmaIOTGateway.h:624
EnigmaIOTGatewayClass::invalidateKey
bool invalidateKey(Node *node, gwInvalidateReason_t reason)
Creates an InvalidateKey message and sned it. This trigger a new key agreement to start on related no...
Definition: EnigmaIOTGateway.cpp:1444
gatewayMessageType_t
gatewayMessageType_t
Message code definition.
Definition: EnigmaIOTGateway.h:34
EnigmaIOTRingBuffer::buffer
Telement * buffer
Actual buffer.
Definition: EnigmaIOTGateway.h:111
EnigmaIOTGatewayClass::useCounter
bool useCounter
true if counter is used to check data messages order
Definition: EnigmaIOTGateway.h:219
WRONG_CLIENT_HELLO
@ WRONG_CLIENT_HELLO
Definition: EnigmaIOTGateway.h:66
EnigmaIOTGatewayClass::myPublicKey
uint8_t myPublicKey[KEY_LENGTH]
Temporary public key store used during key agreement.
Definition: EnigmaIOTGateway.h:206
EnigmaIOTGatewayClass::addInputMsgQueue
bool addInputMsgQueue(const uint8_t *addr, const uint8_t *msg, size_t len)
Add message to input queue.
Definition: EnigmaIOTGateway.cpp:712
EnigmaIOTGatewayClass::rxLedOnTime
unsigned long rxLedOnTime
Flash duration for Rx LED.
Definition: EnigmaIOTGateway.h:215
EnigmaIOTRingBuffer
Ring buffer class. Used to implement message buffer.
Definition: EnigmaIOTGateway.h:105
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
NODE_NAME_SET
@ NODE_NAME_SET
Definition: EnigmaIOTGateway.h:43
NodeList.h
EnigmaIoT sensor node management structures.
EnigmaIOTGatewayClass
Main gateway class. Manages communication with nodes and sends data to upper layer.
Definition: EnigmaIOTGateway.h:204
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
EnigmaIOTGatewayClass::processControlMessage
bool processControlMessage(const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
Processes control message from node.
Definition: EnigmaIOTGateway.cpp:1112
EnigmaIOTRingBuffer::size
int size()
Returns actual number of elements that buffer holds.
Definition: EnigmaIOTGateway.h:126
EnigmaIOTGatewayClass::tempBuffer
msg_queue_item_t tempBuffer
Temporary storage for input message got from buffer.
Definition: EnigmaIOTGateway.h:226
EnigmaIOTRingBuffer::push
bool push(Telement *item)
Adds a new item to buffer, deleting older element if it is full.
Definition: EnigmaIOTGateway.h:145
EnigmaIOTGatewayClass::manageMessage
void manageMessage(const uint8_t *mac, uint8_t *buf, uint8_t count)
Process every received message.
Definition: EnigmaIOTGateway.cpp:853
EnigmaIOTGatewayClass::comm
Comms_halClass * comm
Instance of physical communication layer.
Definition: EnigmaIOTGateway.h:211
EnigmaIOTGatewayClass::rx_cb
static void rx_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len)
Function that will be called anytime this gateway receives a message.
Definition: EnigmaIOTGateway.cpp:769
EnigmaIOTGatewayClass::txled
int8_t txled
I/O pin to connect a led that flashes when gateway transmits data.
Definition: EnigmaIOTGateway.h:212
EnigmaIOTGatewayClass::configWiFiManager
bool configWiFiManager()
Starts configuration AP and web server and gets settings from it.
Definition: EnigmaIOTGateway.cpp:443
EnigmaIOTGatewayClass::processDataMessage
bool processDataMessage(const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node, bool encrypted=true)
Processes data message from node.
Definition: EnigmaIOTGateway.cpp:1225
EnigmaIOTGatewayClass::server
AsyncWebServer * server
WebServer that holds configuration portal.
Definition: EnigmaIOTGateway.h:230
gateway_config_t::networkKey
uint8_t networkKey[KEY_LENGTH]
Definition: EnigmaIOTGateway.h:90
onWiFiManagerStarted_t
void(* onWiFiManagerStarted_t)(void)
Definition: EnigmaIOTGateway.h:85
EnigmaIOTGatewayClass::notifyData
onGwDataRx_t notifyData
Callback function that will be invoked when data is received fron a node.
Definition: EnigmaIOTGateway.h:216
RAW
@ RAW
Definition: EnigmaIOTGateway.h:51
EnigmaIOTGatewayClass::input_queue
EnigmaIOTRingBuffer< msg_queue_item_t > * input_queue
Input messages buffer. It acts as a FIFO queue.
Definition: EnigmaIOTGateway.h:228
EnigmaIoTconfig.h
Parameter configuration.
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
CBOR
@ CBOR
Definition: EnigmaIOTGateway.h:56
PROT_BUF
@ PROT_BUF
Definition: EnigmaIOTGateway.h:53
ENIGMAIOT
@ ENIGMAIOT
Definition: EnigmaIOTGateway.h:58
EnigmaIOTGateway
EnigmaIOTGatewayClass EnigmaIOTGateway
Definition: EnigmaIOTGateway.cpp:1747
DOWNSTREAM_DATA_GET
@ DOWNSTREAM_DATA_GET
Definition: EnigmaIOTGateway.h:38
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::notifyWiFiManagerExit
onWiFiManagerExit_t notifyWiFiManagerExit
Function called when configuration portal exits.
Definition: EnigmaIOTGateway.h:233
DOWNSTREAM_DATA_SET
@ DOWNSTREAM_DATA_SET
Definition: EnigmaIOTGateway.h:37
EnigmaIOTGatewayClass::handle
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
Definition: EnigmaIOTGateway.cpp:787
EnigmaIOTGatewayClass::addWiFiManagerParameter
void addWiFiManagerParameter(AsyncWiFiManagerParameter *p)
Adds a parameter to configuration portal.
Definition: EnigmaIOTGateway.h:419
DOWNSTREAM_CTRL_DATA
@ DOWNSTREAM_CTRL_DATA
Definition: EnigmaIOTGateway.h:40
EnigmaIOTGatewayClass::notifyNodeDisconnection
onNodeDisconnected_t notifyNodeDisconnection
Callback function that will be invoked when a node gets disconnected.
Definition: EnigmaIOTGateway.h:218
EnigmaIOTGatewayClass::processUnencryptedDataMessage
bool processUnencryptedDataMessage(const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
Processes unencrypted data message from node.
Definition: EnigmaIOTGateway.cpp:1172
EnigmaIOTRingBuffer::empty
bool empty()
Checks if buffer is empty.
Definition: EnigmaIOTGateway.h:138
EnigmaIOTGatewayClass::clockResponse
bool clockResponse(Node *node)
Returns timestaps needed so that node can calculate time difference.
Definition: EnigmaIOTGateway.cpp:1603
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
onNewNode_t
void(* onNewNode_t)(uint8_t *mac, uint16_t node_id, char *nodeName)
Definition: EnigmaIOTGateway.h:82
CONTROL_DATA
@ CONTROL_DATA
Definition: EnigmaIOTGateway.h:39
EnigmaIOTRingBuffer::pop
bool pop()
Deletes older item from buffer, if buffer is not empty.
Definition: EnigmaIOTGateway.h:171
SENSOR_DATA
@ SENSOR_DATA
Definition: EnigmaIOTGateway.h:35
EnigmaIOTRingBuffer::maxSize
int maxSize
Buffer size.
Definition: EnigmaIOTGateway.h:107
EnigmaIOTRingBuffer::front
Telement * front()
Gets a pointer to older item in buffer, if buffer is not empty.
Definition: EnigmaIOTGateway.h:190
EnigmaIOTGatewayClass::processClockRequest
bool processClockRequest(const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t *buf, size_t count, Node *node)
Starts clock sync procedure from node to gateway.
Definition: EnigmaIOTGateway.cpp:1543
gatewayPayloadEncoding_t
gatewayPayloadEncoding_t
Definition: EnigmaIOTGateway.h:50
node_instance
Struct that define node fields. Used for long term storage needs.
Definition: NodeList.h:76
EnigmaIOTGatewayClass::getTotalPackets
uint32_t getTotalPackets(uint8_t *address)
Gets total packets sent by node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1309
EnigmaIOTGatewayClass::flashTx
bool flashTx
true if Tx LED should flash
Definition: EnigmaIOTGateway.h:207
EnigmaIOTGatewayClass::dns
DNSServer * dns
DNS server used by configuration portal.
Definition: EnigmaIOTGateway.h:231
msg_queue_item_t
Definition: EnigmaIOTGateway.h:94
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
EnigmaIOTGatewayClass::getStatus
void getStatus(uint8_t *mac_addr, uint8_t status)
Functrion to debug send status.
Definition: EnigmaIOTGateway.cpp:778
EnigmaIOTGatewayClass::getShouldSave
bool getShouldSave()
Gets flag that indicates if configuration should be saved.
Definition: EnigmaIOTGateway.cpp:39
EnigmaIOTRingBuffer::isFull
bool isFull()
Checks if buffer is full.
Definition: EnigmaIOTGateway.h:132
EnigmaIOTGatewayClass::nodelist
NodeList nodelist
Node database that keeps status and shared keys.
Definition: EnigmaIOTGateway.h:210
msg_queue_item_t::len
size_t len
Definition: EnigmaIOTGateway.h:97
EnigmaIOTGatewayClass::getNodes
NodeList * getNodes()
Gets nodes data structure.
Definition: EnigmaIOTGateway.h:632
MAX_MESSAGE_LENGTH
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
Definition: EnigmaIoTconfig.h:13
EnigmaIOTGatewayClass::node
node_t node
temporary store to keep node data while processing a message
Definition: EnigmaIOTGateway.h:209
EnigmaIOTGatewayClass::txLedOnTime
unsigned long txLedOnTime
Flash duration for Tx LED.
Definition: EnigmaIOTGateway.h:214
EnigmaIOTGatewayClass::doSave
static void doSave(void)
Activates a flag that signals that configuration has to be saved.
Definition: EnigmaIOTGateway.cpp:34
MSG_PACK
@ MSG_PACK
Definition: EnigmaIOTGateway.h:54
Node
Class definition for a single sensor Node.
Definition: NodeList.h:93
EnigmaIOTGatewayClass::gwConfig
gateway_config_t gwConfig
Gateway specific configuration to be stored on flash memory.
Definition: EnigmaIOTGateway.h:220
KEY_EXPIRED
@ KEY_EXPIRED
Definition: EnigmaIOTGateway.h:70
NodeList
Definition: NodeList.h:359
EnigmaIOTGatewayClass::processClientHello
bool processClientHello(const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t *buf, size_t count, Node *node)
Gets a buffer containing a ClientHello message and process it. This carries node public key to be use...
Definition: EnigmaIOTGateway.cpp:1471
EnigmaIOTGatewayClass::tx_cb
static void tx_cb(uint8_t *mac_addr, uint8_t status)
Function that will be called anytime this gateway sends a message to indicate status result of sendin...
Definition: EnigmaIOTGateway.cpp:774
EnigmaIOTGatewayClass::saveFlashData
bool saveFlashData()
Saves configuration to flash memory.
Definition: EnigmaIOTGateway.cpp:624
EnigmaIOTGatewayClass::rxled
int8_t rxled
I/O pin to connect a led that flashes when gateway receives data.
Definition: EnigmaIOTGateway.h:213
EnigmaIOTGatewayClass::processNodeNameSet
bool processNodeNameSet(const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
Processes new node name request fromn node.
Definition: EnigmaIOTGateway.cpp:1052
data
@ data
Definition: GwOutput_generic.h:23
EnigmaIOTGatewayClass::downstreamDataMessage
bool downstreamDataMessage(Node *node, const uint8_t *data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t encoding=ENIGMAIOT)
Builds, encrypts and sends a DownstreamData message.
Definition: EnigmaIOTGateway.cpp:1328
WRONG_DATA
@ WRONG_DATA
Definition: EnigmaIOTGateway.h:68
SERVER_HELLO
@ SERVER_HELLO
Definition: EnigmaIOTGateway.h:46
onWiFiManagerExit_t
void(* onWiFiManagerExit_t)(boolean status)
Definition: EnigmaIOTGateway.h:84
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::notifyWiFiManagerStarted
onWiFiManagerStarted_t notifyWiFiManagerStarted
Function called when configuration portal is started.
Definition: EnigmaIOTGateway.h:234
DEFAULT_CHANNEL
static const uint8_t DEFAULT_CHANNEL
WiFi channel to be used on ESP-NOW.
Definition: EnigmaIoTconfig.h:16
EnigmaIOTGatewayClass::getErrorPackets
uint32_t getErrorPackets(uint8_t *address)
Gets number of errored packets of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1315
NETWORK_NAME_LENGTH
static const uint8_t NETWORK_NAME_LENGTH
Maximum number of characters of network name.
Definition: EnigmaIoTconfig.h:18
CLOCK_REQUEST
@ CLOCK_REQUEST
Definition: EnigmaIOTGateway.h:41
onGwDataRx_t
void(* onGwDataRx_t)(uint8_t *mac, uint8_t *data, uint8_t len, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char *nodeName)
Definition: EnigmaIOTGateway.h:81
EnigmaIOTGatewayClass::notifyNewNode
onNewNode_t notifyNewNode
Callback function that will be invoked when a new node is connected.
Definition: EnigmaIOTGateway.h:217
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
UNREGISTERED_NODE
@ UNREGISTERED_NODE
Definition: EnigmaIOTGateway.h:69
NODE_NAME_RESULT
@ NODE_NAME_RESULT
Definition: EnigmaIOTGateway.h:44
helperFunctions.h
Auxiliary function definition.
EnigmaIOTRingBuffer::numElements
int numElements
Number of elements that buffer currently has.
Definition: EnigmaIOTGateway.h:108
FLASH_LED_TIME
static const uint32_t FLASH_LED_TIME
Time that led keeps on during flash in ms.
Definition: EnigmaIoTconfig.h:17
UNKNOWN_ERROR
@ UNKNOWN_ERROR
Definition: EnigmaIOTGateway.h:65
SMILE
@ SMILE
Definition: EnigmaIOTGateway.h:57
gwInvalidateReason_t
gwInvalidateReason_t
Key invalidation reason definition.
Definition: EnigmaIOTGateway.h:64
EnigmaIOTGatewayClass::serverHello
bool serverHello(const uint8_t *key, Node *node)
Build a ServerHello messange and send it to node.
Definition: EnigmaIOTGateway.cpp:1669
EnigmaIOTGatewayClass::loadFlashData
bool loadFlashData()
Loads configuration from flash memory.
Definition: EnigmaIOTGateway.cpp:553
CLIENT_HELLO
@ CLIENT_HELLO
Definition: EnigmaIOTGateway.h:45
NodeList::countActiveNodes
uint16_t countActiveNodes()
Gets the number of active nodes (registered or registering)
Definition: NodeList.cpp:209
control_message_type_t
enum control_message_type control_message_type_t
EnigmaIOTGatewayClass::nodeNameSetRespose
bool nodeNameSetRespose(Node *node, int8_t error)
Send back set name response.
Definition: EnigmaIOTGateway.cpp:996
EnigmaIOTGatewayClass::getPER
double getPER(uint8_t *address)
Gets packet error rate of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1299
KEY_LENGTH
const uint8_t KEY_LENGTH
Key length used by selected crypto algorythm. The only tested value is 32. Change it only if you know...
Definition: EnigmaIoTconfig.h:58
CAYENNELPP
@ CAYENNELPP
Definition: EnigmaIOTGateway.h:52
gateway_config_t
Definition: EnigmaIOTGateway.h:88
EnigmaIOTGatewayClass::plainNetKey
char plainNetKey[KEY_LENGTH]
Definition: EnigmaIOTGateway.h:222
Comms_hal.h
Generic communication system abstraction layer.
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
gateway_config_t::networkName
char networkName[NETWORK_NAME_LENGTH]
Definition: EnigmaIOTGateway.h:91
INVALIDATE_KEY
@ INVALIDATE_KEY
Definition: EnigmaIOTGateway.h:47
onNodeDisconnected_t
void(* onNodeDisconnected_t)(uint8_t *mac, gwInvalidateReason_t reason)
Definition: EnigmaIOTGateway.h:83
EnigmaIOTGatewayClass::wifiManager
AsyncWiFiManager * wifiManager
Wifi configuration portal.
Definition: EnigmaIOTGateway.h:232
status
@ status
Definition: GwOutput_generic.h:25
EnigmaIOTGatewayClass::getInputMsgQueue
msg_queue_item_t * getInputMsgQueue(msg_queue_item_t *buffer)
Gets next item in the queue.
Definition: EnigmaIOTGateway.cpp:735
Comms_halClass
Interface for communication subsystem abstraction layer definition.
Definition: Comms_hal.h:33
UNENCRYPTED_NODE_DATA
@ UNENCRYPTED_NODE_DATA
Definition: EnigmaIOTGateway.h:36
EnigmaIOTGatewayClass::popInputMsgQueue
void popInputMsgQueue()
Deletes next item in the queue.
Definition: EnigmaIOTGateway.cpp:763
Filter.h
Filter to process message rate or other values.
EnigmaIOTRingBuffer::writeIndex
int writeIndex
Pointer to next position to write onto.
Definition: EnigmaIOTGateway.h:110