EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
EnigmaIOTNode.h
Go to the documentation of this file.
1 
9 #ifndef _ENIGMAIOTNODE_h
10 #define _ENIGMAIOTNODE_h
11 //#ifdef ESP8266
12 
13 #if defined(ARDUINO) && ARDUINO >= 100
14 #include "Arduino.h"
15 #else
16 #include "WProgram.h"
17 #endif
18 
19 #include "EnigmaIoTconfig.h"
20 #include "cryptModule.h"
21 #include "helperFunctions.h"
22 #include "Comms_hal.h"
23 #include "NodeList.h"
24 #include <cstddef>
25 #include <cstdint>
26 #include <ESPAsyncWebServer.h>
27 #include <ESPAsyncWiFiManager.h>
28 
29 #define LED_ON HIGH
30 #define LED_OFF !LED_ON
31 
36  SENSOR_DATA = 0x01,
40  CONTROL_DATA = 0x03,
42  CLOCK_REQUEST = 0x05,
43  CLOCK_RESPONSE = 0x06,
44  NODE_NAME_SET = 0x07,
46  CLIENT_HELLO = 0xFF,
47  SERVER_HELLO = 0xFE,
48  INVALIDATE_KEY = 0xFB
49 };
50 
52  RAW = 0x00,
53  CAYENNELPP = 0x81,
54  PROT_BUF = 0x82,
55  MSG_PACK = 0x83,
56  BSON = 0x84,
57  CBOR = 0x85,
58  SMILE = 0x86
59 };
60 
61 
66  UNKNOWN_ERROR = 0x00,
68  WRONG_DATA = 0x03,
70  KEY_EXPIRED = 0x05
71 };
72 
76 typedef struct {
77  uint32_t crc32;
78  uint8_t nodeKey[KEY_LENGTH];
79  uint16_t nodeId;
80  uint8_t channel /*= DEFAULT_CHANNEL*/;
81  uint8_t gateway[ENIGMAIOT_ADDR_LEN];
82  int8_t rssi;
83  uint8_t networkKey[KEY_LENGTH];
84  char networkName[NETWORK_NAME_LENGTH];
85  bool sleepy;
86  uint32_t sleepTime /*= 0*/;
87  char nodeName[NODE_NAME_LENGTH + 1];
88  uint8_t commErrors /*= 0*/;
90  bool nodeKeyValid /* = false*/;
91  status_t nodeRegisterStatus /*= UNREGISTERED*/;
92  uint16_t lastMessageCounter;
94 
96 
97 #if defined ARDUINO_ARCH_ESP8266 || defined ARDUINO_ARCH_ESP32
98 #include <functional>
99 typedef std::function<void (const uint8_t* mac, const uint8_t* buf, uint8_t len, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)> onNodeDataRx_t;
100 typedef std::function<void ()> onConnected_t;
101 typedef std::function<void (nodeInvalidateReason_t reason)> onDisconnected_t;
102 typedef std::function<void (boolean status)> onWiFiManagerExit_t;
103 typedef std::function<void (void)> onWiFiManagerStarted_t;
104 #else
105 typedef void (*onNodeDataRx_t)(const uint8_t* mac, const uint8_t* buf, uint8_t len, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding);
106 typedef void (*onConnected_t)();
107 typedef void (*onDisconnected_t)(nodeInvalidateReason_t reason);
108 typedef void (*onWiFiManagerExit_t)(boolean status);
109 typedef void (*onWiFiManagerStarted_t)(void);
110 #endif
111 
117 protected:
119  bool flashBlue = false;
120  int8_t led = -1;
121  unsigned int ledOnTime;
126  bool useCounter = true;
128  bool sleepRequested = false;
129  uint64_t sleepTime;
131  uint8_t dataMessageSentLength = 0;
132  bool dataMessageSendPending = false;
134  bool dataMessageEncrypt = true;
136  bool otaRunning = false;
137  bool otaError = false;
138  time_t lastOTAmsg;
139  boolean indentifying = false;
140  time_t identifyStart;
142  bool clockSyncEnabled = false;
143  bool shouldRestart = false;
144  bool gatewaySearchStarted = false;
145  bool requestSearchGateway = false;
146  bool requestReportRSSI = false;
147  bool configCleared = false;
148  int resetPin = -1;
149  AsyncWiFiManager* wifiManager;
152 
160  bool checkCRC (const uint8_t* buf, size_t count, uint32_t* crc);
161 
166  void startIdentifying (time_t period);
167 
171  void stopIdentifying ();
172 
177  bool loadRTCData ();
178 
183  bool loadFlashData ();
184 
190  bool saveFlashData (bool fsOpen = false);
191 
199 
204  void restart (bool reboot = true);
205 
210  bool clientHello ();
211 
216  bool clockRequest ();
217 
226  bool processClockResponse (const uint8_t* mac, const uint8_t* buf, size_t count);
227 
235  bool processServerHello (const uint8_t* mac, const uint8_t* buf, size_t count);
236 
244  nodeInvalidateReason_t processInvalidateKey (const uint8_t* mac, const uint8_t* buf, size_t count);
245 
254  bool dataMessage (const uint8_t* data, size_t len, bool controlMessage = false, bool encrypt = true, nodePayloadEncoding_t payloadEncoding = CAYENNELPP);
255 
263  bool unencryptedDataMessage (const uint8_t* data, size_t len, bool controlMessage = false, nodePayloadEncoding_t payloadEncoding = CAYENNELPP);
264 
272  bool processOTACommand (const uint8_t* mac, const uint8_t* data, uint8_t len);
273 
281  bool processControlCommand (const uint8_t* mac, const uint8_t* data, size_t len);
282 
291  bool processDownstreamData (const uint8_t* mac, const uint8_t* buf, size_t count, bool control = false);
292 
301  void manageMessage (const uint8_t* mac, const uint8_t* buf, uint8_t count);
302 
308  void getStatus (uint8_t* mac_addr, uint8_t status);
309 
316  static void rx_cb (uint8_t* mac_addr, uint8_t* data, uint8_t len);
317 
324  static void tx_cb (uint8_t* mac_addr, uint8_t status);
325 
333  bool processGetSleepTimeCommand (const uint8_t* mac, const uint8_t* buf, uint8_t len);
334 
342  bool processSetSleepTimeCommand (const uint8_t* mac, const uint8_t* buf, uint8_t len);
343 
351  bool processSetIdentifyCommand (const uint8_t* mac, const uint8_t* buf, uint8_t len);
352 
360  bool processSetResetConfigCommand (const uint8_t* mac, const uint8_t* buf, uint8_t len);
361 
369  bool processVersionCommand (const uint8_t* mac, const uint8_t* buf, uint8_t len);
370 
380  bool sendData (const uint8_t* data, size_t len, bool controlMessage, bool encrypt = true, nodePayloadEncoding_t payloadEncoding = CAYENNELPP);
381 
388  bool searchForGateway (rtcmem_data_t* data, bool shouldStoreData = false);
389 
393  void clearRTC ();
394 
398  void clearFlash ();
399 
404  bool saveRTCData ();
405 
409  void checkResetButton ();
410 
415  bool reportRSSI ();
416 
424  bool processGetRSSICommand (const uint8_t* mac, const uint8_t* data, uint8_t len);
425 
433  bool processGetNameCommand (const uint8_t* mac, const uint8_t* data, uint8_t len);
434 
442  bool processSetNameResponse (const uint8_t* mac, const uint8_t* data, uint8_t len);
443 
451  bool processSetNameCommand (const uint8_t* mac, const uint8_t* data, uint8_t len);
452 
458  bool sendNodeNameSet (const char* name);
459 
460 public:
474  void begin (Comms_halClass* comm, uint8_t* gateway = NULL, uint8_t* networkKey = NULL, bool useCounter = true, bool sleepy = true);
475 
479  void stop ();
480 
486  void setSleepTime (uint32_t sleepTime);
487 
493  bool setNodeAddress (uint8_t address[ENIGMAIOT_ADDR_LEN]);
494 
499  uint32_t getSleepTime ();
500 
505  void handle ();
506 
511  void enableClockSync (bool clockSync = true) {
512  clockSyncEnabled = clockSync;
513  }
514 
520  void setLed (uint8_t led, time_t onTime = FLASH_LED_TIME);
521 
526  void setResetPin (int pin);
527 
534  bool sendData (const uint8_t* data, size_t len, nodePayloadEncoding_t payloadEncoding = CAYENNELPP) {
535  return sendData (data, len, false, true, payloadEncoding);
536  }
537 
544  bool sendUnencryptedData (const uint8_t* data, size_t len, nodePayloadEncoding_t payloadEncoding = CAYENNELPP) {
545  return sendData (data, len, false, false, payloadEncoding);
546  }
547 
571  void onDataRx (onNodeDataRx_t handler) {
572  notifyData = handler;
573  }
574 
598  void onConnected (onConnected_t handler) {
599  notifyConnection = handler;
600  }
601 
628  notifyDisconnection = handler;
629  }
630 
637  }
638 
645  }
646 
651  void addWiFiManagerParameter (AsyncWiFiManagerParameter* p) {
652  if (wifiManager) {
653  wifiManager->addParameter (p);
654  }
655  }
656 
662  void sleep ();
663 
668  int64_t clock ();
669 
674  time_t unixtime ();
675 
680  bool hasClockSync ();
681 
686  bool isRegistered () {
687  return node.isRegistered ();
688  }
689 
694  int8_t getRSSI ();
695 
699  void resetConfig ();
700 
701 };
702 
704 
705 //#endif // ESP8266
706 #endif // _ENIGMAIOTNODE_h
EnigmaIOTNodeClass::otaRunning
bool otaRunning
True if OTA update has started.
Definition: EnigmaIOTNode.h:136
EnigmaIOTNodeClass::notifyWiFiManagerExit
onWiFiManagerExit_t notifyWiFiManagerExit
Function called when configuration portal exits.
Definition: EnigmaIOTNode.h:150
EnigmaIOTNodeClass::otaError
bool otaError
True if OTA update has failed. This normally produces a restart.
Definition: EnigmaIOTNode.h:137
EnigmaIOTNodeClass::notifyData
onNodeDataRx_t notifyData
Callback that will be called on every message reception.
Definition: EnigmaIOTNode.h:123
WRONG_CLIENT_HELLO
@ WRONG_CLIENT_HELLO
Definition: EnigmaIOTNode.h:67
EnigmaIOTNodeClass::unixtime
time_t unixtime()
Gets current time in seconds from 1970, if time is synchronized.
Definition: EnigmaIOTNode.cpp:1181
onDisconnected_t
void(* onDisconnected_t)(nodeInvalidateReason_t reason)
Definition: EnigmaIOTNode.h:107
UNENCRYPTED_NODE_DATA
@ UNENCRYPTED_NODE_DATA
Definition: EnigmaIOTNode.h:37
nodeMessageType_t
nodeMessageType nodeMessageType_t
Definition: EnigmaIOTNode.h:95
rtcmem_data_t::nodeId
uint16_t nodeId
Definition: EnigmaIOTNode.h:79
EnigmaIOTNodeClass::hasClockSync
bool hasClockSync()
Checks if internal clock is synchronized to gateway.
Definition: EnigmaIOTNode.cpp:1189
EnigmaIOTNodeClass::enableClockSync
void enableClockSync(bool clockSync=true)
Controls clock synchronization function.
Definition: EnigmaIOTNode.h:511
EnigmaIOTNodeClass::sendData
bool sendData(const uint8_t *data, size_t len, bool controlMessage, bool encrypt=true, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Initiades data transmission distinguissing if it is payload or control data.
Definition: EnigmaIOTNode.cpp:1260
CONTROL_DATA
@ CONTROL_DATA
Definition: EnigmaIOTNode.h:40
SERVER_HELLO
@ SERVER_HELLO
Definition: EnigmaIOTNode.h:47
cryptModule.h
Crypto library that implements EnigmaIoT encryption, decryption and key agreement fuctions.
NodeList.h
EnigmaIoT sensor node management structures.
NODE_NAME_RESULT
@ NODE_NAME_RESULT
Definition: EnigmaIOTNode.h:45
EnigmaIOTNodeClass::clientHello
bool clientHello()
Build a ClientHello messange and send it to gateway.
Definition: EnigmaIOTNode.cpp:968
nodeMessageType
nodeMessageType
Message code definition.
Definition: EnigmaIOTNode.h:35
CBOR
@ CBOR
Definition: EnigmaIOTNode.h:57
EnigmaIOTNodeClass::searchForGateway
bool searchForGateway(rtcmem_data_t *data, bool shouldStoreData=false)
Starts searching for a gateway that it using configured Network Name as WiFi AP. Stores this info for...
Definition: EnigmaIOTNode.cpp:664
EnigmaIOTNodeClass::setResetPin
void setResetPin(int pin)
Sets a pin to be used to reset configuration it it is connected to ground during startup.
Definition: EnigmaIOTNode.cpp:72
EnigmaIOTNodeClass::led
int8_t led
IO Pin that corresponds to Tx LED. Default value disables LED. It is initialized with setLed method.
Definition: EnigmaIOTNode.h:120
RAW
@ RAW
Definition: EnigmaIOTNode.h:52
EnigmaIOTNodeClass::checkCRC
bool checkCRC(const uint8_t *buf, size_t count, uint32_t *crc)
Check that a given CRC matches to calulated value from a buffer.
Definition: EnigmaIOTNode.cpp:958
EnigmaIOTNodeClass::sendData
bool sendData(const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Starts a data message transmission.
Definition: EnigmaIOTNode.h:534
rtcmem_data_t::rssi
int8_t rssi
Definition: EnigmaIOTNode.h:82
EnigmaIOTNodeClass::rx_cb
static void rx_cb(uint8_t *mac_addr, uint8_t *data, uint8_t len)
Function that will be called anytime this node receives a message.
Definition: EnigmaIOTNode.cpp:950
EnigmaIOTNodeClass::processOTACommand
bool processOTACommand(const uint8_t *mac, const uint8_t *data, uint8_t len)
Processes a single OTA update command or data.
Definition: EnigmaIOTNode.cpp:1817
EnigmaIOTNodeClass::processSetSleepTimeCommand
bool processSetSleepTimeCommand(const uint8_t *mac, const uint8_t *buf, uint8_t len)
Processes a request to set new sleep time configuration.
Definition: EnigmaIOTNode.cpp:1754
EnigmaIOTNodeClass::processGetNameCommand
bool processGetNameCommand(const uint8_t *mac, const uint8_t *data, uint8_t len)
Processes a request to get Node name and address.
Definition: EnigmaIOTNode.cpp:1495
EnigmaIoTconfig.h
Parameter configuration.
rtcmem_data_t::crc32
uint32_t crc32
Definition: EnigmaIOTNode.h:77
ENIGMAIOT_ADDR_LEN
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
Definition: EnigmaIoTconfig.h:14
EnigmaIOTNodeClass::clearRTC
void clearRTC()
Clears configuration stored in RTC memory to recover factory state.
Definition: EnigmaIOTNode.cpp:1740
EnigmaIOTNodeClass::handle
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
Definition: EnigmaIOTNode.cpp:801
EnigmaIOTNode
EnigmaIOTNodeClass EnigmaIOTNode
Definition: EnigmaIOTNode.cpp:2229
SMILE
@ SMILE
Definition: EnigmaIOTNode.h:58
NODE_NAME_LENGTH
static const uint8_t NODE_NAME_LENGTH
Maximum number of characters of node name.
Definition: EnigmaIoTconfig.h:19
DOWNSTREAM_DATA_SET
@ DOWNSTREAM_DATA_SET
Definition: EnigmaIOTNode.h:38
EnigmaIOTNodeClass::checkResetButton
void checkResetButton()
Checks reset button status during startup.
Definition: EnigmaIOTNode.cpp:488
PROT_BUF
@ PROT_BUF
Definition: EnigmaIOTNode.h:54
EnigmaIOTNodeClass::resetPin
int resetPin
Pin used to reset configuration if it is connected to ground during startup.
Definition: EnigmaIOTNode.h:148
EnigmaIOTNodeClass::requestReportRSSI
bool requestReportRSSI
Flag to control RSSI reporting.
Definition: EnigmaIOTNode.h:146
UNREGISTERED_NODE
@ UNREGISTERED_NODE
Definition: EnigmaIOTNode.h:69
EnigmaIOTNodeClass::setSleepTime
void setSleepTime(uint32_t sleepTime)
Allows to configure a new sleep time period from user code.
Definition: EnigmaIOTNode.cpp:746
EnigmaIOTNodeClass::indentifying
boolean indentifying
True if node has its led flashing to be identified.
Definition: EnigmaIOTNode.h:139
EnigmaIOTNodeClass::processSetNameResponse
bool processSetNameResponse(const uint8_t *mac, const uint8_t *data, uint8_t len)
Processes a response to set Node name.
Definition: EnigmaIOTNode.cpp:1529
status_t
enum node_status status_t
Node state.
Definition: NodeList.h:39
EnigmaIOTNodeClass::flashBlue
bool flashBlue
If true Tx LED will be flashed.
Definition: EnigmaIOTNode.h:119
EnigmaIOTNodeClass::getSleepTime
uint32_t getSleepTime()
Returns sleep period in seconds.
Definition: EnigmaIOTNode.cpp:55
EnigmaIOTNodeClass::sendUnencryptedData
bool sendUnencryptedData(const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Starts a data message transmission.
Definition: EnigmaIOTNode.h:544
EnigmaIOTNodeClass::comm
Comms_halClass * comm
Comms abstraction layer.
Definition: EnigmaIOTNode.h:122
BSON
@ BSON
Definition: EnigmaIOTNode.h:56
EnigmaIOTNodeClass::dataMessageSent
uint8_t dataMessageSent[MAX_MESSAGE_LENGTH]
Buffer where sent message is stored in case of retransmission is needed.
Definition: EnigmaIOTNode.h:130
EnigmaIOTNodeClass::processSetIdentifyCommand
bool processSetIdentifyCommand(const uint8_t *mac, const uint8_t *buf, uint8_t len)
Processes a request to start indicate to identify a node visually.
Definition: EnigmaIOTNode.cpp:1691
EnigmaIOTNodeClass::timeSyncPeriod
clock_t timeSyncPeriod
Clock synchronization period.
Definition: EnigmaIOTNode.h:141
EnigmaIOTNodeClass::clockRequest
bool clockRequest()
Build a ClockRequest messange and send it to gateway.
Definition: EnigmaIOTNode.cpp:1057
MSG_PACK
@ MSG_PACK
Definition: EnigmaIOTNode.h:55
EnigmaIOTNodeClass::sleep
void sleep()
Requests transition to sleep mode (low energy state)
Definition: EnigmaIOTNode.cpp:1287
INVALIDATE_KEY
@ INVALIDATE_KEY
Definition: EnigmaIOTNode.h:48
EnigmaIOTNodeClass::processSetResetConfigCommand
bool processSetResetConfigCommand(const uint8_t *mac, const uint8_t *buf, uint8_t len)
Processes a request to reset node configuration.
Definition: EnigmaIOTNode.cpp:1711
WRONG_DATA
@ WRONG_DATA
Definition: EnigmaIOTNode.h:68
EnigmaIOTNodeClass::tx_cb
static void tx_cb(uint8_t *mac_addr, uint8_t status)
Function that will be called anytime this node sends a message to indicate status result of sending p...
Definition: EnigmaIOTNode.cpp:954
EnigmaIOTNodeClass::processServerHello
bool processServerHello(const uint8_t *mac, const uint8_t *buf, size_t count)
Gets a buffer containing a ServerHello message and process it. It uses that message to calculate a sh...
Definition: EnigmaIOTNode.cpp:1196
QUICK_SYNC_TIME
static const unsigned int QUICK_SYNC_TIME
Period of clock synchronization request in case of resync is needed.
Definition: EnigmaIoTconfig.h:46
EnigmaIOTNodeClass::onWiFiManagerExit
void onWiFiManagerExit(onWiFiManagerExit_t handle)
Register callback to be called on wifi manager exit.
Definition: EnigmaIOTNode.h:635
rtcmem_data_t::lastMessageCounter
uint16_t lastMessageCounter
Definition: EnigmaIOTNode.h:92
EnigmaIOTNodeClass::clearFlash
void clearFlash()
Clears configuration stored in flash to recover factory state.
Definition: EnigmaIOTNode.cpp:309
EnigmaIOTNodeClass::onDisconnected
void onDisconnected(onDisconnected_t handler)
Defines a function callback that will be called everytime node is disconnected from gateway.
Definition: EnigmaIOTNode.h:627
EnigmaIOTNodeClass::configWiFiManager
bool configWiFiManager(rtcmem_data_t *data)
Starts configuration AP and web server and gets settings from it.
Definition: EnigmaIOTNode.cpp:321
EnigmaIOTNodeClass::resetConfig
void resetConfig()
Deletes configuration file stored on SPIFFS. It makes neccessary to configure it again using WiFi Por...
Definition: EnigmaIOTNode.cpp:45
EnigmaIOTNodeClass::sleepTime
uint64_t sleepTime
Time in microseconds that this node will be slept between measurements.
Definition: EnigmaIOTNode.h:129
EnigmaIOTNodeClass::dataMessage
bool dataMessage(const uint8_t *data, size_t len, bool controlMessage=false, bool encrypt=true, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Builds, encrypts and sends a Data message.
Definition: EnigmaIOTNode.cpp:1361
DOWNSTREAM_DATA_GET
@ DOWNSTREAM_DATA_GET
Definition: EnigmaIOTNode.h:39
EnigmaIOTNodeClass::stopIdentifying
void stopIdentifying()
Stops node identification.
Definition: EnigmaIOTNode.cpp:483
EnigmaIOTNodeClass::dataMessageSendPending
bool dataMessageSendPending
True in case of message retransmission is needed.
Definition: EnigmaIOTNode.h:132
EnigmaIOTNodeClass::notifyConnection
onConnected_t notifyConnection
Callback that will be called anytime a new node is registered.
Definition: EnigmaIOTNode.h:124
EnigmaIOTNodeClass::processControlCommand
bool processControlCommand(const uint8_t *mac, const uint8_t *data, size_t len)
Processes a control command. Does not propagate to user code.
Definition: EnigmaIOTNode.cpp:1987
EnigmaIOTNodeClass::unencryptedDataMessage
bool unencryptedDataMessage(const uint8_t *data, size_t len, bool controlMessage=false, nodePayloadEncoding_t payloadEncoding=CAYENNELPP)
Builds and sends a Data message without encryption. Not recommended, use it only if you absolutely ne...
Definition: EnigmaIOTNode.cpp:1297
nodePayloadEncoding_t
nodePayloadEncoding_t
Definition: EnigmaIOTNode.h:51
EnigmaIOTNodeClass::useCounter
bool useCounter
true means that data message counter will be used to mark message order
Definition: EnigmaIOTNode.h:126
UNKNOWN_ERROR
@ UNKNOWN_ERROR
Definition: EnigmaIOTNode.h:66
EnigmaIOTNodeClass::processSetNameCommand
bool processSetNameCommand(const uint8_t *mac, const uint8_t *data, uint8_t len)
Processes a request to set Node name.
Definition: EnigmaIOTNode.cpp:1577
EnigmaIOTNodeClass::isRegistered
bool isRegistered()
Checks if node is registered.
Definition: EnigmaIOTNode.h:686
EnigmaIOTNodeClass::ledOnTime
unsigned int ledOnTime
Time that LED is On during flash. Initalized on setLed
Definition: EnigmaIOTNode.h:121
EnigmaIOTNodeClass::node
Node node
Node abstraction to store context.
Definition: EnigmaIOTNode.h:118
EnigmaIOTNodeClass::sendNodeNameSet
bool sendNodeNameSet(const char *name)
Informs Gateway about custom node name.
Definition: EnigmaIOTNode.cpp:1614
EnigmaIOTNodeClass::addWiFiManagerParameter
void addWiFiManagerParameter(AsyncWiFiManagerParameter *p)
Adds a parameter to configuration portal.
Definition: EnigmaIOTNode.h:651
EnigmaIOTNodeClass::invalidateReason
nodeInvalidateReason_t invalidateReason
Last key invalidation reason.
Definition: EnigmaIOTNode.h:135
EnigmaIOTNodeClass::rtcmem_data
rtcmem_data_t rtcmem_data
Context data to be stored on persistent storage.
Definition: EnigmaIOTNode.h:127
EnigmaIOTNodeClass::loadRTCData
bool loadRTCData()
Loads configuration from RTC data. Uses a CRC to check data integrity.
Definition: EnigmaIOTNode.cpp:113
EnigmaIOTNodeClass::clockSyncEnabled
bool clockSyncEnabled
If true clock is synchronized with Gateway.
Definition: EnigmaIOTNode.h:142
MAX_MESSAGE_LENGTH
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
Definition: EnigmaIoTconfig.h:13
EnigmaIOTNodeClass::sleepRequested
bool sleepRequested
true means that this node will sleep as soon a message is sent and downlink wait time has passed
Definition: EnigmaIOTNode.h:128
NODE_NAME_SET
@ NODE_NAME_SET
Definition: EnigmaIOTNode.h:44
EnigmaIOTNodeClass::processVersionCommand
bool processVersionCommand(const uint8_t *mac, const uint8_t *buf, uint8_t len)
Processes a request firmware version.
Definition: EnigmaIOTNode.cpp:1799
EnigmaIOTNodeClass::processDownstreamData
bool processDownstreamData(const uint8_t *mac, const uint8_t *buf, size_t count, bool control=false)
Processes downstream data from gateway.
Definition: EnigmaIOTNode.cpp:2018
EnigmaIOTNodeClass::wifiManager
AsyncWiFiManager * wifiManager
Wifi configuration portal.
Definition: EnigmaIOTNode.h:149
EnigmaIOTNodeClass::processClockResponse
bool processClockResponse(const uint8_t *mac, const uint8_t *buf, size_t count)
Gets a buffer containing a ClockResponse message and process it. It uses that message to calculate cl...
Definition: EnigmaIOTNode.cpp:1109
EnigmaIOTNodeClass::dataMessageEncrypt
bool dataMessageEncrypt
Message encryption enabled. Stored for use in case of message retransmission is needed.
Definition: EnigmaIOTNode.h:134
EnigmaIOTNodeClass::onConnected
void onConnected(onConnected_t handler)
Defines a function callback that will be called everytime node is registered on gateway.
Definition: EnigmaIOTNode.h:598
EnigmaIOTNodeClass::notifyWiFiManagerStarted
onWiFiManagerStarted_t notifyWiFiManagerStarted
Function called when configuration portal is started.
Definition: EnigmaIOTNode.h:151
Node
Class definition for a single sensor Node.
Definition: NodeList.h:93
CLOCK_REQUEST
@ CLOCK_REQUEST
Definition: EnigmaIOTNode.h:42
onWiFiManagerExit_t
void(* onWiFiManagerExit_t)(boolean status)
Definition: EnigmaIOTNode.h:108
EnigmaIOTNodeClass::lastOTAmsg
time_t lastOTAmsg
Time when last OTA update message has received. This is used to control timeout.
Definition: EnigmaIOTNode.h:138
KEY_EXPIRED
@ KEY_EXPIRED
Definition: EnigmaIOTNode.h:70
EnigmaIOTNodeClass::begin
void begin(Comms_halClass *comm, uint8_t *gateway=NULL, uint8_t *networkKey=NULL, bool useCounter=true, bool sleepy=true)
Initalizes communication basic data and starts node registration.
Definition: EnigmaIOTNode.cpp:510
EnigmaIOTNodeClass::notifyDisconnection
onDisconnected_t notifyDisconnection
Callback that will be called anytime a node is disconnected.
Definition: EnigmaIOTNode.h:125
Node::isRegistered
bool isRegistered()
Gets registration state of this node.
Definition: NodeList.h:244
EnigmaIOTNodeClass::identifyStart
time_t identifyStart
Time when identification started flashing. Used to control identification timeout.
Definition: EnigmaIOTNode.h:140
EnigmaIOTNodeClass::processInvalidateKey
nodeInvalidateReason_t processInvalidateKey(const uint8_t *mac, const uint8_t *buf, size_t count)
Gets a buffer containing an InvalidateKey message and process it. This trigger a new key agreement to...
Definition: EnigmaIOTNode.cpp:2074
SENSOR_DATA
@ SENSOR_DATA
Definition: EnigmaIOTNode.h:36
EnigmaIOTNodeClass::setLed
void setLed(uint8_t led, time_t onTime=FLASH_LED_TIME)
Sets a LED to be flashed every time a message is transmitted.
Definition: EnigmaIOTNode.cpp:67
EnigmaIOTNodeClass::saveRTCData
bool saveRTCData()
Save configuration to RTC to store current status and recover it after deep sleep.
Definition: EnigmaIOTNode.cpp:286
EnigmaIOTNodeClass::loadFlashData
bool loadFlashData()
Loads configuration from flash memory.
Definition: EnigmaIOTNode.cpp:159
EnigmaIOTNodeClass::onWiFiManagerStarted
void onWiFiManagerStarted(onWiFiManagerStarted_t handle)
Register callback to be called on wifi manager start.
Definition: EnigmaIOTNode.h:643
data
@ data
Definition: GwOutput_generic.h:23
CLOCK_RESPONSE
@ CLOCK_RESPONSE
Definition: EnigmaIOTNode.h:43
DOWNSTREAM_CTRL_DATA
@ DOWNSTREAM_CTRL_DATA
Definition: EnigmaIOTNode.h:41
EnigmaIOTNodeClass::reportRSSI
bool reportRSSI()
Sends RSSI value and channel to Gateway.
Definition: EnigmaIOTNode.cpp:780
EnigmaIOTNodeClass::shouldRestart
bool shouldRestart
Triggers a restart if true.
Definition: EnigmaIOTNode.h:143
EnigmaIOTNodeClass::getStatus
void getStatus(uint8_t *mac_addr, uint8_t status)
Functrion to debug send status.
Definition: EnigmaIOTNode.cpp:2214
NETWORK_NAME_LENGTH
static const uint8_t NETWORK_NAME_LENGTH
Maximum number of characters of network name.
Definition: EnigmaIoTconfig.h:18
CLIENT_HELLO
@ CLIENT_HELLO
Definition: EnigmaIOTNode.h:46
EnigmaIOTNodeClass
Main node class. Manages communication with gateway and allows sending and receiving user data.
Definition: EnigmaIOTNode.h:116
EnigmaIOTNodeClass::processGetSleepTimeCommand
bool processGetSleepTimeCommand(const uint8_t *mac, const uint8_t *buf, uint8_t len)
Processes a request of sleep time configuration.
Definition: EnigmaIOTNode.cpp:1472
CAYENNELPP
@ CAYENNELPP
Definition: EnigmaIOTNode.h:53
helperFunctions.h
Auxiliary function definition.
EnigmaIOTNodeClass::stop
void stop()
Stops EnigmaIoT protocol.
Definition: EnigmaIOTNode.cpp:736
EnigmaIOTNodeClass::processGetRSSICommand
bool processGetRSSICommand(const uint8_t *mac, const uint8_t *data, uint8_t len)
Processes a request to measure RSSI.
Definition: EnigmaIOTNode.cpp:1704
EnigmaIOTNodeClass::setNodeAddress
bool setNodeAddress(uint8_t address[ENIGMAIOT_ADDR_LEN])
Set node address to be used in EnigmaIOT communication.
Definition: EnigmaIOTNode.cpp:741
EnigmaIOTNodeClass::requestSearchGateway
bool requestSearchGateway
Flag to control updating gateway address, RSSI and channel.
Definition: EnigmaIOTNode.h:145
nodeInvalidateReason_t
nodeInvalidateReason_t
Key invalidation reason definition.
Definition: EnigmaIOTNode.h:65
EnigmaIOTNodeClass::saveFlashData
bool saveFlashData(bool fsOpen=false)
Saves configuration to flash memory.
Definition: EnigmaIOTNode.cpp:233
rtcmem_data_t::sleepy
bool sleepy
Definition: EnigmaIOTNode.h:85
FLASH_LED_TIME
static const uint32_t FLASH_LED_TIME
Time that led keeps on during flash in ms.
Definition: EnigmaIoTconfig.h:17
EnigmaIOTNodeClass::clock
int64_t clock()
Gets current clock counter. millis() + offset.
Definition: EnigmaIOTNode.cpp:1172
EnigmaIOTNodeClass::dataMessageSendEncoding
nodePayloadEncoding_t dataMessageSendEncoding
Encoding of the message pending to be sent.
Definition: EnigmaIOTNode.h:133
EnigmaIOTNodeClass::manageMessage
void manageMessage(const uint8_t *mac, const uint8_t *buf, uint8_t count)
Process every received message.
Definition: EnigmaIOTNode.cpp:2090
onNodeDataRx_t
void(* onNodeDataRx_t)(const uint8_t *mac, const uint8_t *buf, uint8_t len, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
Definition: EnigmaIOTNode.h:105
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
Comms_hal.h
Generic communication system abstraction layer.
EnigmaIOTNodeClass::gatewaySearchStarted
bool gatewaySearchStarted
Avoids start a new gateway scan if it already started.
Definition: EnigmaIOTNode.h:144
EnigmaIOTNodeClass::configCleared
bool configCleared
This flag disables asy configuration save after triggering a factory reset.
Definition: EnigmaIOTNode.h:147
rtcmem_data_t
Context data to be stored con persistent storage to be used after wake from sleep mode.
Definition: EnigmaIOTNode.h:76
onWiFiManagerStarted_t
void(* onWiFiManagerStarted_t)(void)
Definition: EnigmaIOTNode.h:109
status
@ status
Definition: GwOutput_generic.h:25
EnigmaIOTNodeClass::getRSSI
int8_t getRSSI()
Gets latest RSSI measurement. It is updated during start up or in case of transmission errors.
Definition: EnigmaIOTNode.cpp:63
EnigmaIOTNodeClass::startIdentifying
void startIdentifying(time_t period)
Starts node identification by flashing led.
Definition: EnigmaIOTNode.cpp:477
Comms_halClass
Interface for communication subsystem abstraction layer definition.
Definition: Comms_hal.h:33
EnigmaIOTNodeClass::restart
void restart(bool reboot=true)
Sets connection as unregistered to force a resyncrhonisation after boot.
Definition: EnigmaIOTNode.cpp:1976
EnigmaIOTNodeClass::dataMessageSentLength
uint8_t dataMessageSentLength
Message length stored for use in case of message retransmission is needed.
Definition: EnigmaIOTNode.h:131
onConnected_t
void(* onConnected_t)()
Definition: EnigmaIOTNode.h:106
EnigmaIOTNodeClass::onDataRx
void onDataRx(onNodeDataRx_t handler)
Defines a function callback that will be called on every downlink data message that is received from ...
Definition: EnigmaIOTNode.h:571