EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Node Class Reference

Class definition for a single sensor Node. More...

#include <NodeList.h>

Public Member Functions

 Node ()
 Plain constructor. More...
 
 Node (node_t nodeData)
 Constructor that initializes data from another Node data. More...
 
uint8_t * getMacAddress ()
 Gets address from Node. More...
 
uint16_t getNodeId ()
 Gets Node identifier. More...
 
void setNodeId (uint16_t nodeId)
 Sets a new Node identifier. More...
 
char * getNodeName ()
 Gets Node name. More...
 
void setNodeName (const char *name)
 Sets Node name. More...
 
uint8_t * getEncriptionKey ()
 Gets Node encryption key. More...
 
void setEncryptionKey (const uint8_t *key)
 Sets encryption key. More...
 
time_t getKeyValidFrom ()
 Gets last time that key was agreed with gateway. More...
 
void setKeyValidFrom (time_t keyValidFrom)
 Sets time when key was agreed with gateway. More...
 
time_t getLastMessageTime ()
 Gets last time that node sent a message. More...
 
void setLastMessageTime ()
 Sets current moment as last node message time. More...
 
uint16_t getLastMessageCounter ()
 Gets counter for last received message from node. More...
 
uint16_t getLastControlCounter ()
 Gets counter for last received control message from node. More...
 
uint16_t getLastDownlinkMsgCounter ()
 Gets counter for last downlink message from gateway. More...
 
void setLastMessageCounter (uint16_t counter)
 Sets counter for last received message from node. More...
 
void setLastControlCounter (uint16_t counter)
 Sets counter for last received control message from node. More...
 
void setLastDownlinkMsgCounter (uint16_t counter)
 Sets counter for last downlink message from gateway. More...
 
void setMacAddress (const uint8_t *macAddress)
 Sets node address. More...
 
bool isKeyValid ()
 Gets shared key validity for this node. More...
 
void setKeyValid (bool status)
 Sets shared key validity for this node. More...
 
bool isRegistered ()
 Gets registration state of this node. More...
 
status_t getStatus ()
 Gets status for finite state machine that represents node. More...
 
void setStatus (status_t status)
 Sets status for finite state machine that represents node. More...
 
node_t getNodeData ()
 Gets a struct that represents node object. May be used for node serialization. More...
 
void printToSerial (Stream *port=&Serial)
 Dumps node data to the given stream, Serial by default. This method may be used for debugging. More...
 
void reset ()
 Resets all node fields to a default initial and not registered state. More...
 
void setSleepy (bool sleepy)
 Sets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sleep after sending a message. In this case it will wait for a short while for a downlink message from gateway. More...
 
void setInitAsSleepy (bool sleepy)
 Records if node started as a sleepy node or not. If it did not started so it will never accept sleep time changes. More...
 
bool getInitAsSleepy ()
 Gets initial sleepy mode. More...
 
bool getSleepy ()
 Gets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sleep after sending a message. In this case it will wait for a short while for a downlink message from gateway. 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)
 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 setBroadcastKeyRequested (bool request)
 Mark node to be waiting for broadcast key. More...
 
bool isBroadcastKeyRequested ()
 Checks if node is waiting for broadcast key. More...
 
void updatePacketsRate (float value)
 Adds a new message rate value for filter calculation. More...
 
int8_t getRSSI ()
 Gets last RSSI measurement of Gateway. More...
 
void setRSSI (int8_t rssi)
 Stores last RSSI measurement of Gateway. More...
 
bool useTimeSync ()
 Gets node info to check if it has requested time sync ever. More...
 
void setTimeSyncEnabled ()
 Mark node as time sync enabled. More...
 
uint8_t * getVersion ()
 Gets node EnigmaIOT version. More...
 
void setVersion (uint8_t major, uint8_t minor, uint8_t incremental)
 Sets node EnigmaIOT version. More...
 

Public Attributes

uint8_t queuedMessage [MAX_MESSAGE_LENGTH]
 Message queued for sending to node in case of sleepy mode. More...
 
