EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
ButtonController.h
Go to the documentation of this file.
1 // BasicController.h
2 
3 #ifndef _BUTTONCONTROLLER_h
4 #define _BUTTONCONTROLLER_h
5 
6 #if defined(ARDUINO) && ARDUINO >= 100
7 #include "Arduino.h"
8 #else
9 #include "WProgram.h"
10 #endif
11 
12 #ifdef ESP32
13 #include <SPIFFS.h>
14 #endif
15 
17 #include "haTrigger.h"
18 
19 // --------------------------------------------------
20 // You may define data structures and constants here
21 // --------------------------------------------------
22 #define BUTTON_PIN 4
23 
24 #define CONTROLLER_CLASS_NAME ButtonController
25 static const char* CONTROLLER_NAME = "Button controller";
26 
28 protected:
29  // --------------------------------------------------
30  // add all parameters that your project needs here
31  // --------------------------------------------------
32  bool pushTriggered = false;
33  bool pushReleased = true;
34 
35 public:
36  void setup (EnigmaIOTNodeClass* node, void* data = NULL);
37 
38  bool processRxCommand (const uint8_t* address, const uint8_t* buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding) override;
39 
40  void loop () override;
41 
43 
47  void configManagerStart () override;
48 
53  void configManagerExit (bool status) override;
54 
59  bool loadConfig () override;
60 
61  void connectInform ();
62 
63 protected:
68  bool saveConfig () override;
69 
70  bool sendCommandResp (const char* command, bool result) override;
71 
72  bool sendStartAnouncement () override {
73  // You can send a 'hello' message when your node starts. Useful to detect unexpected reboot
74  const size_t capacity = JSON_OBJECT_SIZE (10);
75  DynamicJsonDocument json (capacity);
76  json["status"] = "start";
77  json["device"] = CONTROLLER_NAME;
78  char version_buf[10];
79  snprintf (version_buf, 10, "%d.%d.%d",
81  json["version"] = String (version_buf);
82 
83  return sendJson (json);
84  }
85 
86  void buildHADiscovery ();
87 
88  // ------------------------------------------------------------
89  // You may add additional method definitions that you need here
90  // ------------------------------------------------------------
91 };
92 
93 #endif
94 
nodeMessageType
nodeMessageType
Message code definition.
Definition: EnigmaIOTNode.h:35
CONTROLLER_NAME
static const char * CONTROLLER_NAME
Definition: ButtonController.h:25
CONTROLLER_CLASS_NAME::loop
void loop() override
This should be called periodically for module handling.
Definition: ButtonController.cpp:53
ENIGMAIOT_PROT_VERS
static const uint8_t ENIGMAIOT_PROT_VERS[3]
EnitmaIoT Version.
Definition: EnigmaIoTconfig.h:16
CONTROLLER_CLASS_NAME::buildHADiscovery
void buildHADiscovery()
Definition: ButtonController.cpp:124
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::pushTriggered
bool pushTriggered
Definition: ButtonController.h:32
CONTROLLER_CLASS_NAME::configManagerStart
void configManagerStart() override
Called when wifi manager starts config portal.
Definition: ButtonController.cpp:103
CONTROLLER_CLASS_NAME::pushReleased
bool pushReleased
Definition: ButtonController.h:33
CONTROLLER_CLASS_NAME::~CONTROLLER_CLASS_NAME
~CONTROLLER_CLASS_NAME()
Definition: ButtonController.cpp:98
nodePayloadEncoding_t
nodePayloadEncoding_t
Definition: EnigmaIOTNode.h:58
CONTROLLER_CLASS_NAME::sendStartAnouncement
bool sendStartAnouncement() override
Send a message to notify node has started running.
Definition: ButtonController.h:72
CONTROLLER_CLASS_NAME::saveConfig
bool saveConfig() override
Saves output module configuration.
Definition: ButtonController.cpp:119
haTrigger.h
Home Assistant trigger integration.
CONTROLLER_CLASS_NAME::connectInform
void connectInform()
Used to notify controller that it is registered on EnigmaIOT network.
Definition: ButtonController.cpp:31
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::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
CONTROLLER_CLASS_NAME::setup
void setup(EnigmaIOTNodeClass *node, void *data=NULL)
Initialize data structures.
Definition: ButtonController.cpp:40
EnigmaIOTjsonController.h
Prototype for JSON/MSGPACK based controller node.
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
status
@ status
Definition: GwOutput_generic.h:25
EnigmaIOTjsonController
Definition: EnigmaIOTjsonController.h:34