 |
EnigmaIOT
0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
23 memcpy (thisNode.
mac,
mac, 6);
33 port->printf (
"Node: %d\n",
nodeId);
36 port->printf (
"\tMAC Address: %s\n", macstr);
38 port->printf (
"\tKey valid from: %lu ms ago\n", (millis () -
keyValidFrom));
39 port->printf (
"\tKey: %s\n",
keyValid ?
"Valid" :
"Invalid");
40 port->print (
"\tStatus: ");
43 port->println (
"Unregistered");
46 port->println (
"Initializing");
49 port->println (
"Going to sleep");
52 port->println (
"Wait for server hello");
55 port->println (
"Wait for Downlik");
58 port->println (
"Registered. Wait for messages");
84 keyValid (nodeData.keyValid),
86 lastMessageCounter (nodeData.lastMessageCounter),
87 nodeId (nodeData.nodeId),
88 keyValidFrom (nodeData.keyValidFrom)
93 memcpy (
key, nodeData.
key, sizeof (uint16_t));
94 memcpy (
mac, nodeData.
mac, 6);
105 DEBUG_DBG (
"Reset node");
114 DEBUG_DBG (
"Reset packet rate");
130 return &(
nodes[nodeId]);
137 if (!memcmp (
nodes[index].mac, mac, 6)) {
139 return &(
nodes[index]);
154 return &(
nodes[index]);
167 DEBUG_ERROR (
"Name too long %s", name);
171 if (!strlen (name)) {
172 DEBUG_ERROR (
"Empty name", name);
178 DEBUG_DBG (
"Node %d status is %d", i,
nodes[i].
status);
181 DEBUG_DBG (
"Node %d name is %s", i, currentNodeNamme ? currentNodeNamme :
"NULL");
182 if (currentNodeNamme && !strncmp (currentNodeNamme, name,
NODE_NAME_LENGTH)) {
185 DEBUG_INFO (
"Found node name %s in Node List with address %s", name,
mac2str (address, addrStr));
187 DEBUG_ERROR (
"Duplicated name %s", name);
201 return &(
nodes[index]);
210 uint16_t counter = 0;
258 for (
int i = nodeId + 1; i <
NUM_NODES; i++) {
uint16_t lastMessageCounter
Last message counter state for specific Node.
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.
EnigmaIoT sensor node management structures.
void printToSerial(Stream *port)
Dumps node list data to a Stream object.
Node nodes[NUM_NODES]
Static Node array that holds maximum number of supported nodes.
Node * getNewNode(const uint8_t *mac)
Finds a node that correspond with given address of creates a new one if it does not exist.
bool keyValid
Node shared key valid.
Node * getNodeFromMAC(const uint8_t *mac)
Gets node that correspond with given address.
NodeList()
Node list constructor.
static const size_t ENIGMAIOT_ADDR_LEN
Address size. Mac address = 6 bytes.
uint8_t key[32]
Shared key.
static const uint8_t NODE_NAME_LENGTH
Maximum number of characters of node name.
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,...
void setMacAddress(uint8_t *macAddress)
Sets node address.
timer_t keyValidFrom
Last time that Node and Gateway agreed a key.
void initRateFilter()
Starts smoothing filter.
char * mac2str(const uint8_t *mac, char *buffer)
Debug helper function that generates a string that represent a MAC address.
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 ffor a specific nope.
Node * getNextActiveNode(uint16_t nodeId)
Gets next active node by nodeId.
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.
status_t status
Node state.
uint8_t mac[ENIGMAIOT_ADDR_LEN]
Node address.
char * getNodeName()
Gets Node name.
FilterClass * rateFilter
Filter for message rate smoothing.
time_t keyValidFrom
Last time that Node and Gateway agreed a key.
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.
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)
const uint8_t KEY_LENGTH
Key length used by selected crypto algorythm. The only tested value is 32. Change it only if you know...