size_t qMessageLength
 Queued message length. More...
 
bool qMessagePending = false
 True if message should be sent just after next data message More...
 
uint32_t packetNumber = 0
 Number of packets received from node to gateway. More...
 
uint32_t packetErrors = 0
 Number of errored packets. More...
 
double per = 0
 Current packet error rate of a specific node. More...
 
double packetsHour = 0
 Packet rate for a specific nope. More...
 

Protected Member Functions

void initRateFilter ()
 Starts smoothing filter. More...
 

Protected Attributes

bool keyValid
 Node shared key valid. More...
 
status_t status
 Current node status. See enum node_status More...
 
uint16_t lastMessageCounter
 Last message counter state for specific Node. More...
 
uint16_t lastControlCounter
 Last message counter state for specific Node. More...
 
uint16_t lastDownlinkMsgCounter
 Last downlink message counter state for specific Node. More...
 
uint16_t nodeId
 Node identifier asigned by gateway. More...
 
timer_t keyValidFrom
 Last time that Node and Gateway agreed a key. More...
 
bool sleepyNode = true
 Node sleepy definition. More...
 
bool broadcastEnabled = false
 Node is able to send broadcast messages. More...
 
bool broadcastKeyRequested = false
 Node is waiting for broadcast key. More...
 
bool initAsSleepy
 Stores initial sleepy node. If this is false, this node does not accept sleep time changes. More...
 
bool askedTimeSync = false
 
uint8_t mac [ENIGMAIOT_ADDR_LEN]
 Node address. More...
 
uint8_t key [KEY_LENGTH]
 Shared key. More...
 
timer_t lastMessageTime
 Node state. More...
 
FilterClassrateFilter
 Filter for message rate smoothing. More...
 
char nodeName [NODE_NAME_LENGTH]
 Node name. Use as a human friendly name to avoid use of numeric address. More...
 
int8_t rssi
 Stores last RSSI measurement. More...
 
uint8_t enigmaIOTVersion [3]
 Protocol version, filled when a version message is received. More...
 

Friends

class NodeList
 

Detailed Description

Class definition for a single sensor Node.

Definition at line 109 of file NodeList.h.

Constructor & Destructor Documentation

◆ Node() [1/2]

Node::Node ( )

Plain constructor.

Returns
Returns a new unregistered Node instance

Definition at line 78 of file NodeList.cpp.

◆ Node() [2/2]

Node::Node ( node_t  nodeData)
explicit

Constructor that initializes data from another Node data.

Parameters
nodeDatanode_instance struct that contains initalization values for new Node
Returns
Returns a new Node instance with same data as given node_instance struct

Definition at line 84 of file NodeList.cpp.

Member Function Documentation

◆ broadcastIsEnabled()

bool Node::broadcastIsEnabled ( )
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.

Returns
true if node has broadcast mode enabled.

Definition at line 373 of file NodeList.h.

◆ enableBroadcast()

void Node::enableBroadcast ( bool  broadcast)
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.

Parameters
broadcasttrue to enable broadcast mode on this node.

Definition at line 386 of file NodeList.h.

◆ getEncriptionKey()

uint8_t* Node::getEncriptionKey ( )
inline

Gets Node encryption key.

Returns
Returns a pointer to Node encryption key

Definition at line 173 of file NodeList.h.

◆ getInitAsSleepy()

bool Node::getInitAsSleepy ( )
inline

Gets initial sleepy mode.

Returns
true if node started as sleepy. false otherwise

Definition at line 354 of file NodeList.h.

◆ getKeyValidFrom()

time_t Node::getKeyValidFrom ( )
inline

Gets last time that key was agreed with gateway.

Returns
Time in milliseconds of last key agreement

Definition at line 187 of file NodeList.h.

◆ getLastControlCounter()

uint16_t Node::getLastControlCounter ( )
inline

Gets counter for last received control message from node.

Returns
Message counter

Definition at line 226 of file NodeList.h.

