EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
EnigmaIOTNodeClass Class Reference

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 setSleepTime (uint32_t sleepTime)
 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...
 
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 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 (onWiFiManagerStarted_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 SPIFFS. It makes neccessary to configure it again using WiFi Portal. 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 restart (bool reboot=true)
 Sets connection as unregistered to force a resyncrhonisation after boot. 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 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. More...
 
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 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)
 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 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, bool controlMessage, 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_halClasscomm
 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...
 
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...
 
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...
 
onWiFiManagerStarted_t notifyWiFiManagerStarted
 Function called when configuration portal is started. More...
 

Detailed Description

Main node class. Manages communication with gateway and allows sending and receiving user data.

Definition at line 116 of file EnigmaIOTNode.h.

Member Function Documentation

◆ addWiFiManagerParameter()

void EnigmaIOTNodeClass::addWiFiManagerParameter ( AsyncWiFiManagerParameter *  p)
inline

Adds a parameter to configuration portal.

Parameters
pConfiguration parameter

Definition at line 651 of file EnigmaIOTNode.h.

◆ begin()

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.

Parameters
commPhysical layer to be used on this node network
gatewayGateway address
networkKeyNetwork key to protect shared key agreement
useCounterIndicates if a counter has to be added to every message data to check message sequence. true by default
sleepyIndicates 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 510 of file EnigmaIOTNode.cpp.

◆ checkCRC()

bool EnigmaIOTNodeClass::checkCRC ( const uint8_t *  buf,
size_t  count,
uint32_t *  crc 
)
protected

Check that a given CRC matches to calulated value from a buffer.

Parameters
bufPointer to the buffer that contains the stream to calculate CRC
countBuffer length in number of bytes
crcReceived CRC to check against calculation
Returns
Returns true if CRC check was successful. false otherwise

Definition at line 958 of file EnigmaIOTNode.cpp.

◆ checkResetButton()

void EnigmaIOTNodeClass::checkResetButton ( )
protected

Checks reset button status during startup.

Definition at line 488 of file EnigmaIOTNode.cpp.

◆ clearFlash()

void EnigmaIOTNodeClass::clearFlash ( )
protected

Clears configuration stored in flash to recover factory state.

Definition at line 309 of file EnigmaIOTNode.cpp.

◆ clearRTC()

void EnigmaIOTNodeClass::clearRTC ( )
protected

Clears configuration stored in RTC memory to recover factory state.

Definition at line 1740 of file EnigmaIOTNode.cpp.

◆ clientHello()

bool EnigmaIOTNodeClass::clientHello ( )
protected

Build a ClientHello messange and send it to gateway.

Returns
Returns true if ClientHello message was successfully sent. false otherwise

Definition at line 968 of file EnigmaIOTNode.cpp.

◆ clock()

int64_t EnigmaIOTNodeClass::clock ( )

Gets current clock counter. millis() + offset.

Returns
Clock value in int64_t format

Definition at line 1172 of file EnigmaIOTNode.cpp.

◆ clockRequest()

bool EnigmaIOTNodeClass::clockRequest ( )
protected

Build a ClockRequest messange and send it to gateway.

Returns
Returns true if ClockRequest message was successfully sent. false otherwise

Definition at line 1057 of file EnigmaIOTNode.cpp.

◆ configWiFiManager()

bool EnigmaIOTNodeClass::configWiFiManager ( rtcmem_data_t data)
protected

Starts configuration AP and web server and gets settings from it.

Parameters
dataPointer to configuration data to be stored on RTC memory to keep status along sleep cycles
Returns
Returns true if data was been correctly configured. false otherwise

Definition at line 321 of file EnigmaIOTNode.cpp.

◆ dataMessage()

bool EnigmaIOTNodeClass::dataMessage ( const uint8_t *  data,
size_t  len,
bool  controlMessage = false,
bool  encrypt = true,
nodePayloadEncoding_t  payloadEncoding = CAYENNELPP 
)
protected

Builds, encrypts and sends a Data message.

Parameters
dataBuffer to store payload to be sent
lenLength of payload data
controlMessageSignals if this message is an EnigmaIoT control message that should not be passed to higher layers
payloadEncodingIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK
Returns
Returns true if message could be correcly sent

