|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
9 #ifndef _ENIGMAIOTJSONCONTROLLER_h
10 #define _ENIGMAIOTJSONCONTROLLER_h
12 #if defined(ARDUINO) && ARDUINO >= 100
19 #include <ArduinoJson.h>
20 #if SUPPORT_HA_DISCOVERY
24 #if defined ESP8266 || defined ESP32
27 #if SUPPORT_HA_DISCOVERY
28 typedef std::function<void ()> haDiscovery_call_t;
29 #endif // SUPPORT_HA_DISCOVERY
31 #error This code only supports ESP8266 or ESP32 platforms
32 #endif // defined ESP8266 || defined ESP32
38 #if SUPPORT_HA_DISCOVERY
39 std::queue<haDiscovery_call_t> haCallQueue;
40 bool doSendHAdiscovery =
false;
43 #endif // SUPPORT_HA_DISCOVERY
82 DEBUG_INFO (
"Connect inform");
84 #if SUPPORT_HA_DISCOVERY
88 DEBUG_INFO (
"Enable HA Discovery");
89 doSendHAdiscovery =
true;
90 sendHAtime = millis ();
91 #endif // SUPPORT_HA_DISCOVERY
116 #if SUPPORT_HA_DISCOVERY
117 void callHAdiscoveryCalls () {
118 if (doSendHAdiscovery && millis () - sendHAtime > sendHAdelay) {
119 haDiscovery_call_t hacall = 0;
120 DEBUG_INFO (
"Call HA discovery");
121 if (haCallQueue.size ()) {
122 hacall = haCallQueue.front ();
124 DEBUG_INFO (
"haCallQueue size is %d", haCallQueue.size ());
126 DEBUG_INFO (
"Execute hacall");
129 sendHAtime = millis ();
136 doSendHAdiscovery =
false;
138 DEBUG_INFO (
" Exit call HA discovery. Delay = %d. doSendHAdiscovery = %s",
139 sendHAdelay, doSendHAdiscovery ?
"true" :
"false");
171 int len = measureMsgPack (json) + 1;
172 uint8_t* buffer = (uint8_t*)malloc (len);
173 len = serializeMsgPack (json, (
char*)buffer, len);
175 size_t strLen = measureJson (json) + 1;
176 char* strBuffer = (
char*)calloc (
sizeof (uint8_t), strLen);
180 serializeJson (json, strBuffer, strLen);
181 DEBUG_INFO (
"Trying to send: %s", strBuffer);
186 DEBUG_WARN (
"---- Error sending data");
188 DEBUG_INFO (
"---- Data sent");
199 #if SUPPORT_HA_DISCOVERY
200 void addHACall (haDiscovery_call_t HACall) {
201 haCallQueue.push (HACall);
204 bool sendHADiscovery (uint8_t*
data,
size_t len) {
206 DEBUG_WARN (
"Empty HA message");
213 DEBUG_WARN (
"---- Error sending data");
215 DEBUG_INFO (
"---- Data sent");
222 #endif // _ENIGMAIOTJSONCONTROLLER_h
virtual void loop()=0
This should be called periodically for module handling.
#define HA_FIRST_DISCOVERY_DELAY
virtual void configManagerStart()=0
Called when wifi manager starts config portal.
virtual void configManagerExit(bool status)=0
Called when wifi manager exits config portal.
#define HA_NEXT_DISCOVERY_DELAY_SLEEPY
#define HA_NEXT_DISCOVERY_DELAY
nodeMessageType
Message code definition.
virtual void disconnectInform(nodeInvalidateReason_t reason)
Used to notify controller that it is unregistered on EnigmaIOT network.
#define HA_FIRST_DISCOVERY_DELAY_SLEEPY
virtual bool sendStartAnouncement()=0
Send a message to notify node has started running.
virtual void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
void sendDataCallback(sendData_cb cb)
Register send data callback to run when module needs to send a message.
bool getSleepy()
Gets node working mode regarding battery saving strategy. If node is sleepy it will turn into deep sl...
bool sendJson(DynamicJsonDocument &json)
Sends a JSON encoded message to lower layer.
virtual bool loadConfig()=0
Loads output module configuration.
EnigmaIOTNodeClass * enigmaIotNode
virtual bool saveConfig()=0
Saves output module configuration.
virtual bool sendCommandResp(const char *command, bool result)=0
Sends command processing response acknowledge.
virtual bool processRxCommand(const uint8_t *mac, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)=0
Called to process a downlink command.
Library to build a node for EnigmaIoT system.
virtual void setup(EnigmaIOTNodeClass *node, void *config=NULL)=0
Initialize data structures.
Main node class. Manages communication with gateway and allows sending and receiving user data.
nodeInvalidateReason_t
Key invalidation reason definition.
Node * getNode()
Gets Node instance.