◆ getLastDownlinkMsgCounter()

uint16_t Node::getLastDownlinkMsgCounter ( )
inline

Gets counter for last downlink message from gateway.

Returns
Message counter

Definition at line 234 of file NodeList.h.

◆ getLastMessageCounter()

uint16_t Node::getLastMessageCounter ( )
inline

Gets counter for last received message from node.

Returns
Message counter

Definition at line 218 of file NodeList.h.

◆ getLastMessageTime()

time_t Node::getLastMessageTime ( )
inline

Gets last time that node sent a message.

Returns
Time in milliseconds of last received node message

Definition at line 203 of file NodeList.h.

◆ getMacAddress()

uint8_t* Node::getMacAddress ( )
inline

Gets address from Node.

Returns
Returns a pointer to Node address

Definition at line 128 of file NodeList.h.

◆ getNodeData()

node_t Node::getNodeData ( )

Gets a struct that represents node object. May be used for node serialization.

Returns
Node struct

Definition at line 17 of file NodeList.cpp.

◆ getNodeId()

uint16_t Node::getNodeId ( )
inline

Gets Node identifier.

Returns
Returns Node identifier

Definition at line 136 of file NodeList.h.

◆ getNodeName()

char* Node::getNodeName ( )
inline

Gets Node name.

Returns
Returns Node name

Definition at line 152 of file NodeList.h.

◆ getRSSI()

int8_t Node::getRSSI ( )
inline

Gets last RSSI measurement of Gateway.

Returns
RSSI power of Gateway signal

Definition at line 418 of file NodeList.h.

◆ getSleepy()

bool Node::getSleepy ( )
inline

Gets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sleep after sending a message. In this case it will wait for a short while for a downlink message from gateway.

Returns
true if node sleeps after sending a message and wait for downlink. false if downlink may happen in any moment

Definition at line 363 of file NodeList.h.

◆ getStatus()

status_t Node::getStatus ( )
inline

Gets status for finite state machine that represents node.

Returns
Node status

Definition at line 300 of file NodeList.h.

◆ getVersion()

uint8_t* Node::getVersion ( )
inline

Gets node EnigmaIOT version.

Returns
EnigmaIOT protocol version in a uint8_t array of 3 elements

Definition at line 449 of file NodeList.h.

◆ initRateFilter()

void Node::initRateFilter ( )
protected

Starts smoothing filter.

Definition at line 67 of file NodeList.cpp.

◆ isBroadcastKeyRequested()

bool Node::isBroadcastKeyRequested ( )
inline

Checks if node is waiting for broadcast key.

Returns
true if node is waiting.

Definition at line 404 of file NodeList.h.

◆ isKeyValid()

bool Node::isKeyValid ( )
inline

Gets shared key validity for this node.

Returns
true if node shared key is valid. false otherwise

Definition at line 276 of file NodeList.h.

◆ isRegistered()

bool Node::isRegistered ( )
inline

Gets registration state of this node.

Returns
true if node is registered on gateway. false otherwise

Definition at line 292 of file NodeList.h.

◆ printToSerial()

void Node::printToSerial ( Stream *  port = &Serial)

Dumps node data to the given stream, Serial by default. This method may be used for debugging.

Parameters
portStream to print data to

Definition at line 32 of file NodeList.cpp.

◆ reset()

void Node::reset ( )

Resets all node fields to a default initial and not registered state.

Definition at line 106 of file NodeList.cpp.

◆ setBroadcastKeyRequested()

void Node::setBroadcastKeyRequested ( bool  request)
inline

Mark node to be waiting for broadcast key.

Parameters
requesttrue to mark node as waiting.

Definition at line 396 of file NodeList.h.

◆ setEncryptionKey()

void Node::setEncryptionKey ( const uint8_t *  key)

Sets encryption key.

Parameters
keyNew key

Definition at line 11 of file NodeList.cpp.

◆ setInitAsSleepy()

void Node::setInitAsSleepy ( bool  sleepy)
inline