Definition at line 1361 of file EnigmaIOTNode.cpp.

◆ enableClockSync()

void EnigmaIOTNodeClass::enableClockSync ( bool  clockSync = true)
inline

Controls clock synchronization function.

Parameters
clockSyncIf true clock will be synchronized with gateway

Definition at line 511 of file EnigmaIOTNode.h.

◆ getRSSI()

int8_t EnigmaIOTNodeClass::getRSSI ( )

Gets latest RSSI measurement. It is updated during start up or in case of transmission errors.

Returns
RSSI value

Definition at line 63 of file EnigmaIOTNode.cpp.

◆ getSleepTime()

uint32_t EnigmaIOTNodeClass::getSleepTime ( )

Returns sleep period in seconds.

Returns
Sleep period in seconds

Definition at line 55 of file EnigmaIOTNode.cpp.

◆ getStatus()

void EnigmaIOTNodeClass::getStatus ( uint8_t *  mac_addr,
uint8_t  status 
)
protected

Functrion to debug send status.

Parameters
mac_addrAddress of message sender
statusResult status code

Definition at line 2214 of file EnigmaIOTNode.cpp.

◆ handle()

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 801 of file EnigmaIOTNode.cpp.

◆ hasClockSync()

bool EnigmaIOTNodeClass::hasClockSync ( )

Checks if internal clock is synchronized to gateway.

Returns
True if clock is synchronized

Definition at line 1189 of file EnigmaIOTNode.cpp.

◆ isRegistered()

bool EnigmaIOTNodeClass::isRegistered ( )
inline

Checks if node is registered.

Returns
True if node is registered

Definition at line 686 of file EnigmaIOTNode.h.

◆ loadFlashData()

bool EnigmaIOTNodeClass::loadFlashData ( )
protected

Loads configuration from flash memory.

Returns
Returns true if data was read successfuly. false otherwise

Definition at line 159 of file EnigmaIOTNode.cpp.

◆ loadRTCData()

bool EnigmaIOTNodeClass::loadRTCData ( )
protected

Loads configuration from RTC data. Uses a CRC to check data integrity.

Returns
Returns true if data is valid. false otherwise

Definition at line 113 of file EnigmaIOTNode.cpp.

◆ manageMessage()

void EnigmaIOTNodeClass::manageMessage ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  count 
)
protected

Process every received message.

It starts clasiffying message usint the first byte. After that it passes it to the corresponding method for decoding

Parameters
macAddress of message sender
bufBuffer that stores message bytes
countLength of message in number of bytes

Definition at line 2090 of file EnigmaIOTNode.cpp.

◆ onConnected()

void EnigmaIOTNodeClass::onConnected ( onConnected_t  handler)
inline

Defines a function callback that will be called everytime node is registered on gateway.

Use example:

// First define the callback function
// Do whatever you need to process disconnecion
}
void setup () {
.....
// Now register function as data message handler
.....
}
void loop {
.....
}
Parameters
handlerPointer to the function

Definition at line 598 of file EnigmaIOTNode.h.

◆ onDataRx()

void EnigmaIOTNodeClass::onDataRx ( onNodeDataRx_t  handler)
inline

Defines a function callback that will be called on every downlink data message that is received from gateway.

Use example:

// First define the callback function
void processRxData (const uint8_t* mac, const uint8_t* buffer, uint8_t length) {
// Do whatever you need with received data
}
void setup () {
.....
// Now register function as data message handler
.....
}
void loop {
.....
}
Parameters
handlerPointer to the function

Definition at line 571 of file EnigmaIOTNode.h.

◆ onDisconnected()

void EnigmaIOTNodeClass::onDisconnected ( onDisconnected_t  handler)
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:

// First define the callback function
// Do whatever you need to process disconnecion
}
void setup () {
.....
// Now register function as data message handler
.....
}
void loop {
.....
}
Parameters
handlerPointer to the function

Definition at line 627 of file EnigmaIOTNode.h.

◆ onWiFiManagerExit()

void EnigmaIOTNodeClass::onWiFiManagerExit ( onWiFiManagerExit_t  handle)
inline

Register callback to be called on wifi manager exit.

