|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
23 memcpy (thisNode.
mac,
mac, 6);
34 port->printf (
"Node: %d\n",
nodeId);
37 port->printf (
"\tMAC Address: %s\n", macstr);
39 port->printf (
"\tKey valid from: %lu ms ago\n", (millis () -
keyValidFrom));
40 port->printf (
"\tKey: %s\n",
keyValid ?
"Valid" :
"Invalid");
41 port->print (
"\tStatus: ");
44 port->println (
"Unregistered");
47 port->println (
"Initializing");
50 port->println (
"Going to sleep");
53 port->println (
"Wait for server hello");
56 port->println (
"Wait for Downlik");
59 port->println (
"Registered. Wait for messages");
85 keyValid (nodeData.keyValid),
87 lastMessageCounter (nodeData.lastMessageCounter),
88 nodeId (nodeData.nodeId),
89 keyValidFrom (nodeData.keyValidFrom),
95 memcpy (
key, nodeData.
key, sizeof (uint16_t));
96 memcpy (
mac, nodeData.
mac, 6);
107 DEBUG_DBG (
"Reset node");
123 DEBUG_DBG (
"Reset packet rate");
139 return &(
nodes[nodeId]);
152 return &(
nodes[index]);
185 DEBUG_DBG (
"Address '%s' is broadcast node", name);
192 return &(
nodes[index]);
205 DEBUG_ERROR (
"Name too long %s", name);
209 if (!strlen (name)) {
210 DEBUG_ERROR (
"Empty name", name);
216 DEBUG_DBG (
"Node %d status is %d", i,
nodes[i].
status);
219 DEBUG_DBG (
"Node %d name is %s", i, currentNodeNamme ? currentNodeNamme :
"NULL");
220 if (currentNodeNamme && !strncmp (currentNodeNamme, name,
NODE_NAME_LENGTH)) {
223 DEBUG_INFO (
"Found node name %s in Node List with address %s", name,
mac2str (address));
225 DEBUG_ERROR (
"Duplicated name %s", name);
239 return &(
nodes[index]);
248 uint16_t counter = 0;
296 if (nodeId == 0xFFFF) {
301 for (
int i = nodeId + 1; i <
NUM_NODES; i++) {
uint16_t lastMessageCounter
Last message counter state for specific Node.
Node broadcastNode
Node instance that holds data used for broadcast messages. This does not represent any individual nod...
bool broadcastKeyRequested
Node is waiting for broadcast key.
uint16_t lastMessageCounter
Last message counter state for specific Node.
Node * findEmptyNode()
Searches for a free place for a new Node instance.
Node * getNodeFromName(const char *name)
Gets node that correspond with given node name.
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
void setNodeName(const char *name)
Sets Node name.
EnigmaIoT sensor node management structures.
void printToSerial(Stream *port)
Dumps node list data to a Stream object.
void setStatus(status_t status)
Sets status for finite state machine that represents node.
Node nodes[NUM_NODES]
Static Node array that holds maximum number of supported nodes.
static const uint8_t NODE_NAME_LENGTH
Maximum number of characters of node name.
void initBroadcastNode()
Init broadcast node data.
Node * getNewNode(const uint8_t *mac)
Finds a node that correspond with given address of creates a new one if it does not exist.
void setNodeId(uint16_t nodeId)
Sets a new Node identifier.
uint8_t * str2mac(const char *macAddrString, uint8_t *macBytes)
Debug helper function that creates MAC address byte array from text representation.
bool keyValid
Node shared key valid.
Node * getNodeFromMAC(const uint8_t *mac)
Gets node that correspond with given address.
NodeList()
Node list constructor.
uint8_t key[32]
Shared key.
static const int RATE_AVE_ORDER
Message rate filter order.
node_t getNodeData()
Gets a struct that represents node object. May be used for node serialization.
bool keyValid
Node shared key valid.
uint16_t nodeId
Node identifier asigned by gateway.
bool unregisterNode(uint16_t nodeId)
Frees up a node and marks it as available.
uint16_t nodeId
Node identifier asigned by gateway.
float addValue(float value)
Pushes a new value for calculation. Until the buffer is filled up to filter order,...
uint8_t enigmaIOTVersion[3]
Protocol version, filled when a version message is received.
uint16_t lastControlCounter
Last message counter state for specific Node.
timer_t keyValidFrom
Last time that Node and Gateway agreed a key.
char nodeName[NODE_NAME_LENGTH]
Node name. Use as a human friendly name to avoid use of numeric address.
void setSleepy(bool sleepy)
Sets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sl...
void initRateFilter()
Starts smoothing filter.
void reset()
Resets all node fields to a default initial and not registered state.
void setEncryptionKey(const uint8_t *key)
Sets encryption key.
status_t status
Current node status. See enum node_status
double packetsHour
Packet rate for a specific nope.
Node * getNextActiveNode(uint16_t nodeId)
Gets next active node by nodeId.
uint8_t * getEncriptionKey()
Gets Node encryption key.
static const int NUM_NODES
Maximum number of nodes that this gateway can handle.
Struct that define node fields. Used for long term storage needs.
uint8_t key[KEY_LENGTH]
Shared key.
uint16_t lastDownlinkMsgCounter
Last downlink message counter state for specific Node.
status_t status
Node state.
static const char BROADCAST_NONE_NAME[]
Name to reference broadcast node.
void setMacAddress(const uint8_t *macAddress)
Sets node address.
uint8_t mac[ENIGMAIOT_ADDR_LEN]
Node address.
const uint8_t KEY_LENGTH
Key length used by selected crypto algorythm. The only tested value is 32. Change it only if you know...
char * getNodeName()
Gets Node name.
FilterClass * rateFilter
Filter for message rate smoothing.
time_t keyValidFrom
Last time that Node and Gateway agreed a key.
static const uint8_t BROADCAST_ADDRESS[]
Broadcast address.
void updatePacketsRate(float value)
Adds a new message rate value for filter calculation.
Class definition for a single sensor Node.
int8_t checkNodeName(const char *name, const uint8_t *address)
Check Node name for duplicate.
float addWeigth(float coeff)
Adds a new weighting value. It is pushed on the array so latest value will be used for older data.
void clear()
Resets state of the filter to an initial value.
void printToSerial(Stream *port=&Serial)
Dumps node data to the given stream, Serial by default. This method may be used for debugging.
uint8_t mac[ENIGMAIOT_ADDR_LEN]
Node address.
char * mac2str(const uint8_t *mac, char *extBuffer)
Debug helper function that generates a string that represent a MAC address.
Auxiliary function definition.
Node * getNodeFromID(uint16_t nodeId)
Gets node that correspond with given nodeId.
char nodeName[NODE_NAME_LENGTH]
Node name. Use as a human friendly name to avoid use of numeric address.
uint16_t countActiveNodes()
Gets the number of active nodes (registered or registering)