|
EnigmaIOT
0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Main gateway class. Manages communication with nodes and sends data to upper layer. More...
#include <EnigmaIOTGateway.h>
Public Member Functions | |
| bool | getShouldSave () |
| Gets flag that indicates if configuration should be saved. More... | |
| char * | getNetworkName () |
| Gets EnigmaIOT network name. More... | |
| char * | getNetworkKey (bool plain=false) |
| Gets hashed EnigmaIOT network key. More... | |
| void | addWiFiManagerParameter (AsyncWiFiManagerParameter *p) |
| Adds a parameter to configuration portal. More... | |
| void | onWiFiManagerExit (onWiFiManagerExit_t handle) |
| Register callback to be called on wifi manager exit. More... | |
| void | onWiFiManagerStarted (onWiFiManagerStarted_t handle) |
| Register callback to be called on wifi manager start. More... | |
| bool | configWiFiManager () |
| Starts configuration AP and web server and gets settings from it. More... | |
| void | begin (Comms_halClass *comm, uint8_t *networkKey=NULL, bool useDataCounter=true) |
| Initalizes communication basic data and starts accepting node registration. More... | |
| void | handle () |
This method should be called periodically for instance inside loop() function. It is used for internal gateway maintenance tasks. More... | |
| void | setTxLed (uint8_t led, time_t onTime=FLASH_LED_TIME) |
| Sets a LED to be flashed every time a message is transmitted. More... | |
| void | setRxLed (uint8_t led, time_t onTime=FLASH_LED_TIME) |
| Sets a LED to be flashed every time a message is received. More... | |
| void | onDataRx (onGwDataRx_t handler) |
| Defines a function callback that will be called on every downlink data message that is received from a node. More... | |
| double | getPER (uint8_t *address) |
| Gets packet error rate of node that has a specific address. More... | |
| uint32_t | getTotalPackets (uint8_t *address) |
| Gets total packets sent by node that has a specific address. More... | |
| uint32_t | getErrorPackets (uint8_t *address) |
| Gets number of errored packets of node that has a specific address. More... | |
| double | getPacketsHour (uint8_t *address) |
| Gets packet rate sent by node that has a specific address, in packets per hour. More... | |
| 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. More... | |
| void | onNewNode (onNewNode_t handler) |
| Defines a function callback that will be called every time a node gets connected or reconnected. More... | |
| void | onNodeDisconnected (onNodeDisconnected_t handler) |
| Defines a function callback that will be called every time a node is disconnected. More... | |
| bool | addInputMsgQueue (const uint8_t *addr, const uint8_t *msg, size_t len) |
| Add message to input queue. More... | |
| msg_queue_item_t * | getInputMsgQueue (msg_queue_item_t *buffer) |
| Gets next item in the queue. More... | |
| void | popInputMsgQueue () |
| Deletes next item in the queue. More... | |
| int | getActiveNodesNumber () |
| Gets number of active nodes. More... | |
| NodeList * | getNodes () |
| Gets nodes data structure. More... | |
Protected Member Functions | |
| bool | serverHello (const uint8_t *key, Node *node) |
| Build a ServerHello messange and send it to node. More... | |
| 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 used on Diffie Hellman algorithm. More... | |
| 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. More... | |
| bool | clockResponse (Node *node) |
| Returns timestaps needed so that node can calculate time difference. More... | |
| bool | invalidateKey (Node *node, gwInvalidateReason_t reason) |
| Creates an InvalidateKey message and sned it. This trigger a new key agreement to start on related node. More... | |
| 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. More... | |
| bool | processUnencryptedDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node) |
| Processes unencrypted data message from node. More... | |
| 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. More... | |
| bool | processControlMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node) |
| Processes control message from node. More... | |
| bool | processNodeNameSet (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node) |
| Processes new node name request fromn node. More... | |
| bool | nodeNameSetRespose (Node *node, int8_t error) |
| Send back set name response. More... | |
| void | manageMessage (const uint8_t *mac, uint8_t *buf, uint8_t count) |
| Process every received message. More... | |
| void | getStatus (uint8_t *mac_addr, uint8_t status) |
| Functrion to debug send status. More... | |
| bool | loadFlashData () |
| Loads configuration from flash memory. More... | |
| bool | saveFlashData () |
| Saves configuration to flash memory. More... | |
Static Protected Member Functions | |
| static void | doSave (void) |
| Activates a flag that signals that configuration has to be saved. More... | |
| 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. More... | |
| 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 sending process. More... | |
Protected Attributes | |
| uint8_t | myPublicKey [KEY_LENGTH] |
| Temporary public key store used during key agreement. More... | |
| bool | flashTx = false |
true if Tx LED should flash More... | |
| volatile bool | flashRx = false |
true if Rx LED should flash More... | |
| node_t | node |
| temporary store to keep node data while processing a message More... | |
| NodeList | nodelist |
| Node database that keeps status and shared keys. More... | |
| Comms_halClass * | comm |
| Instance of physical communication layer. More... | |
| int8_t | txled = -1 |
| I/O pin to connect a led that flashes when gateway transmits data. More... | |
| int8_t | rxled = -1 |
| I/O pin to connect a led that flashes when gateway receives data. More... | |
| unsigned long | txLedOnTime |
| Flash duration for Tx LED. More... | |
| unsigned long | rxLedOnTime |
| Flash duration for Rx LED. More... | |
| onGwDataRx_t | notifyData |
| Callback function that will be invoked when data is received fron a node. More... | |
| onNewNode_t | notifyNewNode |
| Callback function that will be invoked when a new node is connected. More... | |
| onNodeDisconnected_t | notifyNodeDisconnection |
| Callback function that will be invoked when a node gets disconnected. More... | |
| bool | useCounter = true |
true if counter is used to check data messages order More... | |
| gateway_config_t | gwConfig |
| Gateway specific configuration to be stored on flash memory. More... | |
| char | plainNetKey [KEY_LENGTH] |
| msg_queue_item_t | tempBuffer |
| Temporary storage for input message got from buffer. More... | |
| EnigmaIOTRingBuffer< msg_queue_item_t > * | input_queue |
| Input messages buffer. It acts as a FIFO queue. More... | |
| AsyncWebServer * | server |
| WebServer that holds configuration portal. More... | |
| DNSServer * | dns |
| DNS server used by configuration portal. More... | |
| AsyncWiFiManager * | wifiManager |
| Wifi configuration portal. More... | |
| onWiFiManagerExit_t | notifyWiFiManagerExit |
| Function called when configuration portal exits. More... | |
| onWiFiManagerStarted_t | notifyWiFiManagerStarted |
| Function called when configuration portal is started. More... | |
Main gateway class. Manages communication with nodes and sends data to upper layer.
Definition at line 204 of file EnigmaIOTGateway.h.
| bool EnigmaIOTGatewayClass::addInputMsgQueue | ( | const uint8_t * | addr, |
| const uint8_t * | msg, | ||
| size_t | len | ||
| ) |
Add message to input queue.
| addr | Origin address |
| msg | EnigmaIoT message |
| len | Message length |
Definition at line 712 of file EnigmaIOTGateway.cpp.
|
inline |
Adds a parameter to configuration portal.
| p | Configuration parameter |
Definition at line 419 of file EnigmaIOTGateway.h.
| void EnigmaIOTGatewayClass::begin | ( | Comms_halClass * | comm, |
| uint8_t * | networkKey = NULL, |
||
| bool | useDataCounter = true |
||
| ) |
Initalizes communication basic data and starts accepting node registration.
| comm | Physical layer to be used on this network |
| networkKey | Network key to protect shared key agreement |
| useDataCounter | Indicates if a counter is going to be added to every message data to check message sequence. true by default |
Definition at line 667 of file EnigmaIOTGateway.cpp.
|
protected |
Returns timestaps needed so that node can calculate time difference.
| node | Pointer to data that corresponds to originating node |
true if message could be correcly processed Definition at line 1603 of file EnigmaIOTGateway.cpp.
| bool EnigmaIOTGatewayClass::configWiFiManager | ( | ) |
Starts configuration AP and web server and gets settings from it.
true if data was been correctly configured. false otherwise Definition at line 443 of file EnigmaIOTGateway.cpp.
|
staticprotected |
Activates a flag that signals that configuration has to be saved.
Definition at line 34 of file EnigmaIOTGateway.cpp.
|
protected |
Builds, encrypts and sends a DownstreamData message.
| node | Node that downstream data message is going to |
| data | Buffer to store payload to be sent |
| len | Length of payload data |
| controlData | Content data type if control data |
| encoding | Identifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK |
true if message could be correcly sent or scheduled Definition at line 1328 of file EnigmaIOTGateway.cpp.
|
inline |
Gets number of active nodes.
Definition at line 624 of file EnigmaIOTGateway.h.
| uint32_t EnigmaIOTGatewayClass::getErrorPackets | ( | uint8_t * | address | ) |
Gets number of errored packets of node that has a specific address.
| address | Node address |
Definition at line 1315 of file EnigmaIOTGateway.cpp.
| msg_queue_item_t * EnigmaIOTGatewayClass::getInputMsgQueue | ( | msg_queue_item_t * | buffer | ) |
Gets next item in the queue.
Definition at line 735 of file EnigmaIOTGateway.cpp.
|
inline |
Gets hashed EnigmaIOT network key.
Definition at line 408 of file EnigmaIOTGateway.h.
|
inline |
Gets EnigmaIOT network name.
Definition at line 400 of file EnigmaIOTGateway.h.
|
inline |
Gets nodes data structure.
Definition at line 632 of file EnigmaIOTGateway.h.
| double EnigmaIOTGatewayClass::getPacketsHour | ( | uint8_t * | address | ) |
Gets packet rate sent by node that has a specific address, in packets per hour.
| address | Node address |
Definition at line 1321 of file EnigmaIOTGateway.cpp.
| double EnigmaIOTGatewayClass::getPER | ( | uint8_t * | address | ) |
Gets packet error rate of node that has a specific address.
| address | Node address |
Definition at line 1299 of file EnigmaIOTGateway.cpp.
| bool EnigmaIOTGatewayClass::getShouldSave | ( | ) |
Gets flag that indicates if configuration should be saved.
true if config data should be saved. false otherwise Definition at line 39 of file EnigmaIOTGateway.cpp.
|
protected |
Functrion to debug send status.
| mac_addr | Address of message sender |
| status | Result status code |
Definition at line 778 of file EnigmaIOTGateway.cpp.
| uint32_t EnigmaIOTGatewayClass::getTotalPackets | ( | uint8_t * | address | ) |
Gets total packets sent by node that has a specific address.
| address | Node address |
Definition at line 1309 of file EnigmaIOTGateway.cpp.
| void EnigmaIOTGatewayClass::handle | ( | ) |
This method should be called periodically for instance inside loop() function. It is used for internal gateway maintenance tasks.
digitalRead (rxled) &&
digitalRead (txled) &&
Definition at line 787 of file EnigmaIOTGateway.cpp.
|
protected |
Creates an InvalidateKey message and sned it. This trigger a new key agreement to start on related node.
| node | Node to send Invalidate Key message to |
| reason | Reason that produced key invalidation in gwInvalidateReason_t format |
true if message could be correcly sent Definition at line 1444 of file EnigmaIOTGateway.cpp.
|
protected |
Loads configuration from flash memory.
true if data was read successfuly. false otherwise Definition at line 553 of file EnigmaIOTGateway.cpp.
|
protected |
Process every received message.
It starts clasiffying message usint the first byte. After that it passes it to the corresponding method for decoding
| mac | Address of message sender |
| buf | Buffer that stores message bytes |
| count | Length of message in number of bytes |
Definition at line 853 of file EnigmaIOTGateway.cpp.
|
protected |
Send back set name response.
| node | Pointer to data that corresponds to originating node |
| error | Result code of name set procedure (0: OK, -1: Already used, -2: Too long, -3: Empty name, -4: Message error) |
true if message could be correcly processed Definition at line 996 of file EnigmaIOTGateway.cpp.
|
inline |
Defines a function callback that will be called on every downlink data message that is received from a node.
Use example:
| handler | Pointer to the function |
Definition at line 500 of file EnigmaIOTGateway.h.
|
inline |
Defines a function callback that will be called every time a node gets connected or reconnected.
Use example:
| handler | Pointer to the function |
Definition at line 568 of file EnigmaIOTGateway.h.
|
inline |
Defines a function callback that will be called every time a node is disconnected.
Use example:
| handler | Pointer to the function |
Definition at line 597 of file EnigmaIOTGateway.h.
|
inline |
Register callback to be called on wifi manager exit.
| handle | Callback function pointer |
Definition at line 429 of file EnigmaIOTGateway.h.
|
inline |
Register callback to be called on wifi manager start.
| handle | Callback function pointer |
Definition at line 437 of file EnigmaIOTGateway.h.
| void EnigmaIOTGatewayClass::popInputMsgQueue | ( | ) |
Deletes next item in the queue.
Definition at line 763 of file EnigmaIOTGateway.cpp.
|
protected |
Gets a buffer containing a ClientHello message and process it. This carries node public key to be used on Diffie Hellman algorithm.
| mac | Address where this message was received from |
| buf | Pointer to the buffer that contains the message |
| count | Message length in number of bytes of ClientHello message |
| node | Node entry that Client Hello message comes from |
true if message could be correcly processed Definition at line 1471 of file EnigmaIOTGateway.cpp.
|
protected |
Starts clock sync procedure from node to gateway.
| mac | Address where this message was received from |
| buf | Pointer to the buffer that contains the message |
| count | Message length in number of bytes of ClockRequest message |
| node | Node entry that Client Hello message comes from |
true if message could be correcly processed Definition at line 1543 of file EnigmaIOTGateway.cpp.
|
protected |
Processes control message from node.
| mac | Node address |
| buf | Buffer that stores received message |
| count | Length of received data |
| node | Node where data message comes from |
true if message could be correcly decoded Definition at line 1112 of file EnigmaIOTGateway.cpp.
|
protected |
Processes data message from node.
| mac | Node address |
| buf | Buffer that stores received message |
| count | Length of received data |
| node | Node where data message comes from |
| encrypted | true if received message is encrypted |
true if message could be correcly decoded Definition at line 1225 of file EnigmaIOTGateway.cpp.
|
protected |
Processes new node name request fromn node.
| mac | Node address |
| buf | Buffer that stores received message |
| count | Length of received data |
| node | Node where data message comes from |
true if message could be correcly decoded Definition at line 1052 of file EnigmaIOTGateway.cpp.
|
protected |
Processes unencrypted data message from node.
| mac | Node address |
| buf | Buffer that stores received message |
| count | Length of received data |
| node | Node where data message comes from |
true if message could be correcly decoded Definition at line 1172 of file EnigmaIOTGateway.cpp.
|
staticprotected |
Function that will be called anytime this gateway receives a message.
| mac_addr | Address of message sender |
| data | Buffer that stores message bytes |
| len | Length of message in number of bytes |
Definition at line 769 of file EnigmaIOTGateway.cpp.
|
protected |
Saves configuration to flash memory.
true if data could be written successfuly. false otherwise Definition at line 624 of file EnigmaIOTGateway.cpp.
| bool EnigmaIOTGatewayClass::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.
| mac | Node address |
| data | Payload buffer |
| len | Payload length |
| controlData | Indicates if data is control data and its class |
| payload_type | Identifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK |
Definition at line 325 of file EnigmaIOTGateway.cpp.
|
protected |
Build a ServerHello messange and send it to node.
| key | Node public key to be used on Diffie Hellman algorithm |
| node | Entry in node list database where node will be registered |
true if ServerHello message was successfully sent. false otherwise Definition at line 1669 of file EnigmaIOTGateway.cpp.
| void EnigmaIOTGatewayClass::setRxLed | ( | uint8_t | led, |
| time_t | onTime = FLASH_LED_TIME |
||
| ) |
Sets a LED to be flashed every time a message is received.
| led | LED I/O pin |
| onTime | Flash duration. 100ms by default. |
Definition at line 50 of file EnigmaIOTGateway.cpp.
| void EnigmaIOTGatewayClass::setTxLed | ( | uint8_t | led, |
| time_t | onTime = FLASH_LED_TIME |
||
| ) |
Sets a LED to be flashed every time a message is transmitted.
| led | LED I/O pin |
| onTime | Flash duration. 100ms by default. |
Definition at line 43 of file EnigmaIOTGateway.cpp.
|
staticprotected |
Function that will be called anytime this gateway sends a message to indicate status result of sending process.
| mac_addr | Address of message destination |
| status | Result of sending process |
Definition at line 774 of file EnigmaIOTGateway.cpp.
|
protected |
Instance of physical communication layer.
Definition at line 211 of file EnigmaIOTGateway.h.
|
protected |
DNS server used by configuration portal.
Definition at line 231 of file EnigmaIOTGateway.h.
|
protected |
true if Rx LED should flash
Definition at line 208 of file EnigmaIOTGateway.h.
|
protected |
true if Tx LED should flash
Definition at line 207 of file EnigmaIOTGateway.h.
|
protected |
Gateway specific configuration to be stored on flash memory.
Definition at line 220 of file EnigmaIOTGateway.h.
|
protected |
Input messages buffer. It acts as a FIFO queue.
Definition at line 228 of file EnigmaIOTGateway.h.
|
protected |
Temporary public key store used during key agreement.
Definition at line 206 of file EnigmaIOTGateway.h.
|
protected |
temporary store to keep node data while processing a message
Definition at line 209 of file EnigmaIOTGateway.h.
|
protected |
Node database that keeps status and shared keys.
Definition at line 210 of file EnigmaIOTGateway.h.
|
protected |
Callback function that will be invoked when data is received fron a node.
Definition at line 216 of file EnigmaIOTGateway.h.
|
protected |
Callback function that will be invoked when a new node is connected.
Definition at line 217 of file EnigmaIOTGateway.h.
|
protected |
Callback function that will be invoked when a node gets disconnected.
Definition at line 218 of file EnigmaIOTGateway.h.
|
protected |
Function called when configuration portal exits.
Definition at line 233 of file EnigmaIOTGateway.h.
|
protected |
Function called when configuration portal is started.
Definition at line 234 of file EnigmaIOTGateway.h.
|
protected |
Definition at line 222 of file EnigmaIOTGateway.h.
|
protected |
I/O pin to connect a led that flashes when gateway receives data.
Definition at line 213 of file EnigmaIOTGateway.h.
|
protected |
Flash duration for Rx LED.
Definition at line 215 of file EnigmaIOTGateway.h.
|
protected |
WebServer that holds configuration portal.
Definition at line 230 of file EnigmaIOTGateway.h.
|
protected |
Temporary storage for input message got from buffer.
Definition at line 226 of file EnigmaIOTGateway.h.
|
protected |
I/O pin to connect a led that flashes when gateway transmits data.
Definition at line 212 of file EnigmaIOTGateway.h.
|
protected |
Flash duration for Tx LED.
Definition at line 214 of file EnigmaIOTGateway.h.
|
protected |
true if counter is used to check data messages order
Definition at line 219 of file EnigmaIOTGateway.h.
|
protected |
Wifi configuration portal.
Definition at line 232 of file EnigmaIOTGateway.h.
1.8.18