Parameters
handleCallback function pointer

Definition at line 635 of file EnigmaIOTNode.h.

◆ onWiFiManagerStarted()

void EnigmaIOTNodeClass::onWiFiManagerStarted ( onWiFiManagerStarted_t  handle)
inline

Register callback to be called on wifi manager start.

Parameters
handleCallback function pointer

Definition at line 643 of file EnigmaIOTNode.h.

◆ processClockResponse()

bool EnigmaIOTNodeClass::processClockResponse ( const uint8_t *  mac,
const uint8_t *  buf,
size_t  count 
)
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.

Parameters
macAddress where this message was received from
bufPointer to the buffer that contains the message
countMessage length in number of bytes of ClockResponse message
Returns
Returns true if message could be correcly processed

Definition at line 1109 of file EnigmaIOTNode.cpp.

◆ processControlCommand()

bool EnigmaIOTNodeClass::processControlCommand ( const uint8_t *  mac,
const uint8_t *  data,
size_t  len 
)
protected

Processes a control command. Does not propagate to user code.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1987 of file EnigmaIOTNode.cpp.

◆ processDownstreamData()

bool EnigmaIOTNodeClass::processDownstreamData ( const uint8_t *  mac,
const uint8_t *  buf,
size_t  count,
bool  control = false 
)
protected

Processes downstream data from gateway.

Parameters
macGateway address
bufBuffer to store received payload
countLength of payload data
controlIdicates if downstream message is user or control data. If true it is a control message
Returns
Returns true if message could be correcly decoded

Definition at line 2018 of file EnigmaIOTNode.cpp.

◆ processGetNameCommand()

bool EnigmaIOTNodeClass::processGetNameCommand ( const uint8_t *  mac,
const uint8_t *  data,
uint8_t  len 
)
protected

Processes a request to get Node name and address.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1495 of file EnigmaIOTNode.cpp.

◆ processGetRSSICommand()

bool EnigmaIOTNodeClass::processGetRSSICommand ( const uint8_t *  mac,
const uint8_t *  data,
uint8_t  len 
)
protected

Processes a request to measure RSSI.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1704 of file EnigmaIOTNode.cpp.

◆ processGetSleepTimeCommand()

bool EnigmaIOTNodeClass::processGetSleepTimeCommand ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  len 
)
protected

Processes a request of sleep time configuration.

Parameters
macGateway address
bufBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1472 of file EnigmaIOTNode.cpp.

◆ processInvalidateKey()

nodeInvalidateReason_t EnigmaIOTNodeClass::processInvalidateKey ( const uint8_t *  mac,
const uint8_t *  buf,
size_t  count 
)
protected

Gets a buffer containing an InvalidateKey message and process it. This trigger a new key agreement to start.

Parameters
macAddress where this message was received from
bufPointer to the buffer that contains the message
countMessage length in number of bytes of InvalidateKey message
Returns
Returns the reason because key is not valid anymore. Check possible values in nodeInvalidateReason_t

Definition at line 2074 of file EnigmaIOTNode.cpp.

◆ processOTACommand()

bool EnigmaIOTNodeClass::processOTACommand ( const uint8_t *  mac,
const uint8_t *  data,
uint8_t  len 
)
protected

Processes a single OTA update command or data.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1817 of file EnigmaIOTNode.cpp.

◆ processServerHello()

bool EnigmaIOTNodeClass::processServerHello ( const uint8_t *  mac,
const uint8_t *  buf,
size_t  count 
)
protected

Gets a buffer containing a ServerHello message and process it. It uses that message to calculate a shared key using Diffie Hellman algorithm.

Parameters
macAddress where this message was received from
bufPointer to the buffer that contains the message
countMessage length in number of bytes of ServerHello message
Returns
Returns true if message could be correcly processed

Definition at line 1196 of file EnigmaIOTNode.cpp.

◆ processSetIdentifyCommand()

bool EnigmaIOTNodeClass::processSetIdentifyCommand ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  len 
)
protected

Processes a request to start indicate to identify a node visually.

Parameters
macGateway address
bufBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1691 of file EnigmaIOTNode.cpp.

◆ processSetNameCommand()