Records if node started as a sleepy node or not. If it did not started so it will never accept sleep time changes.

Parameters
sleepytrue if node started as sleepy. false otherwise

Definition at line 346 of file NodeList.h.

◆ setKeyValid()

void Node::setKeyValid ( bool  status)
inline

Sets shared key validity for this node.

Parameters
statusnode key validity

Definition at line 284 of file NodeList.h.

◆ setKeyValidFrom()

void Node::setKeyValidFrom ( time_t  keyValidFrom)
inline

Sets time when key was agreed with gateway.

Parameters
keyValidFromTime on key agreement

Definition at line 195 of file NodeList.h.

◆ setLastControlCounter()

void Node::setLastControlCounter ( uint16_t  counter)
inline

Sets counter for last received control message from node.

Parameters
counterMessage counter

Definition at line 250 of file NodeList.h.

◆ setLastDownlinkMsgCounter()

void Node::setLastDownlinkMsgCounter ( uint16_t  counter)
inline

Sets counter for last downlink message from gateway.

Parameters
counterMessage counter

Definition at line 258 of file NodeList.h.

◆ setLastMessageCounter()

void Node::setLastMessageCounter ( uint16_t  counter)
inline

Sets counter for last received message from node.

Parameters
counterMessage counter

Definition at line 242 of file NodeList.h.

◆ setLastMessageTime()

void Node::setLastMessageTime ( )
inline

Sets current moment as last node message time.

Definition at line 210 of file NodeList.h.

◆ setMacAddress()

void Node::setMacAddress ( const uint8_t *  macAddress)
inline

Sets node address.

Parameters
macAddressNode address

Definition at line 266 of file NodeList.h.

◆ setNodeId()

void Node::setNodeId ( uint16_t  nodeId)
inline

Sets a new Node identifier.

Parameters
nodeIdNew nodeId value

Definition at line 144 of file NodeList.h.

◆ setNodeName()

void Node::setNodeName ( const char *  name)
inline

Sets Node name.

Parameters
nameCustom node name. This should be unique in the network

Definition at line 164 of file NodeList.h.

◆ setRSSI()

void Node::setRSSI ( int8_t  rssi)
inline

Stores last RSSI measurement of Gateway.

Parameters
rssiRSSI power of Gateway signal

Definition at line 426 of file NodeList.h.

◆ setSleepy()

void Node::setSleepy ( bool  sleepy)
inline

Sets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sleep after sending a message. In this case it will wait for a short while for a downlink message from gateway.

Parameters
sleepytrue if node sleeps after sending a message and wait for downlink. false if downlink may happen in any moment

Definition at line 334 of file NodeList.h.

◆ setStatus()

void Node::setStatus ( status_t  status)
inline

Sets status for finite state machine that represents node.

Parameters
statusNode status

Definition at line 308 of file NodeList.h.

◆ setTimeSyncEnabled()

void Node::setTimeSyncEnabled ( )
inline

Mark node as time sync enabled.

Definition at line 441 of file NodeList.h.

◆ setVersion()

void Node::setVersion ( uint8_t  major,
uint8_t  minor,
uint8_t  incremental 
)
inline

Sets node EnigmaIOT version.

Parameters
majorMajor protocol version. In 0.9.6, this should be 0
minorMinor protocol version. In 0.9.6, this should be 9
incrementalIncremental protocol version. In 0.9.6, this should be 6

Definition at line 459 of file NodeList.h.

◆ updatePacketsRate()

void Node::updatePacketsRate ( float  value)

Adds a new message rate value for filter calculation.

Parameters
valueNext value for calculation

Definition at line 101 of file NodeList.cpp.

◆ useTimeSync()

bool Node::useTimeSync ( )
inline

Gets node info to check if it has requested time sync ever.

Returns
true or false

Definition at line 434 of file NodeList.h.

Friends And Related Function Documentation

◆ NodeList

friend class NodeList
friend

Definition at line 502 of file NodeList.h.

