EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Main node class. Manages communication with gateway and allows sending and receiving user data. More...
#include <EnigmaIOTNode.h>
Public Member Functions | |
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. More... | |
void | stop () |
Stops EnigmaIoT protocol. More... | |
void | restart (restartReason_t reason, bool reboot=true) |
Sets connection as unregistered to force a resyncrhonisation after boot. More... | |
void | setSleepTime (uint32_t sleepTime, bool forceSleepForever=false) |
Allows to configure a new sleep time period from user code. More... | |
bool | setNodeAddress (uint8_t address[ENIGMAIOT_ADDR_LEN]) |
Set node address to be used in EnigmaIOT communication. More... | |
uint32_t | getSleepTime () |
Returns sleep period in seconds. More... | |
bool | broadcastIsEnabled () |
Returns if node broadcast mode is enabled. In that case, node is able to send and receive encrypted broadcast messages. If this is enabled this will be notified to gateway so that it sends broadcast key. Notice this mode is optional and does not disable the ability to send normal messages. More... | |
void | enableBroadcast (bool broadcast=true) |
Enables node broadcast mode. Node will request broadcast key to Gateway. When it is received node will be able to send and receive encrypted broadcast messages. More... | |
void | handle () |
This method should be called periodically for instance inside loop() function. It is used for internal node maintenance tasks. More... | |
void | enableClockSync (bool clockSync=true) |
Controls clock synchronization function. More... | |
void | setLed (uint8_t led, time_t onTime=FLASH_LED_TIME) |
Sets a LED to be flashed every time a message is transmitted. More... | |
void | setResetPin (int pin) |
Sets a pin to be used to reset configuration it it is connected to ground during startup. More... | |
bool | sendData (const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding=CAYENNELPP) |
Starts a data message transmission. More... | |
bool | sendHADiscoveryMessage (const uint8_t *data, size_t len) |
Builds, encrypts and sends a HomeAssistant discovery message. More... | |
bool | sendUnencryptedData (const uint8_t *data, size_t len, nodePayloadEncoding_t payloadEncoding=CAYENNELPP) |
Starts a data message transmission. More... | |
void | onDataRx (onNodeDataRx_t handler) |
Defines a function callback that will be called on every downlink data message that is received from gateway. More... | |
void | onConnected (onConnected_t handler) |
Defines a function callback that will be called everytime node is registered on gateway. More... | |
void | onDisconnected (onDisconnected_t handler) |
Defines a function callback that will be called everytime node is disconnected from gateway. More... | |
void | onWiFiManagerExit (onWiFiManagerExit_t handle) |
Register callback to be called on wifi manager exit. More... | |
void | onWiFiManagerStarted (simpleEventHandler_t handle) |
Register callback to be called on wifi manager start. More... | |
void | addWiFiManagerParameter (AsyncWiFiManagerParameter *p) |
Adds a parameter to configuration portal. More... | |
void | sleep () |
Requests transition to sleep mode (low energy state) More... | |
int64_t | clock () |
Gets current clock counter. millis() + offset. More... | |
time_t | unixtime () |
Gets current time in seconds from 1970, if time is synchronized. More... | |
bool | hasClockSync () |
Checks if internal clock is synchronized to gateway. More... | |
bool | isRegistered () |
Checks if node is registered. More... | |
int8_t | getRSSI () |
Gets latest RSSI measurement. It is updated during start up or in case of transmission errors. More... | |
void | resetConfig () |
Deletes configuration file stored on flash. It makes neccessary to configure it again using WiFi Portal. More... | |
bool | getOTArunning () |
Checks if OTA is running. More... | |
Node * | getNode () |
Gets Node instance. More... | |
Protected Member Functions | |
bool | checkCRC (const uint8_t *buf, size_t count, uint32_t *crc) |
Check that a given CRC matches to calulated value from a buffer. More... | |
void | startIdentifying (time_t period) |
Starts node identification by flashing led. More... | |
void | stopIdentifying () |
Stops node identification. More... | |
bool | loadRTCData () |
Loads configuration from RTC data. Uses a CRC to check data integrity. More... | |
bool | loadFlashData () |
Loads configuration from flash memory. More... | |
bool | saveFlashData (bool fsOpen=false) |
Saves configuration to flash memory. More... | |
bool | configWiFiManager (rtcmem_data_t *data) |
Starts configuration AP and web server and gets settings from it. More... | |
void | sendRestart () |
Sends a restart notification control message. More... | |
bool | clientHello () |
Build a ClientHello messange and send it to gateway. More... | |
bool | clockRequest () |
Build a ClockRequest messange and send it to gateway. More... | |
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 clock difference against gateway and synchronize to it. More... | |
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 shared key using Diffie Hellman algorithm. More... | |
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 start. More... | |
bool | processBroadcastKeyMessage (const uint8_t *mac, const uint8_t *buf, size_t count) |
Gets a buffer containing a BroadcastKey message and process it. This key is used to send and receive broadcast messages. More... | |
bool | dataMessage (const uint8_t *data, size_t len, dataMessageType_t dataMsgType=DATA_TYPE, bool encrypt=true, nodePayloadEncoding_t payloadEncoding=CAYENNELPP) |
Builds, encrypts and sends a Data message. More... | |
bool | unencryptedDataMessage (const uint8_t *data, size_t len, dataMessageType_t dataMsgType=DATA_TYPE, nodePayloadEncoding_t payloadEncoding=CAYENNELPP) |
Builds and sends a Data message without encryption. Not recommended, use it only if you absolutely need more performance. More... | |
bool | processOTACommand (const uint8_t *mac, const uint8_t *data, uint8_t len) |
Processes a single OTA update command or data. More... | |
bool | processControlCommand (const uint8_t *mac, const uint8_t *data, size_t len, bool broadcast) |
Processes a control command. Does not propagate to user code. More... | |
bool | processDownstreamData (const uint8_t *mac, const uint8_t *buf, size_t count, bool control=false) |
Processes downstream data from gateway. More... | |
void | manageMessage (const uint8_t *mac, const 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 | processGetSleepTimeCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request of sleep time configuration. More... | |
bool | processSetSleepTimeCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request to set new sleep time configuration. More... | |
bool | processSetIdentifyCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request to start indicate to identify a node visually. More... | |
bool | processSetResetConfigCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request to reset node configuration. More... | |
bool | processSetRestartCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request to restar node mcu. More... | |
bool | processVersionCommand (const uint8_t *mac, const uint8_t *buf, uint8_t len) |
Processes a request firmware version. More... | |
bool | sendData (const uint8_t *data, size_t len, dataMessageType_t dataMsgType, bool encrypt=true, nodePayloadEncoding_t payloadEncoding=CAYENNELPP) |
Initiades data transmission distinguissing if it is payload or control data. More... | |
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 subsequent use. More... | |
void | clearRTC () |
Clears configuration stored in RTC memory to recover factory state. More... | |
void | clearFlash () |
Clears configuration stored in flash to recover factory state. More... | |
bool | saveRTCData () |
Save configuration to RTC to store current status and recover it after deep sleep. More... | |
void | checkResetButton () |
Checks reset button status during startup. More... | |
bool | reportRSSI () |
Sends RSSI value and channel to Gateway. More... | |
bool | processGetRSSICommand (const uint8_t *mac, const uint8_t *data, uint8_t len) |
Processes a request to measure RSSI. More... | |
bool | processGetNameCommand (const uint8_t *mac, const uint8_t *data, uint8_t len) |
Processes a request to get Node name and address. More... | |
bool | processSetNameResponse (const uint8_t *mac, const uint8_t *data, uint8_t len) |
Processes a response to set Node name. More... | |
bool | processSetNameCommand (const uint8_t *mac, const uint8_t *data, uint8_t len) |
Processes a request to set Node name. More... | |
bool | sendNodeNameSet (const char *name) |
Informs Gateway about custom node name. More... | |
Static Protected Member Functions | |
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. More... | |
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 process. More... | |
Protected Attributes | |
Node | node |
Node abstraction to store context. More... | |
bool | flashBlue = false |
If true Tx LED will be flashed. More... | |
int8_t | led = -1 |
IO Pin that corresponds to Tx LED. Default value disables LED. It is initialized with setLed method. More... | |
unsigned int | ledOnTime |
Time that LED is On during flash. Initalized on setLed More... | |
Comms_halClass * | comm |
Comms abstraction layer. More... | |
onNodeDataRx_t | notifyData |
Callback that will be called on every message reception. More... | |
onConnected_t | notifyConnection |
Callback that will be called anytime a new node is registered. More... | |
onDisconnected_t | notifyDisconnection |
Callback that will be called anytime a node is disconnected. More... | |
bool | useCounter = true |
true means that data message counter will be used to mark message order More... | |
rtcmem_data_t | rtcmem_data |
Context data to be stored on persistent storage. More... | |
bool | sleepRequested = false |
true means that this node will sleep as soon a message is sent and downlink wait time has passed More... | |
uint64_t | sleepTime |
Time in microseconds that this node will be slept between measurements. More... | |
uint8_t | dataMessageSent [MAX_MESSAGE_LENGTH] |
Buffer where sent message is stored in case of retransmission is needed. More... | |
uint8_t | dataMessageSentLength = 0 |
Message length stored for use in case of message retransmission is needed. More... | |
bool | dataMessageSendPending = false |
True in case of message retransmission is needed. More... | |
nodePayloadEncoding_t | dataMessageSendEncoding = RAW |
Encoding of the message pending to be sent. More... | |
bool | dataMessageEncrypt = true |
Message encryption enabled. Stored for use in case of message retransmission is needed. More... | |
nodeInvalidateReason_t | invalidateReason = UNKNOWN_ERROR |
Last key invalidation reason. More... | |
bool | otaRunning = false |
True if OTA update has started. More... | |
bool | otaError = false |
True if OTA update has failed. This normally produces a restart. More... | |
bool | protectOTA = false |
True if OTA update was launched. OTA flag is stored on RTC so this disables writting. More... | |
time_t | lastOTAmsg |
Time when last OTA update message has received. This is used to control timeout. More... | |
boolean | indentifying = false |
True if node has its led flashing to be identified. More... | |
time_t | identifyStart |
Time when identification started flashing. Used to control identification timeout. More... | |
clock_t | timeSyncPeriod = QUICK_SYNC_TIME |
Clock synchronization period. More... | |
bool | clockSyncEnabled = false |
If true clock is synchronized with Gateway. More... | |
bool | shouldRestart = false |
Triggers a restart if true. More... | |
restartReason_t | restartReason |
Reason of restart (OTA, restart requested, configuration reset) More... | |
bool | gatewaySearchStarted = false |
Avoids start a new gateway scan if it already started. More... | |
bool | requestSearchGateway = false |
Flag to control updating gateway address, RSSI and channel. More... | |
bool | requestReportRSSI = false |
Flag to control RSSI reporting. More... | |
bool | configCleared = false |
This flag disables asy configuration save after triggering a factory reset. More... | |
int | resetPin = -1 |
Pin used to reset configuration if it is connected to ground during startup. More... | |
AsyncWiFiManager * | wifiManager |
Wifi configuration portal. More... | |
onWiFiManagerExit_t | notifyWiFiManagerExit |
Function called when configuration portal exits. More... | |
simpleEventHandler_t | notifyWiFiManagerStarted |
Function called when configuration portal is started. More... | |
time_t | cycleStartedTime |
Used to calculate exact sleep time by substracting awake time. More... | |
int16_t | lastBroadcastMsgCounter |
Counter for broadcast messages from gateway */. More... | |
Main node class. Manages communication with gateway and allows sending and receiving user data.
Definition at line 134 of file EnigmaIOTNode.h.
|
inline |
Adds a parameter to configuration portal.
p | Configuration parameter |
Definition at line 735 of file EnigmaIOTNode.h.
void EnigmaIOTNodeClass::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.
comm | Physical layer to be used on this node network |
gateway | Gateway address |
networkKey | Network key to protect shared key agreement |
useCounter | Indicates if a counter has to be added to every message data to check message sequence. true by default |
sleepy | Indicates if this node changes to low energy mode (sleep mode) after sending a data message. true by default |
This condition is signalled to Gateway during registration so that downlink messages are managed diferently. On non sleepy nodes a downlink data message can be sent on any moment as node will be always awake. But for nodes that sleep, normally those that are powered with batteries, downlink message will be queued on gateway and sent just after an uplink data message from node has been sent
Definition at line 696 of file EnigmaIOTNode.cpp.
|
inline |
Returns if node broadcast mode is enabled. In that case, node is able to send and receive encrypted broadcast messages. If this is enabled this will be notified to gateway so that it sends broadcast key. Notice this mode is optional and does not disable the ability to send normal messages.
true
if node has broadcast mode enabled. Definition at line 557 of file EnigmaIOTNode.h.
|
protected |
Check that a given CRC matches to calulated value from a buffer.
buf | Pointer to the buffer that contains the stream to calculate CRC |
count | Buffer length in number of bytes |
crc | Received CRC to check against calculation |
true
if CRC check was successful. false
otherwise Definition at line 1182 of file EnigmaIOTNode.cpp.
|
protected |
Checks reset button status during startup.
Definition at line 674 of file EnigmaIOTNode.cpp.
|
protected |
Clears configuration stored in flash to recover factory state.
Definition at line 464 of file EnigmaIOTNode.cpp.
|
protected |
Clears configuration stored in RTC memory to recover factory state.
Definition at line 2093 of file EnigmaIOTNode.cpp.
|
protected |
Build a ClientHello messange and send it to gateway.
true
if ClientHello message was successfully sent. false
otherwise Definition at line 1192 of file EnigmaIOTNode.cpp.
int64_t EnigmaIOTNodeClass::clock | ( | ) |
Gets current clock counter. millis() + offset.
int64_t
format Definition at line 1455 of file EnigmaIOTNode.cpp.
|
protected |
Build a ClockRequest messange and send it to gateway.
true
if ClockRequest message was successfully sent. false
otherwise Definition at line 1291 of file EnigmaIOTNode.cpp.
|
protected |
Starts configuration AP and web server and gets settings from it.
data | Pointer to configuration data to be stored on RTC memory to keep status along sleep cycles |
true
if data was been correctly configured. false
otherwise Definition at line 481 of file EnigmaIOTNode.cpp.
|
protected |
Builds, encrypts and sends a Data message.
data | Buffer to store payload to be sent |
len | Length of payload data |
dataMsgType | Signals if this message is a special EnigmaIoT message or that should not be passed to higher layers |
payloadEncoding | Determine payload data encoding as nodePayloadEncoding_t. It can be RAW, CAYENNELPP, MSGPACK |
encrypt | Indicates if message should be encrypted. True by default. Not recommended to set to false, use it only if you absolutely need more performance |
true
if message could be correcly sent Definition at line 1635 of file EnigmaIOTNode.cpp.
|
inline |
Enables node broadcast mode. Node will request broadcast key to Gateway. When it is received node will be able to send and receive encrypted broadcast messages.
broadcast | true to enable broadcast mode on this node. |
Definition at line 566 of file EnigmaIOTNode.h.
|
inline |
Controls clock synchronization function.
clockSync | If true clock will be synchronized with gateway |
Definition at line 584 of file EnigmaIOTNode.h.
|
inline |
|
inline |
int8_t EnigmaIOTNodeClass::getRSSI | ( | ) |
Gets latest RSSI measurement. It is updated during start up or in case of transmission errors.
Definition at line 85 of file EnigmaIOTNode.cpp.
uint32_t EnigmaIOTNodeClass::getSleepTime | ( | ) |
Returns sleep period in seconds.
Definition at line 77 of file EnigmaIOTNode.cpp.
|
protected |
Functrion to debug send status.
mac_addr | Address of message sender |
status | Result status code |
Definition at line 2704 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::handle | ( | ) |
This method should be called periodically for instance inside loop()
function. It is used for internal node maintenance tasks.
digitalRead (led) &&
Definition at line 1003 of file EnigmaIOTNode.cpp.
bool EnigmaIOTNodeClass::hasClockSync | ( | ) |
Checks if internal clock is synchronized to gateway.
Definition at line 1464 of file EnigmaIOTNode.cpp.
|
inline |
Checks if node is registered.
Definition at line 770 of file EnigmaIOTNode.h.
|
protected |
Loads configuration from flash memory.
true
if data was read successfuly. false
otherwise Definition at line 270 of file EnigmaIOTNode.cpp.
|
protected |
Loads configuration from RTC data. Uses a CRC to check data integrity.
true
if data is valid. false
otherwise Definition at line 221 of file EnigmaIOTNode.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 2551 of file EnigmaIOTNode.cpp.
|
inline |
Defines a function callback that will be called everytime node is registered on gateway.
Use example:
handler | Pointer to the function |
Definition at line 682 of file EnigmaIOTNode.h.
|
inline |
Defines a function callback that will be called on every downlink data message that is received from gateway.
Use example:
handler | Pointer to the function |
Definition at line 655 of file EnigmaIOTNode.h.
|
inline |
Defines a function callback that will be called everytime node is disconnected from gateway.
Deregistration is always started by gateway due syntax or encryption error or in case of key validity is over.
Use example:
handler | Pointer to the function |
Definition at line 711 of file EnigmaIOTNode.h.
|
inline |
Register callback to be called on wifi manager exit.
handle | Callback function pointer |
Definition at line 719 of file EnigmaIOTNode.h.
|
inline |
Register callback to be called on wifi manager start.
handle | Callback function pointer |
Definition at line 727 of file EnigmaIOTNode.h.
|
protected |
Gets a buffer containing a BroadcastKey message and process it. This key is used to send and receive broadcast messages.
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 ServerHello message |
true
if message could be correcly processed Definition at line 2408 of file EnigmaIOTNode.cpp.
|
protected |
Gets a buffer containing a ClockResponse message and process it. It uses that message to calculate clock difference against gateway and synchronize to it.
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 ClockResponse message |
true
if message could be correcly processed Definition at line 1367 of file EnigmaIOTNode.cpp.
|
protected |
Processes a control command. Does not propagate to user code.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
broadcast | true if this is a broadcast addressed message |
true
if message could be correcly decoded and processed Definition at line 2366 of file EnigmaIOTNode.cpp.
|
protected |
Processes downstream data from gateway.
mac | Gateway address |
buf | Buffer to store received payload |
count | Length of payload data |
control | Idicates if downstream message is user or control data. If true it is a control message |
true
if message could be correcly decoded Definition at line 2425 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to get Node name and address.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 1795 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to measure RSSI.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2046 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request of sleep time configuration.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 1772 of file EnigmaIOTNode.cpp.
|
protected |
Gets a buffer containing an InvalidateKey message and process it. This trigger a new key agreement to start.
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 InvalidateKey message |
Definition at line 2527 of file EnigmaIOTNode.cpp.
|
protected |
Processes a single OTA update command or data.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2181 of file EnigmaIOTNode.cpp.
|
protected |
Gets a buffer containing a ServerHello message and process it. It uses that message to calculate a shared key using 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 ServerHello message |
true
if message could be correcly processed Definition at line 1471 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to start indicate to identify a node visually.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2033 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to set Node name.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 1899 of file EnigmaIOTNode.cpp.
|
protected |
Processes a response to set Node name.
mac | Gateway address |
data | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 1829 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to reset node configuration.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2059 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to restar node mcu.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2053 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request to set new sleep time configuration.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2118 of file EnigmaIOTNode.cpp.
|
protected |
Processes a request firmware version.
mac | Gateway address |
buf | Buffer to store received message |
len | Length of payload data |
true
if message could be correcly decoded and processed Definition at line 2163 of file EnigmaIOTNode.cpp.
|
protected |
Sends RSSI value and channel to Gateway.
Definition at line 982 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::resetConfig | ( | ) |
Deletes configuration file stored on flash. It makes neccessary to configure it again using WiFi Portal.
Definition at line 44 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::restart | ( | restartReason_t | reason, |
bool | reboot = true |
||
) |
Sets connection as unregistered to force a resyncrhonisation after boot.
reason | Reason of the reboot (OTA, restart requested, configuration reset) |
reboot | True if a reboot should be triggered after unregistration |
Definition at line 2351 of file EnigmaIOTNode.cpp.
|
staticprotected |
Function that will be called anytime this node 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 1174 of file EnigmaIOTNode.cpp.
|
protected |
Saves configuration to flash memory.
fsOpen | True if FileSystem has is managed in outter code |
true
if data could be written successfuly. false
otherwise Definition at line 352 of file EnigmaIOTNode.cpp.
|
protected |
Save configuration to RTC to store current status and recover it after deep sleep.
true
if result is successful. false
otherwise Definition at line 433 of file EnigmaIOTNode.cpp.
|
protected |
Starts searching for a gateway that it using configured Network Name as WiFi AP. Stores this info for subsequent use.
data | Node context structure |
shouldStoreData | True if this method should save context in flash |
true
if gateway could be found. false
otherwise Definition at line 860 of file EnigmaIOTNode.cpp.
|
protected |
Initiades data transmission distinguissing if it is payload or control data.
data | Buffer to store payload to be sent |
len | Length of payload data |
dataMsgType | Signals if this message is a special EnigmaIoT message or that should not be passed to higher layers |
encrypt | true if data should be encrypted. Default is true |
payloadEncoding | Identifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK |
true
if message could be correcly sent Definition at line 1535 of file EnigmaIOTNode.cpp.
|
inline |
Starts a data message transmission.
data | Payload buffer |
len | Payload length |
payloadEncoding | Identifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK |
Definition at line 609 of file EnigmaIOTNode.h.
bool EnigmaIOTNodeClass::sendHADiscoveryMessage | ( | const uint8_t * | data, |
size_t | len | ||
) |
Builds, encrypts and sends a HomeAssistant discovery message.
data | Buffer to store payload to be sent |
len | Length of payload data |
true
if message could be correcly sent Definition at line 1764 of file EnigmaIOTNode.cpp.
|
protected |
Informs Gateway about custom node name.
name | Custom node name |
Definition at line 1936 of file EnigmaIOTNode.cpp.
|
protected |
Sends a restart notification control message.
Definition at line 56 of file EnigmaIOTNode.cpp.
|
inline |
Starts a data message transmission.
data | Payload buffer |
len | Payload length |
payloadEncoding | Identifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK |
Definition at line 628 of file EnigmaIOTNode.h.
void EnigmaIOTNodeClass::setLed | ( | 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 89 of file EnigmaIOTNode.cpp.
bool EnigmaIOTNodeClass::setNodeAddress | ( | uint8_t | address[ENIGMAIOT_ADDR_LEN] | ) |
Set node address to be used in EnigmaIOT communication.
address | Node address |
true
if addres was set correctly Definition at line 943 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::setResetPin | ( | int | pin | ) |
Sets a pin to be used to reset configuration it it is connected to ground during startup.
pin | Reset pin |
Definition at line 94 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::setSleepTime | ( | uint32_t | sleepTime, |
bool | forceSleepForever = false |
||
) |
Allows to configure a new sleep time period from user code.
sleepTime | Time in seconds. Final period is not espected to be exact. Its value depends on communication process. If it is zero, disables deep sleep. |
forceSleepForever | Ignored if sleepTime is not zero. If it has zero value forces deepSleep command to sleep indifinitely. |
Definition at line 948 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::sleep | ( | ) |
Requests transition to sleep mode (low energy state)
Sleep can be requested in any moment and will be triggered inmediatelly except if node is doing registration or is waiting for downlink
Definition at line 1564 of file EnigmaIOTNode.cpp.
|
protected |
Starts node identification by flashing led.
period | Flash led period in ms |
Definition at line 663 of file EnigmaIOTNode.cpp.
void EnigmaIOTNodeClass::stop | ( | ) |
Stops EnigmaIoT protocol.
Definition at line 938 of file EnigmaIOTNode.cpp.
|
protected |
Stops node identification.
Definition at line 669 of file EnigmaIOTNode.cpp.
|
staticprotected |
Function that will be called anytime this node sends a message to indicate status result of sending process.
mac_addr | Address of message destination |
status | Result of sending process |
Definition at line 1178 of file EnigmaIOTNode.cpp.
|
protected |
Builds and sends a Data message without encryption. Not recommended, use it only if you absolutely need more performance.
data | Buffer to store payload to be sent |
len | Length of payload data |
dataMsgType | Signals if this message is a special EnigmaIoT message or that should not be passed to higher layers |
payloadEncoding | Determine payload data encoding as nodePayloadEncoding_t. It can be RAW, CAYENNELPP, MSGPACK |
true
if message could be correcly sent Definition at line 1574 of file EnigmaIOTNode.cpp.
time_t EnigmaIOTNodeClass::unixtime | ( | ) |
Gets current time in seconds from 1970, if time is synchronized.
time_t
format Definition at line 1460 of file EnigmaIOTNode.cpp.
|
protected |
If true clock is synchronized with Gateway.
Definition at line 161 of file EnigmaIOTNode.h.
|
protected |
Comms abstraction layer.
Definition at line 140 of file EnigmaIOTNode.h.
|
protected |
This flag disables asy configuration save after triggering a factory reset.
Definition at line 167 of file EnigmaIOTNode.h.
|
protected |
Used to calculate exact sleep time by substracting awake time.
Definition at line 172 of file EnigmaIOTNode.h.
|
protected |
Message encryption enabled. Stored for use in case of message retransmission is needed.
Definition at line 152 of file EnigmaIOTNode.h.
|
protected |
Encoding of the message pending to be sent.
Definition at line 151 of file EnigmaIOTNode.h.
|
protected |
True in case of message retransmission is needed.
Definition at line 150 of file EnigmaIOTNode.h.
|
protected |
Buffer where sent message is stored in case of retransmission is needed.
Definition at line 148 of file EnigmaIOTNode.h.
|
protected |
Message length stored for use in case of message retransmission is needed.
Definition at line 149 of file EnigmaIOTNode.h.
|
protected |
If true Tx LED will be flashed.
Definition at line 137 of file EnigmaIOTNode.h.
|
protected |
Avoids start a new gateway scan if it already started.
Definition at line 164 of file EnigmaIOTNode.h.
|
protected |
Time when identification started flashing. Used to control identification timeout.
Definition at line 159 of file EnigmaIOTNode.h.
|
protected |
True if node has its led flashing to be identified.
Definition at line 158 of file EnigmaIOTNode.h.
|
protected |
Last key invalidation reason.
Definition at line 153 of file EnigmaIOTNode.h.
|
protected |
Counter for broadcast messages from gateway */.
Definition at line 173 of file EnigmaIOTNode.h.
|
protected |
Time when last OTA update message has received. This is used to control timeout.
Definition at line 157 of file EnigmaIOTNode.h.
|
protected |
IO Pin that corresponds to Tx LED. Default value disables LED. It is initialized with setLed
method.
Definition at line 138 of file EnigmaIOTNode.h.
|
protected |
Time that LED is On during flash. Initalized on setLed
Definition at line 139 of file EnigmaIOTNode.h.
|
protected |
Node abstraction to store context.
Definition at line 136 of file EnigmaIOTNode.h.
|
protected |
Callback that will be called anytime a new node is registered.
Definition at line 142 of file EnigmaIOTNode.h.
|
protected |
Callback that will be called on every message reception.
Definition at line 141 of file EnigmaIOTNode.h.
|
protected |
Callback that will be called anytime a node is disconnected.
Definition at line 143 of file EnigmaIOTNode.h.
|
protected |
Function called when configuration portal exits.
Definition at line 170 of file EnigmaIOTNode.h.
|
protected |
Function called when configuration portal is started.
Definition at line 171 of file EnigmaIOTNode.h.
|
protected |
True if OTA update has failed. This normally produces a restart.
Definition at line 155 of file EnigmaIOTNode.h.
|
protected |
True if OTA update has started.
Definition at line 154 of file EnigmaIOTNode.h.
|
protected |
True if OTA update was launched. OTA flag is stored on RTC so this disables writting.
Definition at line 156 of file EnigmaIOTNode.h.
|
protected |
Flag to control RSSI reporting.
Definition at line 166 of file EnigmaIOTNode.h.
|
protected |
Flag to control updating gateway address, RSSI and channel.
Definition at line 165 of file EnigmaIOTNode.h.
|
protected |
Pin used to reset configuration if it is connected to ground during startup.
Definition at line 168 of file EnigmaIOTNode.h.
|
protected |
Reason of restart (OTA, restart requested, configuration reset)
Definition at line 163 of file EnigmaIOTNode.h.
|
protected |
Context data to be stored on persistent storage.
Definition at line 145 of file EnigmaIOTNode.h.
|
protected |
Triggers a restart if true.
Definition at line 162 of file EnigmaIOTNode.h.
|
protected |
true
means that this node will sleep as soon a message is sent and downlink wait time has passed
Definition at line 146 of file EnigmaIOTNode.h.
|
protected |
Time in microseconds that this node will be slept between measurements.
Definition at line 147 of file EnigmaIOTNode.h.
|
protected |
Clock synchronization period.
Definition at line 160 of file EnigmaIOTNode.h.
|
protected |
true
means that data message counter will be used to mark message order
Definition at line 144 of file EnigmaIOTNode.h.
|
protected |
Wifi configuration portal.
Definition at line 169 of file EnigmaIOTNode.h.