EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SmartSwitchController.cpp
Go to the documentation of this file.
1 //
2 //
3 //
4 
5 #include <functional>
7 
8 using namespace std;
9 using namespace placeholders;
10 
11 constexpr auto CONFIG_FILE = "/customconf.json";
12 
13 // -----------------------------------------
14 // You may add some global variables you need here,
15 // like serial port instances, I2C, etc
16 // -----------------------------------------
17 const char* relayKey = "rly";
18 const char* commandKey = "cmd";
19 const char* buttonKey = "button";
20 const char* linkKey = "link";
21 const char* bootStateKey = "bstate";
22 
23 bool CONTROLLER_CLASS_NAME::processRxCommand (const uint8_t* address, const uint8_t* buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding) {
24  // Process incoming messages here
25  // They are normally encoded as MsgPack so you can confert them to JSON very easily
27  DEBUG_WARN ("Wrong message type");
28  return false;
29  }
30  // Check payload encoding
31  if (payloadEncoding != MSG_PACK) {
32  DEBUG_WARN ("Wrong payload encoding");
33  return false;
34  }
35 
36  // Decode payload
37  DynamicJsonDocument doc (256);
38  uint8_t tempBuffer[MAX_MESSAGE_LENGTH];
39 
40  memcpy (tempBuffer, buffer, length);
41  DeserializationError error = deserializeMsgPack (doc, tempBuffer, length);
42  // Check decoding
43  if (error != DeserializationError::Ok) {
44  DEBUG_WARN ("Error decoding command: %s", error.c_str ());
45  return false;
46  }
47 
48  DEBUG_WARN ("Command: %d = %s", command, command == nodeMessageType_t::DOWNSTREAM_DATA_GET ? "GET" : "SET");
49 
50  // Dump debug data
51  size_t strLen = measureJson (doc) + 1;
52  char* strBuffer = (char*)malloc (strLen);
53  serializeJson (doc, strBuffer, strLen);
54  DEBUG_WARN ("Data: %s", strBuffer);
55  free (strBuffer);
56 
57  // Check cmd field on JSON data
58  if (!doc.containsKey (commandKey)) {
59  DEBUG_WARN ("Wrong format");
60  return false;
61  }
62 
64  if (!strcmp (doc[commandKey], relayKey)) {
65  DEBUG_WARN ("Request relay status. Relay = %s", config.relayStatus == ON ? "ON" : "OFF");
66  if (!sendRelayStatus ()) {
67  DEBUG_WARN ("Error sending relay status");
68  return false;
69  }
70  } else if (!strcmp (doc[commandKey], linkKey)) {
71  DEBUG_WARN ("Request link status. Link = %s", config.linked ? "enabled" : "disabled");
72  if (!sendLinkStatus ()) {
73  DEBUG_WARN ("Error sending link status");
74  return false;
75  }
76 
77  } else if (!strcmp (doc[commandKey], bootStateKey)) {
78  DEBUG_WARN ("Request boot status configuration. Boot = %d",
79  config.bootStatus);
80  if (!sendBootStatus ()) {
81  DEBUG_WARN ("Error sending boot status configuration");
82  return false;
83  }
84 
85  }
86  }
87 
89  if (!strcmp (doc[commandKey], relayKey)) {
90  if (!doc.containsKey (relayKey)) {
91  DEBUG_WARN ("Wrong format");
92  return false;
93  }
94  //DEBUG_WARN ("Set relay status. Relay = %s", doc[relayKey].as<bool> () ? "ON" : "OFF");
95 
96  setRelay (doc[relayKey].as<bool> ());
97 
98  if (!sendRelayStatus ()) {
99  DEBUG_WARN ("Error sending relay status");
100  return false;
101  }
102 
103 
104  } else if (!strcmp (doc[commandKey], linkKey)) {
105  if (!doc.containsKey (linkKey)) {
106  DEBUG_WARN ("Wrong format");
107  return false;
108  }
109  DEBUG_WARN ("Set link status. Link = %s", doc[linkKey].as<bool> () ? "enabled" : "disabled");
110 
111  setLinked (doc[linkKey].as<bool> ());
112 
113  if (!sendLinkStatus ()) {
114  DEBUG_WARN ("Error sending link status");
115  return false;
116  }
117 
118  } else if (!strcmp (doc[commandKey], bootStateKey)) {
119  if (!doc.containsKey (bootStateKey)) {
120  DEBUG_WARN ("Wrong format");
121  return false;
122  }
123  DEBUG_WARN ("Set boot status. Link = %d", doc[bootStateKey].as<int> ());
124 
125  setBoot (doc[bootStateKey].as<int> ());
126 
127  if (!sendBootStatus ()) {
128  DEBUG_WARN ("Error sending boot status configuration");
129  return false;
130  }
131 
132  }
133  }
134 
135  return true;
136 }
137 
139  const size_t capacity = JSON_OBJECT_SIZE (6);
140  DynamicJsonDocument json (capacity);
141 
142  json[commandKey] = relayKey;
143  json[relayKey] = config.relayStatus ? 1 : 0;
144  json[linkKey] = config.linked ? 1 : 0;
145  json[bootStateKey] = config.bootStatus;
146 
147  return sendJson (json);
148 }
149 
151  const size_t capacity = JSON_OBJECT_SIZE (2);
152  DynamicJsonDocument json (capacity);
153 
154  json[commandKey] = linkKey;
155  json[linkKey] = config.linked ? 1 : 0;
156 
157  return sendJson (json);
158 }
159 
161  const size_t capacity = JSON_OBJECT_SIZE (2);
162  DynamicJsonDocument json (capacity);
163 
164  json[commandKey] = bootStateKey;
165  int bootStatus = config.bootStatus;
166  json[bootStateKey] = bootStatus;
167 
168  return sendJson (json);
169 }
170 
171 bool CONTROLLER_CLASS_NAME::sendCommandResp (const char* command, bool result) {
172  // Respond to command with a result: true if successful, false if failed
173  return true;
174 }
175 
177 
178 #if SUPPORT_HA_DISCOVERY
179  // Register every HAEntity discovery function here. As many as you need
180  addHACall (std::bind (&CONTROLLER_CLASS_NAME::buildHASwitchDiscovery, this));
181  addHACall (std::bind (&CONTROLLER_CLASS_NAME::buildHATriggerDiscovery, this));
182  addHACall (std::bind (&CONTROLLER_CLASS_NAME::buildHALinkDiscovery, this));
183 #endif
184 
186 }
187 
189  enigmaIotNode = node;
190 
191  // You do node setup here. Use it as it was the normal setup() Arduino function
192  pinMode (config.buttonPin, INPUT_PULLUP);
193  pinMode (config.relayPin, OUTPUT);
194 
195  if (config.bootStatus != SAVE_RELAY_STATUS) {
196  config.relayStatus = (bool)config.bootStatus;
197  DEBUG_WARN ("Relay status set to Boot Status %d -> %d", config.bootStatus, config.relayStatus);
198  }
199  DEBUG_WARN ("Relay status set to %s", config.relayStatus ? "ON" : "OFF");
200  digitalWrite (config.relayPin, config.relayStatus);
201  // if (!sendRelayStatus ()) {
202  // DEBUG_WARN ("Error sending relay status");
203  // }
204 
205  // Send a 'hello' message when initalizing is finished
206  sendStartAnouncement ();
207 
208  DEBUG_WARN ("Finish begin");
209 
210  // If your node should sleep after sending data do all remaining tasks here
211 }
212 
214  DEBUG_INFO ("Toggle relay");
215  config.relayStatus = !config.relayStatus;
216  digitalWrite (config.relayPin, config.relayStatus ? ON : OFF);
217  if (config.bootStatus == SAVE_RELAY_STATUS) {
218  if (saveConfig ()) {
219  DEBUG_INFO ("Config updated. Relay is %s", config.relayStatus ? "ON" : "OFF");
220  } else {
221  DEBUG_ERROR ("Error saving config");
222  }
223  }
224  sendRelayStatus ();
225 }
226 
228  DEBUG_WARN ("Set relay %s", state ? "ON" : "OFF");
229  config.relayStatus = state;
230  digitalWrite (config.relayPin, config.relayStatus ? ON : OFF);
231  if (config.bootStatus == SAVE_RELAY_STATUS) {
232  if (saveConfig ()) {
233  DEBUG_WARN ("Config updated. Relay is %s", config.relayStatus ? "ON" : "OFF");
234  } else {
235  DEBUG_ERROR ("Error saving config");
236  }
237  }
238 }
239 
241  DEBUG_WARN ("Set link %s", state ? "ON" : "OFF");
242  config.linked = state;
243  if (saveConfig ()) {
244  DEBUG_WARN ("Config updated. Relay is %slinked", !config.relayStatus ? "not " : "");
245  } else {
246  DEBUG_ERROR ("Error saving config");
247  }
248 }
249 
251  DEBUG_WARN ("Set boot state to %d", state);
252  if (state >= RELAY_OFF && state <= SAVE_RELAY_STATUS) {
253  config.bootStatus = (bootRelayStatus_t)state;
254  } else {
255  config.bootStatus = RELAY_OFF;
256  }
257 
258  if (saveConfig ()) {
259  DEBUG_WARN ("Config updated");
260  } else {
261  DEBUG_ERROR ("Error saving config");
262  }
263 }
264 
266 
267  // If your node stays allways awake do your periodic task here
268  if (pushReleased) { // Enter this only if button were not pushed in the last loop
269  if (!digitalRead (config.buttonPin)) {
270  delay (50); // debounce button push
271  if (!digitalRead (config.buttonPin)) {
272  DEBUG_INFO ("Button triggered!");
273  pushTriggered = true; // Button is pushed
274  pushReleased = false; // Mark button as not released
275  }
276  }
277  }
278 
279  if (pushTriggered) { // If button was pushed
280  pushTriggered = false; // Disable push trigger
281  const size_t capacity = JSON_OBJECT_SIZE (2);
282  DynamicJsonDocument json (capacity);
283  json[buttonKey] = config.buttonPin;
284  json["push"] = 1;
285  if (sendJson (json)) {
286  DEBUG_INFO ("Push triggered sent");
287  } else {
288  DEBUG_ERROR ("Push send error");
289  }
290  if (config.linked) {
291  toggleRelay ();
292  }
293  }
294 
295  if (!pushReleased) {
296  if (digitalRead (config.buttonPin)) { // If button is released
297  DEBUG_INFO ("Button released");
298  pushReleased = true;
299  }
300  }
301 
302  static clock_t lastSentStatus;
303  static clock_t sendStatusPeriod = 2000;
304  if (enigmaIotNode->isRegistered () && millis () - lastSentStatus > sendStatusPeriod) {
305  lastSentStatus = millis ();
306  sendStatusPeriod = 300000;
307  sendRelayStatus ();
308  }
309 }
310 
312  // It your class uses dynamic data free it up here
313  // This is normally not needed but it is a good practice
314  if (buttonPinParam) {
315  delete (buttonPinParam);
316  delete (relayPinParam);
317  delete (bootStatusListParam);
318  delete (bootStatusParam);
319  }
320 }
321 
323  DEBUG_WARN ("==== CCost Controller Configuration start ====");
324  // If you need to add custom configuration parameters do it here
325 
326  static char buttonPinParamStr[4];
327  itoa (DEFAULT_BUTTON_PIN, buttonPinParamStr, 10);
328  static char relayPinParamStr[4];
329  itoa (DEFAULT_RELAY_PIN, relayPinParamStr, 10);
330  buttonPinParam = new AsyncWiFiManagerParameter ("buttonPin", "Button Pin", buttonPinParamStr, 3, "required type=\"text\" pattern=\"^1[2-5]$|^[0-5]$\"");
331  relayPinParam = new AsyncWiFiManagerParameter ("relayPin", "Relay Pin", relayPinParamStr, 3, "required type=\"text\" pattern=\"^1[2-5]$|^[0-5]$\"");
332  bootStatusParam = new AsyncWiFiManagerParameter ("bootStatus", "Boot Relay Status", "", 6, "required type=\"text\" list=\"bootStatusList\" pattern=\"^ON$|^OFF$|^SAVE$\"");
333  bootStatusListParam = new AsyncWiFiManagerParameter ("<datalist id=\"bootStatusList\">" \
334  "<option value = \"OFF\" >" \
335  "<option valsenue = \"OFF\" >" \
336  "<option value = \"ON\">" \
337  "<option value = \"SAVE\">" \
338  "</datalist>");
339  EnigmaIOTNode.addWiFiManagerParameter (buttonPinParam);
340  EnigmaIOTNode.addWiFiManagerParameter (relayPinParam);
341  EnigmaIOTNode.addWiFiManagerParameter (bootStatusListParam);
342  EnigmaIOTNode.addWiFiManagerParameter (bootStatusParam);
343 }
344 
346  DEBUG_WARN ("==== CCost Controller Configuration result ====");
347  // You can read configuration paramenter values here
348  DEBUG_WARN ("Button Pin: %s", buttonPinParam->getValue ());
349  DEBUG_WARN ("Boot Relay Status: %s", bootStatusParam->getValue ());
350 
351  // TODO: Finish bootStatusParam analysis
352 
353  if (status) {
354  config.buttonPin = atoi (buttonPinParam->getValue ());
355  if (config.buttonPin > 15 || config.buttonPin < 0) {
356  config.buttonPin = DEFAULT_BUTTON_PIN;
357  }
358  config.relayPin = atoi (relayPinParam->getValue ());
359  if (config.relayPin > 15 || config.relayPin < 0) {
360  config.relayPin = DEFAULT_BUTTON_PIN;
361  }
362  if (!strncmp (bootStatusParam->getValue (), "ON", 6)) {
363  config.bootStatus = RELAY_ON;
364  } else if (!strncmp (bootStatusParam->getValue (), "SAVE", 6)) {
365  config.bootStatus = SAVE_RELAY_STATUS;
366  } else {
367  config.bootStatus = RELAY_OFF;
368  }
369  config.ON_STATE = ON;
370  config.linked = true;
371 
372  if (!saveConfig ()) {
373  DEBUG_ERROR ("Error writting blind controller config to filesystem.");
374  } else {
375  DEBUG_WARN ("Configuration stored");
376  }
377  } else {
378  DEBUG_WARN ("Configuration does not need to be saved");
379  }
380 }
381 
383  config.buttonPin = DEFAULT_BUTTON_PIN;
384  config.relayPin = DEFAULT_RELAY_PIN;
385  config.linked = true;
386  config.ON_STATE = ON;
387 
388 }
389 
391  // If you need to read custom configuration data do it here
392  bool json_correct = false;
393 
394  if (!FILESYSTEM.begin ()) {
395  DEBUG_WARN ("Error starting filesystem. Formatting");
396  FILESYSTEM.format ();
397  }
398 
399  // FILESYSTEM.remove (CONFIG_FILE); // Only for testing
400 
401  if (FILESYSTEM.exists (CONFIG_FILE)) {
402  DEBUG_WARN ("Opening %s file", CONFIG_FILE);
403  File configFile = FILESYSTEM.open (CONFIG_FILE, "r");
404  if (configFile) {
405  size_t size = configFile.size ();
406  DEBUG_WARN ("%s opened. %u bytes", CONFIG_FILE, size);
407  DynamicJsonDocument doc (512);
408  DeserializationError error = deserializeJson (doc, configFile);
409  if (error) {
410  DEBUG_ERROR ("Failed to parse file");
411  } else {
412  DEBUG_WARN ("JSON file parsed");
413  }
414 
415  if (doc.containsKey ("buttonPin") &&
416  doc.containsKey ("relayPin") &&
417  doc.containsKey ("linked") &&
418  doc.containsKey ("ON_STATE") &&
419  doc.containsKey ("bootStatus")) {
420 
421  json_correct = true;
422  config.buttonPin = doc["buttonPin"].as<int> ();
423  config.relayPin = doc["relayPin"].as<int> ();
424  config.linked = doc["linked"].as<bool> ();
425  config.ON_STATE = doc["ON_STATE"].as<int> ();
426  int bootStatus = doc["bootStatus"].as<int> ();
427  if (bootStatus >= RELAY_OFF && bootStatus <= SAVE_RELAY_STATUS) {
428  config.bootStatus = (bootRelayStatus_t)bootStatus;
429  DEBUG_WARN ("Boot status set to %d", config.bootStatus);
430  } else {
431  config.bootStatus = RELAY_OFF;
432  }
433  }
434 
435  if (doc.containsKey ("relayStatus")) {
436  config.relayStatus = doc["relayStatus"].as<bool> ();
437  }
438 
439  configFile.close ();
440  if (json_correct) {
441  DEBUG_WARN ("Smart switch controller configuration successfuly read");
442  } else {
443  DEBUG_WARN ("Smart switch controller configuration error");
444  }
445  DEBUG_WARN ("==== Smart switch Controller Configuration ====");
446  DEBUG_WARN ("Button pin: %d", config.buttonPin);
447  DEBUG_WARN ("Relay pin: %d", config.relayPin);
448  DEBUG_WARN ("Linked: %s", config.linked ? "true" : "false");
449  DEBUG_WARN ("ON level: %s ", config.ON_STATE ? "HIGH" : "LOW");
450  DEBUG_WARN ("Boot relay status: %d ", config.bootStatus);
451 
452 
453  size_t jsonLen = measureJsonPretty (doc) + 1;
454  char* output = (char*)malloc (jsonLen);
455  serializeJsonPretty (doc, output, jsonLen);
456 
457  DEBUG_WARN ("File content:\n%s", output);
458 
459  free (output);
460 
461  } else {
462  DEBUG_WARN ("Error opening %s", CONFIG_FILE);
463  defaultConfig ();
464  }
465  } else {
466  DEBUG_WARN ("%s do not exist", CONFIG_FILE);
467  defaultConfig ();
468  }
469 
470  return json_correct;
471 }
472 
474  // If you need to save custom configuration data do it here
475  if (!FILESYSTEM.begin ()) {
476  DEBUG_WARN ("Error opening filesystem");
477  return false;
478  }
479  DEBUG_INFO ("Filesystem opened");
480 
481  File configFile = FILESYSTEM.open (CONFIG_FILE, "w");
482  if (!configFile) {
483  DEBUG_WARN ("Failed to open config file %s for writing", CONFIG_FILE);
484  return false;
485  } else {
486  DEBUG_INFO ("%s opened for writting", CONFIG_FILE);
487  }
488 
489  DynamicJsonDocument doc (512);
490 
491  doc["buttonPin"] = config.buttonPin;
492  doc["relayPin"] = config.relayPin;
493  doc["linked"] = config.linked;
494  doc["ON_STATE"] = config.ON_STATE;
495  doc["relayStatus"] = config.relayStatus;
496  int bootStatus = config.bootStatus;
497  doc["bootStatus"] = bootStatus;
498 
499  if (serializeJson (doc, configFile) == 0) {
500  DEBUG_ERROR ("Failed to write to file");
501  configFile.close ();
502  //FILESYSTEM.remove (CONFIG_FILE);
503  return false;
504  }
505 
506  size_t jsonLen = measureJsonPretty (doc) + 1;
507  char* output = (char*)malloc (jsonLen);
508  serializeJsonPretty (doc, output, jsonLen);
509 
510  DEBUG_DBG ("File content:\n%s", output);
511 
512  free (output);
513 
514  configFile.flush ();
515  size_t size = configFile.size ();
516 
517  //configFile.write ((uint8_t*)(&mqttgw_config), sizeof (mqttgw_config));
518  configFile.close ();
519  DEBUG_DBG ("Smart Switch controller configuration saved to flash. %u bytes", size);
520 
521  return true;
522 }
523 
524 #if SUPPORT_HA_DISCOVERY
525 // Repeat this method for every entity
527  // Select corresponding HAEntiny type
528  HASwitch* haEntity = new HASwitch ();
529 
530  uint8_t* msgPackBuffer;
531 
532  if (!haEntity) {
533  DEBUG_WARN ("JSON object instance does not exist");
534  return;
535  }
536 
537  // *******************************
538  // Add your characteristics here
539  // There is no need to futher modify this function
540 
541  haEntity->setNameSufix ("switch");
542  haEntity->setStateOn (1);
543  haEntity->setStateOff (0);
544  haEntity->setValueField ("rly");
545  haEntity->setPayloadOff ("{\"cmd\":\"rly\",\"rly\":0}");
546  haEntity->setPayloadOn ("{\"cmd\":\"rly\",\"rly\":1}");
547  // *******************************
548 
549  size_t bufferLen = haEntity->measureMessage ();
550 
551  msgPackBuffer = (uint8_t*)malloc (bufferLen);
552 
553  size_t len = haEntity->getAnounceMessage (bufferLen, msgPackBuffer);
554 
555  DEBUG_INFO ("Resulting MSG pack length: %d", len);
556 
557  if (!sendHADiscovery (msgPackBuffer, len)) {
558  DEBUG_WARN ("Error sending HA discovery message");
559  }
560 
561  if (haEntity) {
562  delete (haEntity);
563  }
564 
565  if (msgPackBuffer) {
566  free (msgPackBuffer);
567  }
568 }
569 
571  // Select corresponding HAEntiny type
572  HASwitch* haEntity = new HASwitch ();
573 
574  uint8_t* msgPackBuffer;
575 
576  if (!haEntity) {
577  DEBUG_WARN ("JSON object instance does not exist");
578  return;
579  }
580 
581  // *******************************
582  // Add your characteristics here
583  // There is no need to futher modify this function
584 
585  haEntity->setNameSufix ("link");
586  haEntity->setStateOn (1);
587  haEntity->setStateOff (0);
588  haEntity->setValueField ("link");
589  haEntity->setPayloadOff ("{\"cmd\":\"link\",\"link\":0}");
590  haEntity->setPayloadOn ("{\"cmd\":\"link\",\"link\":1}");
591  // *******************************
592 
593  size_t bufferLen = haEntity->measureMessage ();
594 
595  msgPackBuffer = (uint8_t*)malloc (bufferLen);
596 
597  size_t len = haEntity->getAnounceMessage (bufferLen, msgPackBuffer);
598 
599  DEBUG_INFO ("Resulting MSG pack length: %d", len);
600 
601  if (!sendHADiscovery (msgPackBuffer, len)) {
602  DEBUG_WARN ("Error sending HA discovery message");
603  }
604 
605  if (haEntity) {
606  delete (haEntity);
607  }
608 
609  if (msgPackBuffer) {
610  free (msgPackBuffer);
611  }
612 }
613 
615  // Select corresponding HAEntiny type
616  HATrigger* haEntity = new HATrigger ();
617 
618  uint8_t* msgPackBuffer;
619 
620  if (!haEntity) {
621  DEBUG_WARN ("JSON object instance does not exist");
622  return;
623  }
624 
625  // *******************************
626  // Add your characteristics here
627  // There is no need to futher modify this function
628 
629  haEntity->setNameSufix ("button");
630  haEntity->setType (button_short_press);
631  haEntity->setSubtype (turn_on);
632  haEntity->setPayload ("{\"button\":4,\"push\":1}");
633  // *******************************
634 
635  size_t bufferLen = haEntity->measureMessage ();
636 
637  msgPackBuffer = (uint8_t*)malloc (bufferLen);
638 
639  size_t len = haEntity->getAnounceMessage (bufferLen, msgPackBuffer);
640 
641  DEBUG_INFO ("Resulting MSG pack length: %d", len);
642 
643  if (!sendHADiscovery (msgPackBuffer, len)) {
644  DEBUG_WARN ("Error sending HA discovery message");
645  }
646 
647  if (haEntity) {
648  delete (haEntity);
649  }
650 
651  if (msgPackBuffer) {
652  free (msgPackBuffer);
653  }
654 }
655 #endif // SUPPORT_HA_DISCOVERY
CONTROLLER_CLASS_NAME::setRelay
void setRelay(bool state)
Definition: SmartSwitchController.cpp:227
HAEntity::measureMessage
size_t measureMessage()
Gets needed buffer size for discovery message.
Definition: haEntity.h:217
HATrigger::setPayload
void setPayload(const char *payload)
Optional payload to match the payload being sent over the topic https://www.home-assistant....
Definition: haTrigger.cpp:13
relayKey
const char * relayKey
Definition: SmartSwitchController.cpp:17
nodeMessageType
nodeMessageType
Message code definition.
Definition: EnigmaIOTNode.h:35
MAX_MESSAGE_LENGTH
static const uint8_t MAX_MESSAGE_LENGTH
Maximum payload size on ESP-NOW.
Definition: EnigmaIoTconfigAdvanced.h:21
SmartSwitchController.h
CONTROLLER_CLASS_NAME::setBoot
void setBoot(int state)
Definition: SmartSwitchController.cpp:250
SAVE_RELAY_STATUS
@ SAVE_RELAY_STATUS
Definition: SmartSwitchController.h:38
HAEntity::getAnounceMessage
size_t getAnounceMessage(int bufferlen, uint8_t *buffer)
Gets entity anounce message to be sent over EnigmaIOT message.
Definition: haEntity.h:153
HATrigger::setSubtype
void setSubtype(ha_triggerSubtype_t subtype)
Set trigger subtype as ha_triggerSubtype_t https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:196
EnigmaIOTjsonController::connectInform
virtual void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
Definition: EnigmaIOTjsonController.h:81
CONTROLLER_CLASS_NAME::loop
void loop() override
This should be called periodically for module handling.
Definition: ButtonController.cpp:53
CONTROLLER_CLASS_NAME::buildHATriggerDiscovery
void buildHATriggerDiscovery()
CONTROLLER_CLASS_NAME::defaultConfig
void defaultConfig()
Definition: SmartSwitchController.cpp:382
DOWNSTREAM_DATA_GET
@ DOWNSTREAM_DATA_GET
Definition: EnigmaIOTGateway.h:44
DOWNSTREAM_DATA_SET
@ DOWNSTREAM_DATA_SET
Definition: EnigmaIOTGateway.h:42
CONTROLLER_CLASS_NAME::configManagerStart
void configManagerStart() override
Called when wifi manager starts config portal.
Definition: ButtonController.cpp:103
HASwitch::setStateOn
void setStateOn(const char *payload)
The payload that represents the on state. Used when value that represents on state in the state_topic...
Definition: haSwitch.cpp:34
linkKey
const char * linkKey
Definition: SmartSwitchController.cpp:20
EnigmaIOTNode
EnigmaIOTNodeClass EnigmaIOTNode
Definition: EnigmaIOTNode.cpp:2719
CONTROLLER_CLASS_NAME::~CONTROLLER_CLASS_NAME
~CONTROLLER_CLASS_NAME()
Definition: ButtonController.cpp:98
RELAY_ON
@ RELAY_ON
Definition: SmartSwitchController.h:37
CONTROLLER_CLASS_NAME::sendRelayStatus
bool sendRelayStatus()
Definition: SmartSwitchController.cpp:138
DEFAULT_RELAY_PIN
#define DEFAULT_RELAY_PIN
Definition: SmartSwitchController.h:31
HASwitch
Definition: haSwitch.h:94
nodePayloadEncoding_t
nodePayloadEncoding_t
Definition: EnigmaIOTNode.h:58
HASwitch::setStateOff
void setStateOff(const char *payload)
The payload that represents the off state. Used when value that represents off state in the state_top...
Definition: haSwitch.cpp:40
ON
#define ON
Definition: SmartSwitchController.h:32
CONTROLLER_CLASS_NAME::buildHALinkDiscovery
void buildHALinkDiscovery()
HASwitch::setPayloadOff
void setPayloadOff(const char *payload)
The payload that represents off state. If specified, will be used for both comparing to the value in ...
Definition: haSwitch.cpp:20
OFF
#define OFF
Definition: SmartSwitchController.h:33
EnigmaIOTNodeClass::addWiFiManagerParameter
void addWiFiManagerParameter(AsyncWiFiManagerParameter *p)
Adds a parameter to configuration portal.
Definition: EnigmaIOTNode.h:735
commandKey
const char * commandKey
Definition: SmartSwitchController.cpp:18
bootStateKey
const char * bootStateKey
Definition: SmartSwitchController.cpp:21
RELAY_OFF
@ RELAY_OFF
Definition: SmartSwitchController.h:36
CONTROLLER_CLASS_NAME::saveConfig
bool saveConfig() override
Saves output module configuration.
Definition: ButtonController.cpp:119
MSG_PACK
@ MSG_PACK
Definition: EnigmaIOTGateway.h:65
buttonKey
const char * buttonKey
Definition: SmartSwitchController.cpp:19
bootRelayStatus_t
bootRelayStatus_t
Definition: SmartSwitchController.h:35
CONTROLLER_CLASS_NAME::connectInform
void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
Definition: ButtonController.cpp:31
turn_on
@ turn_on
Definition: haTrigger.h:105
button_short_press
@ button_short_press
Definition: haTrigger.h:83
data
@ data
Definition: GwOutput_generic.h:23
CONTROLLER_CLASS_NAME::sendCommandResp
bool sendCommandResp(const char *command, bool result) override
Sends command processing response acknowledge.
Definition: ButtonController.cpp:26
CONTROLLER_CLASS_NAME::sendBootStatus
bool sendBootStatus()
Definition: SmartSwitchController.cpp:160
HATrigger
Definition: haTrigger.h:126
CONTROLLER_CLASS_NAME::buildHASwitchDiscovery
void buildHASwitchDiscovery()
Sends a HA discovery message for a single entity. Add as many functions like this as number of entiti...
CONTROLLER_CLASS_NAME::configManagerExit
void configManagerExit(bool status) override
Called when wifi manager exits config portal.
Definition: ButtonController.cpp:109
EnigmaIOTNodeClass
Main node class. Manages communication with gateway and allows sending and receiving user data.
Definition: EnigmaIOTNode.h:134
HAEntity::setNameSufix
void setNameSufix(const char *payload)
Sets name suffix. Used for multi entity nodes.
Definition: haEntity.h:200
HASwitch::setPayloadOn
void setPayloadOn(const char *payload)
The payload that represents on state. If specified, will be used for both comparing to the value in t...
Definition: haSwitch.cpp:14
CONTROLLER_CLASS_NAME::setup
void setup(EnigmaIOTNodeClass *node, void *data=NULL)
Initialize data structures.
Definition: ButtonController.cpp:40
CONTROLLER_CLASS_NAME::setLinked
void setLinked(bool state)
Definition: SmartSwitchController.cpp:240
CONTROLLER_CLASS_NAME::sendLinkStatus
bool sendLinkStatus()
Definition: SmartSwitchController.cpp:150
HASwitch::setValueField
void setValueField(const char *payload)
Defines a json key to extract device’s state from the state_topic. To determine the switches’s state ...
Definition: haSwitch.cpp:54
CONTROLLER_CLASS_NAME::processRxCommand
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.
Definition: ButtonController.cpp:19
CONTROLLER_CLASS_NAME::loadConfig
bool loadConfig() override
Loads output module configuration.
Definition: ButtonController.cpp:114
CONTROLLER_CLASS_NAME::toggleRelay
void toggleRelay()
Definition: SmartSwitchController.cpp:213
DEFAULT_BUTTON_PIN
#define DEFAULT_BUTTON_PIN
Definition: SmartSwitchController.h:30
CONFIG_FILE
constexpr auto CONFIG_FILE
Custom configuration file name.
Definition: SmartSwitchController.cpp:11
status
@ status
Definition: GwOutput_generic.h:25
HATrigger::setType
void setType(ha_triggerType_t type)
Set trigger type as ha_triggerType_t https://www.home-assistant.io/integrations/device_trigger....
Definition: haTrigger.h:178