EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
LedController.h
Go to the documentation of this file.
1 // BasicController.h
2 
3 #ifndef _BASICCONTROLLER_h
4 #define _BASICCONTROLLER_h
5 
6 #if defined(ARDUINO) && ARDUINO >= 100
7 #include "Arduino.h"
8 #else
9 #include "WProgram.h"
10 #endif
11 
12 //#define DEBUG_SERIAL
13 
14 #ifdef ESP32
15 #include <SPIFFS.h>
16 #endif
17 
19 #define CONTROLLER_CLASS_NAME LedController
20 static const char* CONTROLLER_NAME = "LED controller";
21 
22 #if SUPPORT_HA_DISCOVERY
23 #include <haSwitch.h>
24 #endif
25 
26 // --------------------------------------------------
27 // You may define data structures and constants here
28 // --------------------------------------------------
29 #define LED_PIN 2
30 #define _LED_ON LOW
31 #define _LED_OFF !_LED_ON
32 
34 protected:
35  // --------------------------------------------------
36  // add all parameters that your project needs here
37  // --------------------------------------------------
38  int led = _LED_OFF;
39 
40 public:
41  void setup (EnigmaIOTNodeClass* node, void* data = NULL);
42 
43  bool processRxCommand (const uint8_t* address, const uint8_t* buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding);
44 
45  void loop ();
46 
48 
54 
60 
65  bool loadConfig ();
66 
67  void connectInform ();
68 
69 protected:
74  bool saveConfig ();
75 
76  bool sendCommandResp (const char* command, bool result);
77 
79  // You can send a 'hello' message when your node starts. Useful to detect unexpected reboot
80  const size_t capacity = JSON_OBJECT_SIZE (10);
81  DynamicJsonDocument json (capacity);
82  json["status"] = "start";
83  json["device"] = CONTROLLER_NAME;
84  char version_buf[10];
85  snprintf (version_buf, 10, "%d.%d.%d",
87  json["version"] = String (version_buf);
88 
89  return sendJson (json);
90  }
91 
93 
94  // ------------------------------------------------------------
95  // You may add additional method definitions that you need here
96  // ------------------------------------------------------------
97 
98  bool sendLedStatus ();
99 };
100 
101 #endif
102 
CONTROLLER_CLASS_NAME::configManagerStart
void configManagerStart()
Called when wifi manager starts config portal.
nodeMessageType
nodeMessageType
Message code definition.
Definition: EnigmaIOTNode.h:35
CONTROLLER_NAME
static const char * CONTROLLER_NAME
Definition: LedController.h:20
CONTROLLER_CLASS_NAME::loop
void loop()
This should be called periodically for module handling.
ENIGMAIOT_PROT_VERS
static const uint8_t ENIGMAIOT_PROT_VERS[3]
EnitmaIoT Version.
Definition: EnigmaIoTconfig.h:16
CONTROLLER_CLASS_NAME::processRxCommand
bool processRxCommand(const uint8_t *address, const uint8_t *buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding)
Called to process a downlink command.
CONTROLLER_CLASS_NAME::saveConfig
bool saveConfig()
Saves output module configuration.
haSwitch.h
Home Assistant switch integration.
CONTROLLER_CLASS_NAME::buildHADiscovery
void buildHADiscovery()
CONTROLLER_CLASS_NAME
Definition: ButtonController.h:27
EnigmaIOTjsonController::sendJson
bool sendJson(DynamicJsonDocument &json)
Sends a JSON encoded message to lower layer.
Definition: EnigmaIOTjsonController.h:170
CONTROLLER_CLASS_NAME::sendCommandResp
bool sendCommandResp(const char *command, bool result)
Sends command processing response acknowledge.
CONTROLLER_CLASS_NAME::sendLedStatus
bool sendLedStatus()
Definition: LedController.cpp:105
CONTROLLER_CLASS_NAME::~CONTROLLER_CLASS_NAME
~CONTROLLER_CLASS_NAME()
CONTROLLER_CLASS_NAME::led
int led
Definition: LedController.h:38
nodePayloadEncoding_t
nodePayloadEncoding_t
Definition: EnigmaIOTNode.h:58
CONTROLLER_CLASS_NAME::connectInform
void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
CONTROLLER_CLASS_NAME::configManagerExit
void configManagerExit(bool status)
Called when wifi manager exits config portal.
data
@ data
Definition: GwOutput_generic.h:23
EnigmaIOTNodeClass
Main node class. Manages communication with gateway and allows sending and receiving user data.
Definition: EnigmaIOTNode.h:134
CONTROLLER_CLASS_NAME::setup
void setup(EnigmaIOTNodeClass *node, void *data=NULL)
Initialize data structures.
EnigmaIOTjsonController.h
Prototype for JSON/MSGPACK based controller node.
CONTROLLER_CLASS_NAME::sendStartAnouncement
bool sendStartAnouncement()
Send a message to notify node has started running.
Definition: LedController.h:78
_LED_OFF
#define _LED_OFF
Definition: LedController.h:31
status
@ status
Definition: GwOutput_generic.h:25
CONTROLLER_CLASS_NAME::loadConfig
bool loadConfig()
Loads output module configuration.
EnigmaIOTjsonController
Definition: EnigmaIOTjsonController.h:34