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

Main gateway class. Manages communication with nodes and sends data to upper layer. More...

#include <EnigmaIOTGateway.h>

Public Member Functions

bool getShouldSave ()
 Gets flag that indicates if configuration should be saved. More...
 
char * getNetworkName ()
 Gets EnigmaIOT network name. More...
 
char * getNetworkKey (bool plain=false)
 Gets hashed EnigmaIOT network key. More...
 
void addWiFiManagerParameter (AsyncWiFiManagerParameter *p)
 Adds a parameter to configuration portal. 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...
 
bool configWiFiManager ()
 Starts configuration AP and web server and gets settings from it. More...
 
void begin (Comms_halClass *comm, uint8_t *networkKey=NULL, bool useDataCounter=true)
 Initalizes communication basic data and starts accepting node registration. More...
 
void handle ()
 This method should be called periodically for instance inside loop() function. It is used for internal gateway maintenance tasks. More...
 
void setTxLed (uint8_t led, time_t onTime=FLASH_LED_TIME)
 Sets a LED to be flashed every time a message is transmitted. More...
 
void setRxLed (uint8_t led, time_t onTime=FLASH_LED_TIME)
 Sets a LED to be flashed every time a message is received. More...
 
void onDataRx (onGwDataRx_t handler)
 Defines a function callback that will be called on every downlink data message that is received from a node. More...
 
void onHADiscovery (onHADiscovery_t handler)
 Defines a function callback that will be called when a Home Assistant discovery message is received from a node. More...
 
double getPER (uint8_t *address)
 Gets packet error rate of node that has a specific address. More...
 
uint32_t getTotalPackets (uint8_t *address)
 Gets total packets sent by node that has a specific address. More...
 
uint32_t getErrorPackets (uint8_t *address)
 Gets number of errored packets of node that has a specific address. More...
 
double getPacketsHour (uint8_t *address)
 Gets packet rate sent by node that has a specific address, in packets per hour. More...
 
bool sendDownstream (uint8_t *mac, const uint8_t *data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t payload_type=RAW, char *nodeName=NULL)
 Starts a downstream data message transmission. More...
 
void onNewNode (onNewNode_t handler)
 Defines a function callback that will be called every time a node gets connected or reconnected. More...
 
void onNodeDisconnected (onNodeDisconnected_t handler)
 Defines a function callback that will be called every time a node is disconnected. More...
 
void onGatewayRestartRequested (simpleEventHandler_t handler)
 Defines a function callback that will process a gateway restart request. More...
 
bool addInputMsgQueue (const uint8_t *addr, const uint8_t *msg, size_t len)
 Add message to input queue. More...
 
msg_queue_item_tgetInputMsgQueue (msg_queue_item_t *buffer)
 Gets next item in the queue. More...
 
void popInputMsgQueue ()
 Deletes next item in the queue. More...
 
int getActiveNodesNumber ()
 Gets number of active nodes. More...
 
NodeListgetNodes ()
 Gets nodes data structure. More...
 

Protected Member Functions

bool serverHello (const uint8_t *key, Node *node)
 Build a ServerHello message and send it to node. More...
 
bool sendBroadcastKey (Node *node)
 Sends broadcast key to node if it has requested it explicitly or it has notified during handshake. More...
 
bool processClientHello (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t *buf, size_t count, Node *node)
 Gets a buffer containing a ClientHello message and process it. This carries node public key to be used on Diffie Hellman algorithm. More...
 
bool processClockRequest (const uint8_t mac[ENIGMAIOT_ADDR_LEN], const uint8_t *buf, size_t count, Node *node)
 Starts clock sync procedure from node to gateway. More...
 
bool clockResponse (Node *node, uint64_t t1, uint64_t t2)
 Returns timestaps needed so that node can calculate time difference. More...
 
bool invalidateKey (Node *node, gwInvalidateReason_t reason)
 Creates an InvalidateKey message and sned it. This trigger a new key agreement to start on related node. More...
 
bool processDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node, bool encrypted=true)
 Processes data message from node. More...
 
bool processUnencryptedDataMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
 Processes unencrypted data message from node. More...
 
bool downstreamDataMessage (Node *node, const uint8_t *data, size_t len, control_message_type_t controlData, gatewayPayloadEncoding_t encoding=ENIGMAIOT)
 Builds, encrypts and sends a DownstreamData message. More...
 
bool processControlMessage (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
 Processes control message from node. More...
 
bool processNodeNameSet (const uint8_t mac[ENIGMAIOT_ADDR_LEN], uint8_t *buf, size_t count, Node *node)
 Processes new node name request fromn node. More...
 
bool nodeNameSetRespose (Node *node, int8_t error)
 Send back set name response. More...
 
void manageMessage (const uint8_t *mac, 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 loadFlashData ()
 Loads configuration from flash memory. More...
 
bool saveFlashData ()
 Saves configuration to flash memory. More...
 
bool sendHADiscoveryJSON (uint8_t *address, uint8_t *data, size_t len, const char *networkName, const char *nodeName)
 Sends a Home Assistant discovery message after receiving it from node. More...
 

Static Protected Member Functions

static void doSave (void)
 Activates a flag that signals that configuration has to be saved. More...
 
static void doResetConfig (void)
 Activates a flag that signals that configuration has to be saved. More...
 
static void rx_cb (uint8_t *mac_addr, uint8_t *data, uint8_t len)
 Function that will be called anytime this gateway receives a message. More...
 
static void tx_cb (uint8_t *mac_addr, uint8_t status)
 Function that will be called anytime this gateway sends a message to indicate status result of sending process. More...
 

Protected Attributes

uint8_t myPublicKey [KEY_LENGTH]
 Temporary public key store used during key agreement. More...
 
bool flashTx = false
 true if Tx LED should flash More...
 
volatile bool flashRx = false
 true if Rx LED should flash More...
 
node_t node
 temporary store to keep node data while processing a message More...
 
NodeList nodelist
 Node database that keeps status and shared keys. More...
 
Comms_halClasscomm
 Instance of physical communication layer. More...
 
int8_t txled = -1
 I/O pin to connect a led that flashes when gateway transmits data. More...
 
int8_t rxled = -1
 I/O pin to connect a led that flashes when gateway receives data. More...
 
unsigned long txLedOnTime
 Flash duration for Tx LED. More...
 
unsigned long rxLedOnTime
 Flash duration for Rx LED. More...
 
onGwDataRx_t notifyData
 Callback function that will be invoked when data is received from a node. More...
 
onHADiscovery_t notifyHADiscovery
 Callback function that will be invoked when HomeAssistant discovery message is received from a node. More...
 
onNewNode_t notifyNewNode
 Callback function that will be invoked when a new node is connected. More...
 
onNodeDisconnected_t notifyNodeDisconnection
 Callback function that will be invoked when a node gets disconnected. More...
 
simpleEventHandler_t notifyRestartRequested
 Callback function that will be invoked when a hardware restart is requested. More...
 
bool useCounter = true
 true if counter is used to check data messages order More...
 
gateway_config_t gwConfig
 Gateway specific configuration to be stored on flash memory. More...
 
char plainNetKey [KEY_LENGTH]
 
msg_queue_item_t tempBuffer
 Temporary storage for input message got from buffer. More...
 
EnigmaIOTRingBuffer< msg_queue_item_t > * input_queue
 Input messages buffer. It acts as a FIFO queue. More...
 
AsyncWebServer * server
 WebServer that holds configuration portal. More...
 
DNSServer * dns
 DNS server used by configuration portal. 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...
 

Friends

class GatewayAPI
 

Detailed Description

Main gateway class. Manages communication with nodes and sends data to upper layer.

Definition at line 120 of file EnigmaIOTGateway.h.

Member Function Documentation

◆ addInputMsgQueue()

bool EnigmaIOTGatewayClass::addInputMsgQueue ( const uint8_t *  addr,
const uint8_t *  msg,
size_t  len 
)

Add message to input queue.

Parameters
addrOrigin address
msgEnigmaIoT message
lenMessage length

Definition at line 792 of file EnigmaIOTGateway.cpp.

◆ addWiFiManagerParameter()

void EnigmaIOTGatewayClass::addWiFiManagerParameter ( AsyncWiFiManagerParameter *  p)
inline

Adds a parameter to configuration portal.

Parameters
pConfiguration parameter

Definition at line 368 of file EnigmaIOTGateway.h.

◆ begin()

void EnigmaIOTGatewayClass::begin ( Comms_halClass comm,
uint8_t *  networkKey = NULL,
bool  useDataCounter = true 
)

Initalizes communication basic data and starts accepting node registration.

Parameters
commPhysical layer to be used on this network
networkKeyNetwork key to protect shared key agreement
useDataCounterIndicates if a counter is going to be added to every message data to check message sequence. true by default

Definition at line 736 of file EnigmaIOTGateway.cpp.

◆ clockResponse()

bool EnigmaIOTGatewayClass::clockResponse ( Node node,
uint64_t  t1,
uint64_t  t2 
)
protected

Returns timestaps needed so that node can calculate time difference.

Parameters
nodePointer to data that corresponds to originating node
t1Origin clock
t2Received clock
Returns
Returns true if message could be correcly processed

Definition at line 1822 of file EnigmaIOTGateway.cpp.

◆ configWiFiManager()

bool EnigmaIOTGatewayClass::configWiFiManager ( )

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

Returns
Returns true if data was been correctly configured. false otherwise

Definition at line 494 of file EnigmaIOTGateway.cpp.

◆ doResetConfig()

void EnigmaIOTGatewayClass::doResetConfig ( void  )
staticprotected

Activates a flag that signals that configuration has to be saved.

Definition at line 47 of file EnigmaIOTGateway.cpp.

◆ doSave()

void EnigmaIOTGatewayClass::doSave ( void  )
staticprotected

Activates a flag that signals that configuration has to be saved.

Definition at line 42 of file EnigmaIOTGateway.cpp.

◆ downstreamDataMessage()

bool EnigmaIOTGatewayClass::downstreamDataMessage ( Node node,
const uint8_t *  data,
size_t  len,
control_message_type_t  controlData,
gatewayPayloadEncoding_t  encoding = ENIGMAIOT 
)
protected

Builds, encrypts and sends a DownstreamData message.

Parameters
nodeNode that downstream data message is going to
dataBuffer to store payload to be sent
lenLength of payload data
controlDataContent data type if control data
encodingIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK
Returns
Returns true if message could be correcly sent or scheduled

Definition at line 1489 of file EnigmaIOTGateway.cpp.

◆ getActiveNodesNumber()

int EnigmaIOTGatewayClass::getActiveNodesNumber ( )
inline

Gets number of active nodes.

Returns
Number of registered nodes

Definition at line 592 of file EnigmaIOTGateway.h.

◆ getErrorPackets()

uint32_t EnigmaIOTGatewayClass::getErrorPackets ( uint8_t *  address)

Gets number of errored packets of node that has a specific address.

Parameters
addressNode address
Returns
Node errored packets

Definition at line 1476 of file EnigmaIOTGateway.cpp.

◆ getInputMsgQueue()

msg_queue_item_t * EnigmaIOTGatewayClass::getInputMsgQueue ( msg_queue_item_t buffer)

Gets next item in the queue.

Returns
Next message to be processed

Definition at line 815 of file EnigmaIOTGateway.cpp.

◆ getNetworkKey()

char* EnigmaIOTGatewayClass::getNetworkKey ( bool  plain = false)
inline

Gets hashed EnigmaIOT network key.

Returns
Returns hashed EnigmaIOT network key

Definition at line 357 of file EnigmaIOTGateway.h.

◆ getNetworkName()

char* EnigmaIOTGatewayClass::getNetworkName ( )
inline

Gets EnigmaIOT network name.

Returns
Returns EnigmaIOT network name

Definition at line 349 of file EnigmaIOTGateway.h.

◆ getNodes()

NodeList* EnigmaIOTGatewayClass::getNodes ( )
inline

Gets nodes data structure.

Returns
All nodes data structure

Definition at line 600 of file EnigmaIOTGateway.h.

◆ getPacketsHour()

double EnigmaIOTGatewayClass::getPacketsHour ( uint8_t *  address)

Gets packet rate sent by node that has a specific address, in packets per hour.

Parameters
addressNode address
Returns
Node packet rate

Definition at line 1482 of file EnigmaIOTGateway.cpp.

◆ getPER()

double EnigmaIOTGatewayClass::getPER ( uint8_t *  address)

Gets packet error rate of node that has a specific address.

Parameters
addressNode address
Returns
Packet error rate

Definition at line 1460 of file EnigmaIOTGateway.cpp.

◆ getShouldSave()

bool EnigmaIOTGatewayClass::getShouldSave ( )

Gets flag that indicates if configuration should be saved.

Returns
Returns true if config data should be saved. false otherwise

Definition at line 55 of file EnigmaIOTGateway.cpp.

◆ getStatus()

void EnigmaIOTGatewayClass::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 858 of file EnigmaIOTGateway.cpp.

◆ getTotalPackets()

uint32_t EnigmaIOTGatewayClass::getTotalPackets ( uint8_t *  address)

Gets total packets sent by node that has a specific address.

Parameters
addressNode address
Returns
Node total sent packets

Definition at line 1470 of file EnigmaIOTGateway.cpp.

◆ handle()

void EnigmaIOTGatewayClass::handle ( )

This method should be called periodically for instance inside loop() function. It is used for internal gateway maintenance tasks.

digitalRead (rxled) &&

digitalRead (txled) &&

Definition at line 867 of file EnigmaIOTGateway.cpp.

◆ invalidateKey()

bool EnigmaIOTGatewayClass::invalidateKey ( Node node,
gwInvalidateReason_t  reason 
)
protected

Creates an InvalidateKey message and sned it. This trigger a new key agreement to start on related node.

Parameters
nodeNode to send Invalidate Key message to
reasonReason that produced key invalidation in gwInvalidateReason_t format
Returns
Returns true if message could be correcly sent

Definition at line 1624 of file EnigmaIOTGateway.cpp.

◆ loadFlashData()

bool EnigmaIOTGatewayClass::loadFlashData ( )
protected

Loads configuration from flash memory.

Returns
Returns true if data was read successfuly. false otherwise

Definition at line 611 of file EnigmaIOTGateway.cpp.

◆ manageMessage()

void EnigmaIOTGatewayClass::manageMessage ( const uint8_t *  mac,
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 935 of file EnigmaIOTGateway.cpp.

◆ nodeNameSetRespose()

bool EnigmaIOTGatewayClass::nodeNameSetRespose ( Node node,
int8_t  error 
)
protected

Send back set name response.

Parameters
nodePointer to data that corresponds to originating node
errorResult code of name set procedure (0: OK, -1: Already used, -2: Too long, -3: Empty name, -4: Message error)
Returns
Returns true if message could be correcly processed

Definition at line 1106 of file EnigmaIOTGateway.cpp.

◆ onDataRx()

void EnigmaIOTGatewayClass::onDataRx ( onGwDataRx_t  handler)
inline

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

Use example:

// First define the callback function
void processRxData (const uint8_t* mac, const uint8_t* buffer, uint8_t length, uint16_t lostMessages) {
// 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 449 of file EnigmaIOTGateway.h.

◆ onGatewayRestartRequested()

void EnigmaIOTGatewayClass::onGatewayRestartRequested ( simpleEventHandler_t  handler)
inline

Defines a function callback that will process a gateway restart request.

Parameters
handlerPointer to the function

Definition at line 565 of file EnigmaIOTGateway.h.

◆ onHADiscovery()

void EnigmaIOTGatewayClass::onHADiscovery ( onHADiscovery_t  handler)
inline

Defines a function callback that will be called when a Home Assistant discovery message is received from a node.

Parameters
handlerPointer to the function

Definition at line 458 of file EnigmaIOTGateway.h.

◆ onNewNode()

void EnigmaIOTGatewayClass::onNewNode ( onNewNode_t  handler)
inline

Defines a function callback that will be called every time a node gets connected or reconnected.

Use example:

// First define the callback function
void newNodeConnected (uint8_t* mac) {
// Do whatever you need new node address
}
void setup () {
.....
// Now register function as new node condition handler
.....
}
void loop {
.....
.....
}
Parameters
handlerPointer to the function

Definition at line 528 of file EnigmaIOTGateway.h.

◆ onNodeDisconnected()

void EnigmaIOTGatewayClass::onNodeDisconnected ( onNodeDisconnected_t  handler)
inline

Defines a function callback that will be called every time a node is disconnected.

Use example:

// First define the callback function
void nodeDisconnected (uint8_t* mac, gwInvalidateReason_t reason) {
// Do whatever you need node address and disconnection reason
}
void setup () {
.....
// Now register function as new node condition handler
.....
}
void loop {
.....
.....
}
Parameters
handlerPointer to the function

Definition at line 557 of file EnigmaIOTGateway.h.

◆ onWiFiManagerExit()

void EnigmaIOTGatewayClass::onWiFiManagerExit ( onWiFiManagerExit_t  handle)
inline

Register callback to be called on wifi manager exit.

Parameters
handleCallback function pointer

Definition at line 378 of file EnigmaIOTGateway.h.

◆ onWiFiManagerStarted()

void EnigmaIOTGatewayClass::onWiFiManagerStarted ( simpleEventHandler_t  handle)
inline

Register callback to be called on wifi manager start.

Parameters
handleCallback function pointer

Definition at line 386 of file EnigmaIOTGateway.h.

◆ popInputMsgQueue()

void EnigmaIOTGatewayClass::popInputMsgQueue ( )

Deletes next item in the queue.

Definition at line 843 of file EnigmaIOTGateway.cpp.

◆ processClientHello()

bool EnigmaIOTGatewayClass::processClientHello ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
const uint8_t *  buf,
size_t  count,
Node node 
)
protected

Gets a buffer containing a ClientHello message and process it. This carries node public key to be used on 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 ClientHello message
nodeNode entry that Client Hello message comes from
Returns
Returns true if message could be correcly processed

Definition at line 1660 of file EnigmaIOTGateway.cpp.

◆ processClockRequest()

bool EnigmaIOTGatewayClass::processClockRequest ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
const uint8_t *  buf,
size_t  count,
Node node 
)
protected

Starts clock sync procedure from node to gateway.

Parameters
macAddress where this message was received from
bufPointer to the buffer that contains the message
countMessage length in number of bytes of ClockRequest message
nodeNode entry that Client Hello message comes from
Returns
Returns true if message could be correcly processed

Definition at line 1739 of file EnigmaIOTGateway.cpp.

◆ processControlMessage()

bool EnigmaIOTGatewayClass::processControlMessage ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
uint8_t *  buf,
size_t  count,
Node node 
)
protected

Processes control message from node.

Parameters
macNode address
bufBuffer that stores received message
countLength of received data
nodeNode where data message comes from
Returns
Returns true if message could be correcly decoded

Definition at line 1250 of file EnigmaIOTGateway.cpp.

◆ processDataMessage()

bool EnigmaIOTGatewayClass::processDataMessage ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
uint8_t *  buf,
size_t  count,
Node node,
bool  encrypted = true 
)
protected

Processes data message from node.

Parameters
macNode address
bufBuffer that stores received message
countLength of received data
nodeNode where data message comes from
encryptedtrue if received message is encrypted
Returns
Returns true if message could be correcly decoded

Definition at line 1377 of file EnigmaIOTGateway.cpp.

◆ processNodeNameSet()

bool EnigmaIOTGatewayClass::processNodeNameSet ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
uint8_t *  buf,
size_t  count,
Node node 
)
protected

Processes new node name request fromn node.

Parameters
macNode address
bufBuffer that stores received message
countLength of received data
nodeNode where data message comes from
Returns
Returns true if message could be correcly decoded

Definition at line 1175 of file EnigmaIOTGateway.cpp.

◆ processUnencryptedDataMessage()

bool EnigmaIOTGatewayClass::processUnencryptedDataMessage ( const uint8_t  mac[ENIGMAIOT_ADDR_LEN],
uint8_t *  buf,
size_t  count,
Node node 
)
protected

Processes unencrypted data message from node.

Parameters
macNode address
bufBuffer that stores received message
countLength of received data
nodeNode where data message comes from
Returns
Returns true if message could be correcly decoded

Definition at line 1324 of file EnigmaIOTGateway.cpp.

◆ rx_cb()

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

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

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

Definition at line 849 of file EnigmaIOTGateway.cpp.

◆ saveFlashData()

bool EnigmaIOTGatewayClass::saveFlashData ( )
protected

Saves configuration to flash memory.

Returns
Returns true if data could be written successfuly. false otherwise

Definition at line 692 of file EnigmaIOTGateway.cpp.

◆ sendBroadcastKey()

bool EnigmaIOTGatewayClass::sendBroadcastKey ( Node node)
protected

Sends broadcast key to node if it has requested it explicitly or it has notified during handshake.

Parameters
nodeEntry in node list database to get destination address
Returns
Returns true if message was successfully sent. false otherwise

Definition at line 1903 of file EnigmaIOTGateway.cpp.

◆ sendDownstream()

bool EnigmaIOTGatewayClass::sendDownstream ( uint8_t *  mac,
const uint8_t *  data,
size_t  len,
control_message_type_t  controlData,
gatewayPayloadEncoding_t  payload_type = RAW,
char *  nodeName = NULL 
)

Starts a downstream data message transmission.

Parameters
macNode address
dataPayload buffer
lenPayload length
controlDataIndicates if data is control data and its class
payload_typeIdentifies data encoding of payload. It can be RAW, CAYENNELPP, MSGPACK
nodeNameCauses data to be sent to a node with this name instead of numeric address
Returns
Returns true if everything went ok

Definition at line 364 of file EnigmaIOTGateway.cpp.

◆ sendHADiscoveryJSON()

bool EnigmaIOTGatewayClass::sendHADiscoveryJSON ( uint8_t *  address,
uint8_t *  data,
size_t  len,
const char *  networkName,
const char *  nodeName 
)
protected

Sends a Home Assistant discovery message after receiving it from node.

Parameters
addressNode physical address
dataMsgPack input buffer
lenInput buffer length
networkNameEnigmaIOT network name
nodeNameNode name. Can be NULL
Returns
Returns true if data could be written successfuly. false otherwise

Definition at line 1989 of file EnigmaIOTGateway.cpp.

◆ serverHello()

bool EnigmaIOTGatewayClass::serverHello ( const uint8_t *  key,
Node node 
)
protected

Build a ServerHello message and send it to node.

Parameters
keyNode public key to be used on Diffie Hellman algorithm
nodeEntry in node list database where node will be registered
Returns
Returns true if ServerHello message was successfully sent. false otherwise

Definition at line 1910 of file EnigmaIOTGateway.cpp.

◆ setRxLed()

void EnigmaIOTGatewayClass::setRxLed ( uint8_t  led,
time_t  onTime = FLASH_LED_TIME 
)

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

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

Definition at line 66 of file EnigmaIOTGateway.cpp.

◆ setTxLed()

void EnigmaIOTGatewayClass::setTxLed ( 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 59 of file EnigmaIOTGateway.cpp.

◆ tx_cb()

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

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

Parameters
mac_addrAddress of message destination
statusResult of sending process

Definition at line 854 of file EnigmaIOTGateway.cpp.

Friends And Related Function Documentation

◆ GatewayAPI

friend class GatewayAPI
friend

Definition at line 155 of file EnigmaIOTGateway.h.

Member Data Documentation

◆ comm

Comms_halClass* EnigmaIOTGatewayClass::comm
protected

Instance of physical communication layer.

Definition at line 127 of file EnigmaIOTGateway.h.

◆ dns

DNSServer* EnigmaIOTGatewayClass::dns
protected

DNS server used by configuration portal.

Definition at line 150 of file EnigmaIOTGateway.h.

◆ flashRx

volatile bool EnigmaIOTGatewayClass::flashRx = false
protected

true if Rx LED should flash

Definition at line 124 of file EnigmaIOTGateway.h.

◆ flashTx

bool EnigmaIOTGatewayClass::flashTx = false
protected

true if Tx LED should flash

Definition at line 123 of file EnigmaIOTGateway.h.

◆ gwConfig

gateway_config_t EnigmaIOTGatewayClass::gwConfig
protected

Gateway specific configuration to be stored on flash memory.

Definition at line 140 of file EnigmaIOTGateway.h.

◆ input_queue

EnigmaIOTRingBuffer<msg_queue_item_t>* EnigmaIOTGatewayClass::input_queue
protected

Input messages buffer. It acts as a FIFO queue.

Definition at line 147 of file EnigmaIOTGateway.h.

◆ myPublicKey

uint8_t EnigmaIOTGatewayClass::myPublicKey[KEY_LENGTH]
protected

Temporary public key store used during key agreement.

Definition at line 122 of file EnigmaIOTGateway.h.

◆ node

node_t EnigmaIOTGatewayClass::node
protected

temporary store to keep node data while processing a message

Definition at line 125 of file EnigmaIOTGateway.h.

◆ nodelist

NodeList EnigmaIOTGatewayClass::nodelist
protected

Node database that keeps status and shared keys.

Definition at line 126 of file EnigmaIOTGateway.h.

◆ notifyData

onGwDataRx_t EnigmaIOTGatewayClass::notifyData
protected

Callback function that will be invoked when data is received from a node.

Definition at line 132 of file EnigmaIOTGateway.h.

◆ notifyHADiscovery

onHADiscovery_t EnigmaIOTGatewayClass::notifyHADiscovery
protected

Callback function that will be invoked when HomeAssistant discovery message is received from a node.

Definition at line 134 of file EnigmaIOTGateway.h.

◆ notifyNewNode

onNewNode_t EnigmaIOTGatewayClass::notifyNewNode
protected

Callback function that will be invoked when a new node is connected.

Definition at line 136 of file EnigmaIOTGateway.h.

◆ notifyNodeDisconnection

onNodeDisconnected_t EnigmaIOTGatewayClass::notifyNodeDisconnection
protected

Callback function that will be invoked when a node gets disconnected.

Definition at line 137 of file EnigmaIOTGateway.h.

◆ notifyRestartRequested

simpleEventHandler_t EnigmaIOTGatewayClass::notifyRestartRequested
protected

Callback function that will be invoked when a hardware restart is requested.

Definition at line 138 of file EnigmaIOTGateway.h.

◆ notifyWiFiManagerExit

onWiFiManagerExit_t EnigmaIOTGatewayClass::notifyWiFiManagerExit
protected

Function called when configuration portal exits.

Definition at line 152 of file EnigmaIOTGateway.h.

◆ notifyWiFiManagerStarted

simpleEventHandler_t EnigmaIOTGatewayClass::notifyWiFiManagerStarted
protected

Function called when configuration portal is started.

Definition at line 153 of file EnigmaIOTGateway.h.

◆ plainNetKey

char EnigmaIOTGatewayClass::plainNetKey[KEY_LENGTH]
protected

Definition at line 141 of file EnigmaIOTGateway.h.

◆ rxled

int8_t EnigmaIOTGatewayClass::rxled = -1
protected

I/O pin to connect a led that flashes when gateway receives data.

Definition at line 129 of file EnigmaIOTGateway.h.

◆ rxLedOnTime

unsigned long EnigmaIOTGatewayClass::rxLedOnTime
protected

Flash duration for Rx LED.

Definition at line 131 of file EnigmaIOTGateway.h.

◆ server

AsyncWebServer* EnigmaIOTGatewayClass::server
protected

WebServer that holds configuration portal.

Definition at line 149 of file EnigmaIOTGateway.h.

◆ tempBuffer

msg_queue_item_t EnigmaIOTGatewayClass::tempBuffer
protected

Temporary storage for input message got from buffer.

Definition at line 145 of file EnigmaIOTGateway.h.

◆ txled

int8_t EnigmaIOTGatewayClass::txled = -1
protected

I/O pin to connect a led that flashes when gateway transmits data.

Definition at line 128 of file EnigmaIOTGateway.h.

◆ txLedOnTime

unsigned long EnigmaIOTGatewayClass::txLedOnTime
protected

Flash duration for Tx LED.

Definition at line 130 of file EnigmaIOTGateway.h.

◆ useCounter

bool EnigmaIOTGatewayClass::useCounter = true
protected

true if counter is used to check data messages order

Definition at line 139 of file EnigmaIOTGateway.h.

◆ wifiManager

AsyncWiFiManager* EnigmaIOTGatewayClass::wifiManager
protected

Wifi configuration portal.

Definition at line 151 of file EnigmaIOTGateway.h.


The documentation for this class was generated from the following files:
EnigmaIOTGatewayClass::onNodeDisconnected
void onNodeDisconnected(onNodeDisconnected_t handler)
Defines a function callback that will be called every time a node is disconnected.
Definition: EnigmaIOTGateway.h:557
EnigmaIOTNodeClass::handle
void handle()
This method should be called periodically for instance inside loop() function. It is used for interna...
Definition: EnigmaIOTNode.cpp:1003
nodeDisconnected
void nodeDisconnected(uint8_t *mac, gwInvalidateReason_t reason)
Definition: EnigmaIOTGatewayDummy.cpp:224
EnigmaIOTNode
EnigmaIOTNodeClass EnigmaIOTNode
Definition: EnigmaIOTNode.cpp:2719
loop
void loop()
Definition: EnigmaIOT-Button-Controller.cpp:157
EnigmaIOTGatewayClass::onNewNode
void onNewNode(onNewNode_t handler)
Defines a function callback that will be called every time a node gets connected or reconnected.
Definition: EnigmaIOTGateway.h:528
setup
void setup()
Definition: EnigmaIOT-Button-Controller.cpp:101
EnigmaIOTGateway
EnigmaIOTGatewayClass EnigmaIOTGateway
Definition: EnigmaIOTGateway.cpp:2050
newNodeConnected
void newNodeConnected(uint8_t *mac, uint16_t node_id, char *nodeName=NULL)
Definition: EnigmaIOTGatewayDummy.cpp:205
processRxData
void processRxData(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
Definition: EnigmaIOT-Button-Controller.cpp:83
gwInvalidateReason_t
gwInvalidateReason_t
Key invalidation reason definition.
Definition: EnigmaIOTGateway.h:75
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:655