bool EnigmaIOTNodeClass::processSetNameCommand ( const uint8_t *  mac,
const uint8_t *  data,
uint8_t  len 
)
protected

Processes a request to set Node name.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1577 of file EnigmaIOTNode.cpp.

◆ processSetNameResponse()

bool EnigmaIOTNodeClass::processSetNameResponse ( const uint8_t *  mac,
const uint8_t *  data,
uint8_t  len 
)
protected

Processes a response to set Node name.

Parameters
macGateway address
dataBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1529 of file EnigmaIOTNode.cpp.

◆ processSetResetConfigCommand()

bool EnigmaIOTNodeClass::processSetResetConfigCommand ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  len 
)
protected

Processes a request to reset node configuration.

Parameters
macGateway address
bufBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1711 of file EnigmaIOTNode.cpp.

◆ processSetSleepTimeCommand()

bool EnigmaIOTNodeClass::processSetSleepTimeCommand ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  len 
)
protected

Processes a request to set new sleep time configuration.

Parameters
macGateway address
bufBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1754 of file EnigmaIOTNode.cpp.

◆ processVersionCommand()

bool EnigmaIOTNodeClass::processVersionCommand ( const uint8_t *  mac,
const uint8_t *  buf,
uint8_t  len 
)
protected

Processes a request firmware version.

Parameters
macGateway address
bufBuffer to store received message
lenLength of payload data
Returns
Returns true if message could be correcly decoded and processed

Definition at line 1799 of file EnigmaIOTNode.cpp.

◆ reportRSSI()

bool EnigmaIOTNodeClass::reportRSSI ( )
protected

Sends RSSI value and channel to Gateway.

Returns
True if report was sent successfuly

Definition at line 780 of file EnigmaIOTNode.cpp.

◆ resetConfig()

void EnigmaIOTNodeClass::resetConfig ( )

Deletes configuration file stored on SPIFFS. It makes neccessary to configure it again using WiFi Portal.

Definition at line 45 of file EnigmaIOTNode.cpp.

◆ restart()

void EnigmaIOTNodeClass::restart ( bool  reboot = true)
protected

Sets connection as unregistered to force a resyncrhonisation after boot.

Parameters
rebootTrue if a reboot should be triggered after unregistration

Definition at line 1976 of file EnigmaIOTNode.cpp.

◆ rx_cb()

void EnigmaIOTNodeClass::rx_cb ( uint8_t *  mac_addr,
uint8_t *  data,
uint8_t  len 
)
staticprotected

Function that will be called anytime this node receives a message.

Parameters
mac_addrAddress of message sender
dataBuffer that stores message bytes
lenLength of message in number of bytes

Definition at line 950 of file EnigmaIOTNode.cpp.

◆ saveFlashData()

bool EnigmaIOTNodeClass::saveFlashData ( bool  fsOpen = false)
protected

Saves configuration to flash memory.

Parameters
fsOpenTrue if FileSystem has is managed in outter code
Returns
Returns true if data could be written successfuly. false otherwise

Definition at line 233 of file EnigmaIOTNode.cpp.

◆ saveRTCData()

bool EnigmaIOTNodeClass::saveRTCData ( )
protected

Save configuration to RTC to store current status and recover it after deep sleep.

Returns
Returns true if result is successful. false otherwise

Definition at line 286 of file EnigmaIOTNode.cpp.

◆ searchForGateway()

bool EnigmaIOTNodeClass::searchForGateway ( rtcmem_data_t data,
bool  shouldStoreData = false 
)
protected

Starts searching for a gateway that it using configured Network Name as WiFi AP. Stores this info for subsequent use.

Parameters
dataNode context structure
shouldStoreDataTrue if this method should save context in flash
Returns
Returns true if gateway could be found. false otherwise

Definition at line 664 of file EnigmaIOTNode.cpp.

◆ sendData() [1/2]

bool EnigmaIOTNodeClass::sendData ( const uint8_t *  data,
size_t  len,
bool  controlMessage,
bool  encrypt = true,
nodePayloadEncoding_t  payloadEncoding = CAYENNELPP 
)
protected

Initiades data transmission distinguissing if it is payload or control data.