Member Data Documentation

◆ askedTimeSync

bool Node::askedTimeSync = false
protected

Definition at line 488 of file NodeList.h.

◆ broadcastEnabled

bool Node::broadcastEnabled = false
protected

Node is able to send broadcast messages.

Definition at line 485 of file NodeList.h.

◆ broadcastKeyRequested

bool Node::broadcastKeyRequested = false
protected

Node is waiting for broadcast key.

Definition at line 486 of file NodeList.h.

◆ enigmaIOTVersion

uint8_t Node::enigmaIOTVersion[3]
protected

Protocol version, filled when a version message is received.

Definition at line 495 of file NodeList.h.

◆ initAsSleepy

bool Node::initAsSleepy
protected

Stores initial sleepy node. If this is false, this node does not accept sleep time changes.

Definition at line 487 of file NodeList.h.

◆ key

uint8_t Node::key[KEY_LENGTH]
protected

Shared key.

Definition at line 490 of file NodeList.h.

◆ keyValid

bool Node::keyValid
protected

Node shared key valid.

Definition at line 477 of file NodeList.h.

◆ keyValidFrom

timer_t Node::keyValidFrom
protected

Last time that Node and Gateway agreed a key.

Definition at line 483 of file NodeList.h.

◆ lastControlCounter

uint16_t Node::lastControlCounter
protected

Last message counter state for specific Node.

Definition at line 480 of file NodeList.h.

◆ lastDownlinkMsgCounter

uint16_t Node::lastDownlinkMsgCounter
protected

Last downlink message counter state for specific Node.

Definition at line 481 of file NodeList.h.

◆ lastMessageCounter

uint16_t Node::lastMessageCounter
protected

Last message counter state for specific Node.

Definition at line 479 of file NodeList.h.

◆ lastMessageTime

timer_t Node::lastMessageTime
protected

Node state.

Definition at line 491 of file NodeList.h.

◆ mac

uint8_t Node::mac[ENIGMAIOT_ADDR_LEN]
protected

Node address.

Definition at line 489 of file NodeList.h.

◆ nodeId

uint16_t Node::nodeId
protected

Node identifier asigned by gateway.

Definition at line 482 of file NodeList.h.

◆ nodeName

char Node::nodeName[NODE_NAME_LENGTH]
protected

Node name. Use as a human friendly name to avoid use of numeric address.

Definition at line 493 of file NodeList.h.

◆ packetErrors

uint32_t Node::packetErrors = 0

Number of errored packets.

Definition at line 470 of file NodeList.h.

◆ packetNumber

uint32_t Node::packetNumber = 0

Number of packets received from node to gateway.

Definition at line 469 of file NodeList.h.

◆ packetsHour

double Node::packetsHour = 0

Packet rate for a specific nope.

Definition at line 472 of file NodeList.h.

◆ per

double Node::per = 0

Current packet error rate of a specific node.

Definition at line 471 of file NodeList.h.

◆ qMessageLength

size_t Node::qMessageLength

Queued message length.

Definition at line 466 of file NodeList.h.

◆ qMessagePending

bool Node::qMessagePending = false

True if message should be sent just after next data message

Definition at line 467 of file NodeList.h.

◆ queuedMessage

uint8_t Node::queuedMessage[MAX_MESSAGE_LENGTH]

Message queued for sending to node in case of sleepy mode.

Definition at line 465 of file NodeList.h.

◆ rateFilter

FilterClass* Node::rateFilter
protected

Filter for message rate smoothing.

Definition at line 492 of file NodeList.h.

◆ rssi

int8_t Node::rssi
protected

Stores last RSSI measurement.

Definition at line 494 of file NodeList.h.

◆ sleepyNode

bool Node::sleepyNode = true
protected

Node sleepy definition.

Definition at line 484 of file NodeList.h.

◆ status

status_t Node::status
protected

Current node status. See enum node_status

Definition at line 478 of file NodeList.h.


The documentation for this class was generated from the following files: