|
EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
Go to the documentation of this file.
9 using namespace placeholders;
28 DEBUG_WARN (
"Wrong message type");
33 DEBUG_WARN (
"Wrong payload encoding");
38 DynamicJsonDocument doc (256);
41 memcpy (tempBuffer, buffer, length);
42 DeserializationError error = deserializeMsgPack (doc, tempBuffer, length);
44 if (error != DeserializationError::Ok) {
45 DEBUG_WARN (
"Error decoding command: %s", error.c_str ());
52 size_t strLen = measureJson (doc) + 1;
53 char* strBuffer = (
char*)malloc (strLen);
54 serializeJson (doc, strBuffer, strLen);
55 DEBUG_WARN (
"Data: %s", strBuffer);
60 DEBUG_WARN (
"Wrong format");
67 DEBUG_WARN (
"Request LED status. LED = %s", led ==
_LED_ON ?
"ON" :
"OFF");
68 if (!sendLedStatus ()) {
69 DEBUG_WARN (
"Error sending LED status");
78 if (doc.containsKey (
ledKey)) {
79 if (doc[
ledKey].as<int> () == 1) {
81 }
else if (doc[
ledKey].as<int> () == 0) {
84 DEBUG_WARN (
"Wrong LED value: %d", doc[
ledKey].as<int> ());
87 DEBUG_WARN (
"Set LED status to %s", led ==
_LED_ON ?
"ON" :
"OFF");
89 DEBUG_WARN (
"Wrong format");
94 if (!sendLedStatus ()) {
95 DEBUG_WARN (
"Error sending LED status");
106 const size_t capacity = JSON_OBJECT_SIZE (2);
107 DynamicJsonDocument json (capacity);
112 return sendJson (json);
123 #if SUPPORT_HA_DISCOVERY
133 enigmaIotNode = node;
140 sendStartAnouncement ();
144 DEBUG_DBG (
"Finish begin");
161 DEBUG_INFO (
"==== CCost Controller Configuration start ====");
166 DEBUG_INFO (
"==== CCost Controller Configuration result ====");
180 #if SUPPORT_HA_DISCOVERY
186 uint8_t* msgPackBuffer;
189 DEBUG_WARN (
"JSON object instance does not exist");
208 msgPackBuffer = (uint8_t*)malloc (bufferLen);
212 DEBUG_INFO (
"Resulting MSG pack length: %d", len);
214 if (!sendHADiscovery (msgPackBuffer, len)) {
215 DEBUG_WARN (
"Error sending HA discovery message");
223 free (msgPackBuffer);
226 #endif // SUPPORT_HA_DISCOVERY
constexpr auto CONFIG_FILE
Custom configuration file name.
size_t measureMessage()
Gets needed buffer size for discovery message.
nodeMessageType
Message code definition.
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
size_t getAnounceMessage(int bufferlen, uint8_t *buffer)
Gets entity anounce message to be sent over EnigmaIOT message.
virtual void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
void loop() override
This should be called periodically for module handling.
void configManagerStart() override
Called when wifi manager starts config portal.
void setStateOn(const char *payload)
The payload that represents the on state. Used when value that represents on state in the state_topic...
void setStateOff(const char *payload)
The payload that represents the off state. Used when value that represents off state in the state_top...
void setPayloadOff(const char *payload)
The payload that represents off state. If specified, will be used for both comparing to the value in ...
bool saveConfig() override
Saves output module configuration.
void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
bool sendCommandResp(const char *command, bool result) override
Sends command processing response acknowledge.
void configManagerExit(bool status) override
Called when wifi manager exits config portal.
Main node class. Manages communication with gateway and allows sending and receiving user data.
void setPayloadOn(const char *payload)
The payload that represents on state. If specified, will be used for both comparing to the value in t...
void setup(EnigmaIOTNodeClass *node, void *data=NULL)
Initialize data structures.
void setValueField(const char *payload)
Defines a json key to extract device’s state from the state_topic. To determine the switches’s state ...
bool processRxCommand(const uint8_t *address, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding) override
Called to process a downlink command.
bool loadConfig() override
Loads output module configuration.