Parameters
dataBuffer to store payload to be sent
lenLength of payload data
controlMessageSignals if this message is an EnigmaIoT control message that should not be passed to higher layers
encrypttrue if data should be encrypted. Default is true
payloadEncodingIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK
Returns
Returns true if message could be correcly sent

Definition at line 1260 of file EnigmaIOTNode.cpp.

◆ sendData() [2/2]

bool EnigmaIOTNodeClass::sendData ( const uint8_t *  data,
size_t  len,
nodePayloadEncoding_t  payloadEncoding = CAYENNELPP 
)
inline

Starts a data message transmission.

Parameters
dataPayload buffer
lenPayload length
payloadEncodingIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK

Definition at line 534 of file EnigmaIOTNode.h.

◆ sendNodeNameSet()

bool EnigmaIOTNodeClass::sendNodeNameSet ( const char *  name)
protected

Informs Gateway about custom node name.

Parameters
nameCustom node name
Returns
True if message was sent successfuly

Definition at line 1614 of file EnigmaIOTNode.cpp.

◆ sendUnencryptedData()

bool EnigmaIOTNodeClass::sendUnencryptedData ( const uint8_t *  data,
size_t  len,
nodePayloadEncoding_t  payloadEncoding = CAYENNELPP 
)
inline

Starts a data message transmission.

Parameters
dataPayload buffer
lenPayload length
payloadEncodingIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK

Definition at line 544 of file EnigmaIOTNode.h.

◆ setLed()

void EnigmaIOTNodeClass::setLed ( uint8_t  led,
time_t  onTime = FLASH_LED_TIME 
)

Sets a LED to be flashed every time a message is transmitted.

Parameters
ledLED I/O pin
onTimeFlash duration. 100ms by default.

Definition at line 67 of file EnigmaIOTNode.cpp.

◆ setNodeAddress()

bool EnigmaIOTNodeClass::setNodeAddress ( uint8_t  address[ENIGMAIOT_ADDR_LEN])

Set node address to be used in EnigmaIOT communication.

Parameters
addressNode address
Returns
true if addres was set correctly

Definition at line 741 of file EnigmaIOTNode.cpp.

◆ setResetPin()

void EnigmaIOTNodeClass::setResetPin ( int  pin)

Sets a pin to be used to reset configuration it it is connected to ground during startup.

Parameters
pinReset pin

Definition at line 72 of file EnigmaIOTNode.cpp.

◆ setSleepTime()

void EnigmaIOTNodeClass::setSleepTime ( uint32_t  sleepTime)

Allows to configure a new sleep time period from user code.

Parameters
sleepTimeTime in seconds. Final period is not espected to be exact. Its value depends on communication process

Definition at line 746 of file EnigmaIOTNode.cpp.

◆ sleep()

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 1287 of file EnigmaIOTNode.cpp.

◆ startIdentifying()

void EnigmaIOTNodeClass::startIdentifying ( time_t  period)
protected

Starts node identification by flashing led.

Parameters
periodFlash led period in ms

Definition at line 477 of file EnigmaIOTNode.cpp.

◆ stop()

void EnigmaIOTNodeClass::stop ( )

Stops EnigmaIoT protocol.

Definition at line 736 of file EnigmaIOTNode.cpp.

◆ stopIdentifying()

void EnigmaIOTNodeClass::stopIdentifying ( )
protected

Stops node identification.

Definition at line 483 of file EnigmaIOTNode.cpp.

◆ tx_cb()

void EnigmaIOTNodeClass::tx_cb ( uint8_t *  mac_addr,
uint8_t  status 
)
staticprotected

Function that will be called anytime this node sends a message to indicate status result of sending process.

Parameters
mac_addrAddress of message destination
statusResult of sending process

Definition at line 954 of file EnigmaIOTNode.cpp.

◆ unencryptedDataMessage()

bool EnigmaIOTNodeClass::unencryptedDataMessage ( const uint8_t *  data,
size_t  len,
bool  controlMessage = false,
nodePayloadEncoding_t  payloadEncoding = CAYENNELPP 
)
protected

Builds and sends a Data message without encryption. Not recommended, use it only if you absolutely need more performance.

Parameters
dataBuffer to store payload to be sent
lenLength of payload data
controlMessageSignals if this message is an EnigmaIoT control message that should not be passed to higher layers
Returns
Returns true if message could be correcly sent

Definition at line 1297 of file EnigmaIOTNode.cpp.

◆ unixtime()

time_t EnigmaIOTNodeClass::unixtime ( )

Gets current time in seconds from 1970, if time is synchronized.

Returns
Time value in time_t format

Definition at line 1181 of file EnigmaIOTNode.cpp.

Member Data Documentation

◆ clockSyncEnabled

bool EnigmaIOTNodeClass::clockSyncEnabled = false
protected

If true clock is synchronized with Gateway.

Definition at line 142 of file EnigmaIOTNode.h.

◆ comm

Comms_halClass* EnigmaIOTNodeClass::comm
protected

Comms abstraction layer.

Definition at line 122 of file EnigmaIOTNode.h.

◆ configCleared

bool EnigmaIOTNodeClass::configCleared = false
protected

This flag disables asy configuration save after triggering a factory reset.

Definition at line 147 of file EnigmaIOTNode.h.

◆ dataMessageEncrypt

bool EnigmaIOTNodeClass::dataMessageEncrypt = true
protected

Message encryption enabled. Stored for use in case of message retransmission is needed.

Definition at line 134 of file EnigmaIOTNode.h.

◆ dataMessageSendEncoding

nodePayloadEncoding_t EnigmaIOTNodeClass::dataMessageSendEncoding = RAW
protected

Encoding of the message pending to be sent.

Definition at line 133 of file EnigmaIOTNode.h.

◆ dataMessageSendPending

bool EnigmaIOTNodeClass::dataMessageSendPending = false
protected

True in case of message retransmission is needed.

Definition at line 132 of file EnigmaIOTNode.h.

◆ dataMessageSent

uint8_t EnigmaIOTNodeClass::dataMessageSent[MAX_MESSAGE_LENGTH]
protected

Buffer where sent message is stored in case of retransmission is needed.

Definition at line 130 of file EnigmaIOTNode.h.

◆ dataMessageSentLength

uint8_t EnigmaIOTNodeClass::dataMessageSentLength = 0
protected

Message length stored for use in case of message retransmission is needed.

Definition at line 131 of file EnigmaIOTNode.h.

◆ flashBlue

bool EnigmaIOTNodeClass::flashBlue = false
protected

If true Tx LED will be flashed.

Definition at line 119 of file EnigmaIOTNode.h.

◆ gatewaySearchStarted

bool EnigmaIOTNodeClass::gatewaySearchStarted = false
protected

Avoids start a new gateway scan if it already started.

Definition at line 144 of file EnigmaIOTNode.h.

◆ identifyStart

time_t EnigmaIOTNodeClass::identifyStart
protected

Time when identification started flashing. Used to control identification timeout.

Definition at line 140 of file EnigmaIOTNode.h.

◆ indentifying

boolean EnigmaIOTNodeClass::indentifying = false
protected

True if node has its led flashing to be identified.

Definition at line 139 of file EnigmaIOTNode.h.

◆ invalidateReason

nodeInvalidateReason_t EnigmaIOTNodeClass::invalidateReason = UNKNOWN_ERROR
protected

Last key invalidation reason.

Definition at line 135 of file EnigmaIOTNode.h.

◆ lastOTAmsg

time_t EnigmaIOTNodeClass::lastOTAmsg
protected

Time when last OTA update message has received. This is used to control timeout.

Definition at line 138 of file EnigmaIOTNode.h.

◆ led

int8_t EnigmaIOTNodeClass::led = -1
protected

IO Pin that corresponds to Tx LED. Default value disables LED. It is initialized with setLed method.

Definition at line 120 of file EnigmaIOTNode.h.

◆ ledOnTime

unsigned int EnigmaIOTNodeClass::ledOnTime
protected

Time that LED is On during flash. Initalized on setLed

Definition at line 121 of file EnigmaIOTNode.h.

◆ node

Node EnigmaIOTNodeClass::node
protected

Node abstraction to store context.

Definition at line 118 of file EnigmaIOTNode.h.

◆ notifyConnection

onConnected_t EnigmaIOTNodeClass::notifyConnection
protected

Callback that will be called anytime a new node is registered.

Definition at line 124 of file EnigmaIOTNode.h.

◆ notifyData

onNodeDataRx_t EnigmaIOTNodeClass::notifyData
protected

Callback that will be called on every message reception.

Definition at line 123 of file EnigmaIOTNode.h.

◆ notifyDisconnection

onDisconnected_t EnigmaIOTNodeClass::notifyDisconnection
protected

Callback that will be called anytime a node is disconnected.

Definition at line 125 of file EnigmaIOTNode.h.

◆ notifyWiFiManagerExit

onWiFiManagerExit_t EnigmaIOTNodeClass::notifyWiFiManagerExit
protected

Function called when configuration portal exits.

Definition at line 150 of file EnigmaIOTNode.h.

◆ notifyWiFiManagerStarted

onWiFiManagerStarted_t EnigmaIOTNodeClass::notifyWiFiManagerStarted
protected

Function called when configuration portal is started.

Definition at line 151 of file EnigmaIOTNode.h.

◆ otaError

bool EnigmaIOTNodeClass::otaError = false
protected

True if OTA update has failed. This normally produces a restart.

Definition at line 137 of file EnigmaIOTNode.h.

◆ otaRunning

bool EnigmaIOTNodeClass::otaRunning = false
protected

True if OTA update has started.

Definition at line 136 of file EnigmaIOTNode.h.

◆ requestReportRSSI

bool EnigmaIOTNodeClass::requestReportRSSI = false
protected

Flag to control RSSI reporting.

Definition at line 146 of file EnigmaIOTNode.h.

◆ requestSearchGateway

bool EnigmaIOTNodeClass::requestSearchGateway = false
protected

Flag to control updating gateway address, RSSI and channel.

Definition at line 145 of file EnigmaIOTNode.h.

◆ resetPin

int EnigmaIOTNodeClass::resetPin = -1
protected

Pin used to reset configuration if it is connected to ground during startup.

Definition at line 148 of file EnigmaIOTNode.h.

◆ rtcmem_data

rtcmem_data_t EnigmaIOTNodeClass::rtcmem_data
protected

Context data to be stored on persistent storage.

Definition at line 127 of file EnigmaIOTNode.h.

◆ shouldRestart

bool EnigmaIOTNodeClass::shouldRestart = false
protected

Triggers a restart if true.

Definition at line 143 of file EnigmaIOTNode.h.

◆ sleepRequested

bool EnigmaIOTNodeClass::sleepRequested = false
protected

true means that this node will sleep as soon a message is sent and downlink wait time has passed

Definition at line 128 of file EnigmaIOTNode.h.

◆ sleepTime

uint64_t EnigmaIOTNodeClass::sleepTime
protected

Time in microseconds that this node will be slept between measurements.

Definition at line 129 of file EnigmaIOTNode.h.

◆ timeSyncPeriod

clock_t EnigmaIOTNodeClass::timeSyncPeriod = QUICK_SYNC_TIME
protected

Clock synchronization period.

Definition at line 141 of file EnigmaIOTNode.h.

◆ useCounter

bool EnigmaIOTNodeClass::useCounter = true
protected

true means that data message counter will be used to mark message order

Definition at line 126 of file EnigmaIOTNode.h.

◆ wifiManager

AsyncWiFiManager* EnigmaIOTNodeClass::wifiManager
protected

Wifi configuration portal.

Definition at line 149 of file EnigmaIOTNode.h.


The documentation for this class was generated from the following files:
setup
void setup()
Definition: enigmaiot_led_flasher.ino:100
processRxData
void processRxData(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
Definition: enigmaiot_led_flasher.ino:61
EnigmaIOTNode
EnigmaIOTNodeClass EnigmaIOTNode
Definition: EnigmaIOTNode.cpp:2229
loop
void loop()
Definition: enigmaiot_led_flasher.ino:136
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
disconnectEventHandler
void disconnectEventHandler(nodeInvalidateReason_t reason)
Definition: enigmaiot_led_flasher.ino:57
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
connectEventHandler
void connectEventHandler()
Definition: enigmaiot_led_flasher.ino:53
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