EnigmaIOT  0.9.8
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 #include "EnigmaIOTRingBuffer.h"
26 #if ENABLE_REST_API
27 #include "GatewayAPI.h"
28 #endif // ENABLE_REST_API
29 
30 #include "helperFunctions.h"
31 
32 #define LED_ON LOW
33 #define LED_OFF !LED_ON
34 
39  SENSOR_DATA = 0x01,
46  CONTROL_DATA = 0x03,
50  CLOCK_REQUEST = 0x05,
51  CLOCK_RESPONSE = 0x06,
52  NODE_NAME_SET = 0x07,
56  CLIENT_HELLO = 0xFF,
57  SERVER_HELLO = 0xFE,
58  INVALIDATE_KEY = 0xFB
59 };
60 
62  RAW = 0x00,
63  CAYENNELPP = 0x81,
64  PROT_BUF = 0x82,
65  MSG_PACK = 0x83,
66  BSON = 0x84,
67  CBOR = 0x85,
68  SMILE = 0x86,
69  ENIGMAIOT = 0xFF
70 };
71 
76  UNKNOWN_ERROR = 0x00,
78  //WRONG_EXCHANGE_FINISHED = 0x02, /**< KeyExchangeFinished message received was invalid. Probably this means an error on shared key */
79  WRONG_DATA = 0x03,
81  KEY_EXPIRED = 0x05,
82  KICKED = 0x06
83 };
84 
85 #if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32
86 #include <functional>
87 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;
88 #if SUPPORT_HA_DISCOVERY
89 typedef std::function<void (const char* topic, char *message, size_t len)> onHADiscovery_t;
90 #endif
91 typedef std::function<void (uint8_t* mac, uint16_t node_id, char* nodeName)> onNewNode_t;
92 typedef std::function<void (uint8_t* mac, gwInvalidateReason_t reason)> onNodeDisconnected_t;
93 typedef std::function<void (boolean status)> onWiFiManagerExit_t;
94 typedef std::function<void (void)> simpleEventHandler_t;
95 
96 #else
97 typedef void (*onGwDataRx_t)(uint8_t* mac, uint8_t* data, uint8_t len, uint16_t lostMessages, bool control, gatewayPayloadEncoding_t payload_type, char* nodeName);
98 typedef void (*onNewNode_t)(uint8_t* mac, uint16_t node_id, char* nodeName);
99 typedef void (*onNodeDisconnected_t)(uint8_t* mac, gwInvalidateReason_t reason);
100 typedef void (*onWiFiManagerExit_t)(boolean status);
101 typedef void (*simpleEventHandler_t)(void);
102 #endif
103 
104 typedef struct {
105  uint8_t channel = DEFAULT_CHANNEL;
106  uint8_t networkKey[KEY_LENGTH];
107  char networkName[NETWORK_NAME_LENGTH];
109 
110 typedef struct {
111  uint8_t addr[ENIGMAIOT_ADDR_LEN];
113  size_t len;
115 
121 protected:
123  bool flashTx = false;
124  volatile bool flashRx = false;
128  int8_t txled = -1;
129  int8_t rxled = -1;
130  unsigned long txLedOnTime;
131  unsigned long rxLedOnTime;
133 #if SUPPORT_HA_DISCOVERY
134  onHADiscovery_t notifyHADiscovery;
135 #endif
139  bool useCounter = true;
142 #ifdef ESP32
143  portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED;
144 #endif
146 
148 
149  AsyncWebServer* server;
150  DNSServer* dns;
151  AsyncWiFiManager* wifiManager;
154 
155  friend class GatewayAPI;
156 
160  static void doSave (void);
161 
165  static void doResetConfig (void);
166 
167 
174  bool serverHello (const uint8_t* key, Node* node);
175 
181  bool sendBroadcastKey (Node* node);
182 
191  bool processClientHello (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t* buf, size_t count, Node* node);
192 
201  bool processClockRequest (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t* buf, size_t count, Node* node);
202 
210  bool clockResponse (Node* node, uint64_t t1, uint64_t t2);
211 
219 
229  bool processDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node, bool encrypted = true);
230 
239  bool processUnencryptedDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
240 
250  bool downstreamDataMessage (Node* node, const uint8_t* data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t encoding = ENIGMAIOT);
251 
260  bool processControlMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
261 
270  bool processNodeNameSet (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t* buf, size_t count, Node* node);
271 
278  bool nodeNameSetRespose (Node* node, int8_t error);
279 
288  void manageMessage (const uint8_t* mac, uint8_t* buf, uint8_t count);
289 
296  static void rx_cb (uint8_t* mac_addr, uint8_t* data, uint8_t len);
297 
304  static void tx_cb (uint8_t* mac_addr, uint8_t status);
305 
311  void getStatus (uint8_t* mac_addr, uint8_t status);
312 
317  bool loadFlashData ();
318 
323  bool saveFlashData ();
324 
325 #if SUPPORT_HA_DISCOVERY
326 
335  bool sendHADiscoveryJSON (uint8_t* address, uint8_t* data, size_t len, const char* networkName, const char* nodeName);
336 #endif
337 
338 public:
343  bool getShouldSave ();
344 
349  char* getNetworkName () {
350  return gwConfig.networkName;
351  }
352 
357  char* getNetworkKey (bool plain = false) {
358  if (plain)
359  return (char*)(plainNetKey);
360  else
361  return (char*)(gwConfig.networkKey);
362  }
363 
368  void addWiFiManagerParameter (AsyncWiFiManagerParameter* p) {
369  if (wifiManager) {
370  wifiManager->addParameter (p);
371  }
372  }
373 
380  }
381 
388  }
389 
394  bool configWiFiManager ();
395 
402  void begin (Comms_halClass* comm, uint8_t* networkKey = NULL, bool useDataCounter = true);
403 
408  void handle ();
409 
415  void setTxLed (uint8_t led, time_t onTime = FLASH_LED_TIME);
416 
422  void setRxLed (uint8_t led, time_t onTime = FLASH_LED_TIME);
423 
449  void onDataRx (onGwDataRx_t handler) {
450  notifyData = handler;
451  }
452 
453 #if SUPPORT_HA_DISCOVERY
454 
458  void onHADiscovery (onHADiscovery_t handler) {
459  notifyHADiscovery = handler;
460  }
461 #endif
462 
468  double getPER (uint8_t* address);
469 
475  uint32_t getTotalPackets (uint8_t* address);
476 
482  uint32_t getErrorPackets (uint8_t* address);
483 
489  double getPacketsHour (uint8_t* address);
490 
501  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);
502 
528  void onNewNode (onNewNode_t handler) {
529  notifyNewNode = handler;
530  }
531 
558  notifyNodeDisconnection = handler;
559  }
560 
566  notifyRestartRequested = handler;
567  }
568 
575  bool addInputMsgQueue (const uint8_t* addr, const uint8_t* msg, size_t len);
576 
582 
586  void popInputMsgQueue ();
587 
593  return nodelist.countActiveNodes ();
594  }
595 
601  return &nodelist;
602  }
603 
604 };
605 
607 
608 #endif
609 
BSON
@ BSON
Definition: EnigmaIOTGateway.h:66
EnigmaIOTGatewayClass::onWiFiManagerExit
void onWiFiManagerExit(onWiFiManagerExit_t handle)
Register callback to be called on wifi manager exit.
Definition: EnigmaIOTGateway.h:378
EnigmaIOTGatewayClass::flashRx
volatile bool flashRx
true if Rx LED should flash
Definition: EnigmaIOTGateway.h:124
CLOCK_RESPONSE
@ CLOCK_RESPONSE
Definition: EnigmaIOTGateway.h:51
EnigmaIOTGatewayClass::getActiveNodesNumber
int getActiveNodesNumber()
Gets number of active nodes.
Definition: EnigmaIOTGateway.h:592
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:1624
gatewayMessageType_t
gatewayMessageType_t
Message code definition.
Definition: EnigmaIOTGateway.h:38
EnigmaIOTRingBuffer.h
Library to build a gateway for EnigmaIoT system.
EnigmaIOTGatewayClass::useCounter
bool useCounter
true if counter is used to check data messages order
Definition: EnigmaIOTGateway.h:139
EnigmaIOTGatewayClass::doResetConfig
static void doResetConfig(void)
Activates a flag that signals that configuration has to be saved.
Definition: EnigmaIOTGateway.cpp:47
WRONG_CLIENT_HELLO
@ WRONG_CLIENT_HELLO
Definition: EnigmaIOTGateway.h:77
EnigmaIOTGatewayClass::myPublicKey
uint8_t myPublicKey[KEY_LENGTH]
Temporary public key store used during key agreement.
Definition: EnigmaIOTGateway.h:122
EnigmaIOTGatewayClass::addInputMsgQueue
bool addInputMsgQueue(const uint8_t *addr, const uint8_t *msg, size_t len)
Add message to input queue.
Definition: EnigmaIOTGateway.cpp:792
EnigmaIOTGatewayClass::rxLedOnTime
unsigned long rxLedOnTime
Flash duration for Rx LED.
Definition: EnigmaIOTGateway.h:131
BROADCAST_KEY_REQUEST
@ BROADCAST_KEY_REQUEST
Definition: EnigmaIOTGateway.h:54
EnigmaIOTRingBuffer< msg_queue_item_t >
ENIGMAIOT_ADDR_LEN
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
Definition: EnigmaIoTconfigAdvanced.h:23
EnigmaIOTGatewayClass::onNodeDisconnected
void onNodeDisconnected(onNodeDisconnected_t handler)
Defines a function callback that will be called every time a node is disconnected.
Definition: EnigmaIOTGateway.h:557
NODE_NAME_SET
@ NODE_NAME_SET
Definition: EnigmaIOTGateway.h:52
NodeList.h
EnigmaIoT sensor node management structures.
EnigmaIOTGatewayClass
Main gateway class. Manages communication with nodes and sends data to upper layer.
Definition: EnigmaIOTGateway.h:120
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:449
GatewayAPI
Definition: GatewayAPI.h:25
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:1250
EnigmaIOTGatewayClass::onHADiscovery
void onHADiscovery(onHADiscovery_t handler)
Defines a function callback that will be called when a Home Assistant discovery message is received f...
Definition: EnigmaIOTGateway.h:458
MAX_MESSAGE_LENGTH
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
Definition: EnigmaIoTconfigAdvanced.h:21
EnigmaIOTGatewayClass::tempBuffer
msg_queue_item_t tempBuffer
Temporary storage for input message got from buffer.
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:935
EnigmaIOTGatewayClass::comm
Comms_halClass * comm
Instance of physical communication layer.
Definition: EnigmaIOTGateway.h:127
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:849
DOWNSTREAM_BRCAST_DATA_GET
@ DOWNSTREAM_BRCAST_DATA_GET
Definition: EnigmaIOTGateway.h:45
EnigmaIOTGatewayClass::txled
int8_t txled
I/O pin to connect a led that flashes when gateway transmits data.
Definition: EnigmaIOTGateway.h:128
EnigmaIOTGatewayClass::configWiFiManager
bool configWiFiManager()
Starts configuration AP and web server and gets settings from it.
Definition: EnigmaIOTGateway.cpp:494
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:1377
EnigmaIOTGatewayClass::server
AsyncWebServer * server
WebServer that holds configuration portal.
Definition: EnigmaIOTGateway.h:149
gateway_config_t::networkKey
uint8_t networkKey[KEY_LENGTH]
Definition: EnigmaIOTGateway.h:106
EnigmaIOTGatewayClass::notifyData
onGwDataRx_t notifyData
Callback function that will be invoked when data is received from a node.
Definition: EnigmaIOTGateway.h:132
RAW
@ RAW
Definition: EnigmaIOTGateway.h:62
EnigmaIOTGatewayClass::input_queue
EnigmaIOTRingBuffer< msg_queue_item_t > * input_queue
Input messages buffer. It acts as a FIFO queue.
Definition: EnigmaIOTGateway.h:147
EnigmaIoTconfig.h
Parameter configuration.
EnigmaIOTGatewayClass::getNetworkName
char * getNetworkName()
Gets EnigmaIOT network name.
Definition: EnigmaIOTGateway.h:349
KICKED
@ KICKED
Definition: EnigmaIOTGateway.h:82
EnigmaIOTGatewayClass::notifyHADiscovery
onHADiscovery_t notifyHADiscovery
Callback function that will be invoked when HomeAssistant discovery message is received from a node.
Definition: EnigmaIOTGateway.h:134
EnigmaIOTGatewayClass::sendBroadcastKey
bool sendBroadcastKey(Node *node)
Sends broadcast key to node if it has requested it explicitly or it has notified during handshake.
Definition: EnigmaIOTGateway.cpp:1903
NETWORK_NAME_LENGTH
static const uint8_t NETWORK_NAME_LENGTH
Maximum number of characters of network name.
Definition: EnigmaIoTconfigAdvanced.h:24
CBOR
@ CBOR
Definition: EnigmaIOTGateway.h:67
PROT_BUF
@ PROT_BUF
Definition: EnigmaIOTGateway.h:64
ENIGMAIOT
@ ENIGMAIOT
Definition: EnigmaIOTGateway.h:69
EnigmaIOTGatewayClass::notifyRestartRequested
simpleEventHandler_t notifyRestartRequested
Callback function that will be invoked when a hardware restart is requested.
Definition: EnigmaIOTGateway.h:138
EnigmaIOTGateway
EnigmaIOTGatewayClass EnigmaIOTGateway
Definition: EnigmaIOTGateway.cpp:2050
DOWNSTREAM_DATA_GET
@ DOWNSTREAM_DATA_GET
Definition: EnigmaIOTGateway.h:44
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:66
EnigmaIOTGatewayClass::notifyWiFiManagerExit
onWiFiManagerExit_t notifyWiFiManagerExit
Function called when configuration portal exits.
Definition: EnigmaIOTGateway.h:152
DOWNSTREAM_DATA_SET
@ DOWNSTREAM_DATA_SET
Definition: EnigmaIOTGateway.h:42
EnigmaIOTGatewayClass::handle
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
Definition: EnigmaIOTGateway.cpp:867
EnigmaIOTGatewayClass::addWiFiManagerParameter
void addWiFiManagerParameter(AsyncWiFiManagerParameter *p)
Adds a parameter to configuration portal.
Definition: EnigmaIOTGateway.h:368
GatewayAPI.h
API web server to control EnigmaIOT Gateway.
DOWNSTREAM_CTRL_DATA
@ DOWNSTREAM_CTRL_DATA
Definition: EnigmaIOTGateway.h:47
EnigmaIOTGatewayClass::notifyNodeDisconnection
onNodeDisconnected_t notifyNodeDisconnection
Callback function that will be invoked when a node gets disconnected.
Definition: EnigmaIOTGateway.h:137
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:1324
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:59
onNewNode_t
void(* onNewNode_t)(uint8_t *mac, uint16_t node_id, char *nodeName)
Definition: EnigmaIOTGateway.h:98
CONTROL_DATA
@ CONTROL_DATA
Definition: EnigmaIOTGateway.h:46
simpleEventHandler_t
void(* simpleEventHandler_t)(void)
Definition: EnigmaIOTGateway.h:101
SENSOR_DATA
@ SENSOR_DATA
Definition: EnigmaIOTGateway.h:39
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:1739
gatewayPayloadEncoding_t
gatewayPayloadEncoding_t
Definition: EnigmaIOTGateway.h:61
node_instance
Struct that define node fields. Used for long term storage needs.
Definition: NodeList.h:89
DOWNSTREAM_BRCAST_DATA_SET
@ DOWNSTREAM_BRCAST_DATA_SET
Definition: EnigmaIOTGateway.h:43
EnigmaIOTGatewayClass::getTotalPackets
uint32_t getTotalPackets(uint8_t *address)
Gets total packets sent by node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1470
EnigmaIOTGatewayClass::flashTx
bool flashTx
true if Tx LED should flash
Definition: EnigmaIOTGateway.h:123
EnigmaIOTGatewayClass::dns
DNSServer * dns
DNS server used by configuration portal.
Definition: EnigmaIOTGateway.h:150
msg_queue_item_t
Definition: EnigmaIOTGateway.h:110
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:528
EnigmaIOTGatewayClass::getStatus
void getStatus(uint8_t *mac_addr, uint8_t status)
Functrion to debug send status.
Definition: EnigmaIOTGateway.cpp:858
EnigmaIOTGatewayClass::getShouldSave
bool getShouldSave()
Gets flag that indicates if configuration should be saved.
Definition: EnigmaIOTGateway.cpp:55
EnigmaIOTGatewayClass::nodelist
NodeList nodelist
Node database that keeps status and shared keys.
Definition: EnigmaIOTGateway.h:126
EnigmaIOTGatewayClass::clockResponse
bool clockResponse(Node *node, uint64_t t1, uint64_t t2)
Returns timestaps needed so that node can calculate time difference.
Definition: EnigmaIOTGateway.cpp:1822
SENSOR_BRCAST_DATA
@ SENSOR_BRCAST_DATA
Definition: EnigmaIOTGateway.h:40
msg_queue_item_t::len
size_t len
Definition: EnigmaIOTGateway.h:113
EnigmaIOTGatewayClass::getNodes
NodeList * getNodes()
Gets nodes data structure.
Definition: EnigmaIOTGateway.h:600
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: EnigmaIoTconfigAdvanced.h:70
EnigmaIOTGatewayClass::onWiFiManagerStarted
void onWiFiManagerStarted(simpleEventHandler_t handle)
Register callback to be called on wifi manager start.
Definition: EnigmaIOTGateway.h:386
EnigmaIOTGatewayClass::node
node_t node
temporary store to keep node data while processing a message
Definition: EnigmaIOTGateway.h:125
EnigmaIOTGatewayClass::txLedOnTime
unsigned long txLedOnTime
Flash duration for Tx LED.
Definition: EnigmaIOTGateway.h:130
EnigmaIOTGatewayClass::doSave
static void doSave(void)
Activates a flag that signals that configuration has to be saved.
Definition: EnigmaIOTGateway.cpp:42
MSG_PACK
@ MSG_PACK
Definition: EnigmaIOTGateway.h:65
EnigmaIOTGatewayClass::notifyWiFiManagerStarted
simpleEventHandler_t notifyWiFiManagerStarted
Function called when configuration portal is started.
Definition: EnigmaIOTGateway.h:153
Node
Class definition for a single sensor Node.
Definition: NodeList.h:109
EnigmaIOTGatewayClass::gwConfig
gateway_config_t gwConfig
Gateway specific configuration to be stored on flash memory.
Definition: EnigmaIOTGateway.h:140
KEY_EXPIRED
@ KEY_EXPIRED
Definition: EnigmaIOTGateway.h:81
NodeList
Definition: NodeList.h:506
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:1660
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:854
EnigmaIOTGatewayClass::saveFlashData
bool saveFlashData()
Saves configuration to flash memory.
Definition: EnigmaIOTGateway.cpp:692
EnigmaIOTGatewayClass::rxled
int8_t rxled
I/O pin to connect a led that flashes when gateway receives data.
Definition: EnigmaIOTGateway.h:129
HA_DISCOVERY_MESSAGE
@ HA_DISCOVERY_MESSAGE
Definition: EnigmaIOTGateway.h:49
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:1175
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:1489
WRONG_DATA
@ WRONG_DATA
Definition: EnigmaIOTGateway.h:79
SERVER_HELLO
@ SERVER_HELLO
Definition: EnigmaIOTGateway.h:57
onWiFiManagerExit_t
void(* onWiFiManagerExit_t)(boolean status)
Definition: EnigmaIOTGateway.h:100
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:364
DEFAULT_CHANNEL
static const uint8_t DEFAULT_CHANNEL
WiFi channel to be used on ESP-NOW.
Definition: EnigmaIoTconfig.h:17
EnigmaIOTGatewayClass::getErrorPackets
uint32_t getErrorPackets(uint8_t *address)
Gets number of errored packets of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1476
CLOCK_REQUEST
@ CLOCK_REQUEST
Definition: EnigmaIOTGateway.h:50
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:97
EnigmaIOTGatewayClass::onGatewayRestartRequested
void onGatewayRestartRequested(simpleEventHandler_t handler)
Defines a function callback that will process a gateway restart request.
Definition: EnigmaIOTGateway.h:565
EnigmaIOTGatewayClass::notifyNewNode
onNewNode_t notifyNewNode
Callback function that will be invoked when a new node is connected.
Definition: EnigmaIOTGateway.h:136
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:1482
UNREGISTERED_NODE
@ UNREGISTERED_NODE
Definition: EnigmaIOTGateway.h:80
NODE_NAME_RESULT
@ NODE_NAME_RESULT
Definition: EnigmaIOTGateway.h:53
helperFunctions.h
Auxiliary function definition.
FLASH_LED_TIME
static const uint32_t FLASH_LED_TIME
Time that led keeps on during flash in ms.
Definition: EnigmaIoTconfig.h:18
UNKNOWN_ERROR
@ UNKNOWN_ERROR
Definition: EnigmaIOTGateway.h:76
SMILE
@ SMILE
Definition: EnigmaIOTGateway.h:68
gwInvalidateReason_t
gwInvalidateReason_t
Key invalidation reason definition.
Definition: EnigmaIOTGateway.h:75
EnigmaIOTGatewayClass::serverHello
bool serverHello(const uint8_t *key, Node *node)
Build a ServerHello message and send it to node.
Definition: EnigmaIOTGateway.cpp:1910
EnigmaIOTGatewayClass::loadFlashData
bool loadFlashData()
Loads configuration from flash memory.
Definition: EnigmaIOTGateway.cpp:611
DOWNSTREAM_BRCAST_CTRL_DATA
@ DOWNSTREAM_BRCAST_CTRL_DATA
Definition: EnigmaIOTGateway.h:48
CLIENT_HELLO
@ CLIENT_HELLO
Definition: EnigmaIOTGateway.h:56
NodeList::countActiveNodes
uint16_t countActiveNodes()
Gets the number of active nodes (registered or registering)
Definition: NodeList.cpp:247
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:1106
EnigmaIOTGatewayClass::getPER
double getPER(uint8_t *address)
Gets packet error rate of node that has a specific address.
Definition: EnigmaIOTGateway.cpp:1460
CAYENNELPP
@ CAYENNELPP
Definition: EnigmaIOTGateway.h:63
gateway_config_t
Definition: EnigmaIOTGateway.h:104
EnigmaIOTGatewayClass::plainNetKey
char plainNetKey[KEY_LENGTH]
Definition: EnigmaIOTGateway.h:141
Comms_hal.h
Generic communication system abstraction layer.
EnigmaIOTGatewayClass::getNetworkKey
char * getNetworkKey(bool plain=false)
Gets hashed EnigmaIOT network key.
Definition: EnigmaIOTGateway.h:357
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:736
gateway_config_t::networkName
char networkName[NETWORK_NAME_LENGTH]
Definition: EnigmaIOTGateway.h:107
INVALIDATE_KEY
@ INVALIDATE_KEY
Definition: EnigmaIOTGateway.h:58
onNodeDisconnected_t
void(* onNodeDisconnected_t)(uint8_t *mac, gwInvalidateReason_t reason)
Definition: EnigmaIOTGateway.h:99
EnigmaIOTGatewayClass::wifiManager
AsyncWiFiManager * wifiManager
Wifi configuration portal.
Definition: EnigmaIOTGateway.h:151
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:815
Comms_halClass
Interface for communication subsystem abstraction layer definition.
Definition: Comms_hal.h:41
EnigmaIOTGatewayClass::sendHADiscoveryJSON
bool sendHADiscoveryJSON(uint8_t *address, uint8_t *data, size_t len, const char *networkName, const char *nodeName)
Sends a Home Assistant discovery message after receiving it from node.
Definition: EnigmaIOTGateway.cpp:1989
UNENCRYPTED_NODE_DATA
@ UNENCRYPTED_NODE_DATA
Definition: EnigmaIOTGateway.h:41
EnigmaIOTGatewayClass::popInputMsgQueue
void popInputMsgQueue()
Deletes next item in the queue.
Definition: EnigmaIOTGateway.cpp:843
Filter.h
Filter to process message rate or other values.
BROADCAST_KEY_RESPONSE
@ BROADCAST_KEY_RESPONSE
Definition: EnigmaIOTGateway.h:55