EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
ds18b20Controller.h
Go to the documentation of this file.
1 // BasicController.h
2 
3 #ifndef _DS18B20CONTROLLER_h
4 #define _DS18B20CONTROLLER_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 ds18b20Controller
20 static const char* CONTROLLER_NAME = "DS18B20 controller";
21 
22 #if SUPPORT_HA_DISCOVERY
23 #include <haSensor.h>
24 #endif
25 
26 // --------------------------------------------------
27 // You may define data structures and constants here
28 // --------------------------------------------------
29 #include <DallasTemperature.h>
30 
31 
33 protected:
34  // --------------------------------------------------
35  // add all parameters that your project needs here
36  // --------------------------------------------------
37  OneWire* oneWire;
38  DallasTemperature* sensors;
39  DeviceAddress insideThermometer;
40  bool tempSent = false;
41  float tempC;
42 
43 public:
44  void setup (EnigmaIOTNodeClass* node, void* data = NULL);
45 
46  bool processRxCommand (const uint8_t* address, const uint8_t* buffer, uint8_t length, nodeMessageType_t command, nodePayloadEncoding_t payloadEncoding);
47 
48  void loop ();
49 
51 
57 
63 
68  bool loadConfig ();
69 
70  void connectInform ();
71 
72 protected:
77  bool saveConfig ();
78 
79  bool sendCommandResp (const char* command, bool result);
80 
82  // You can send a 'hello' message when your node starts. Useful to detect unexpected reboot
83  const size_t capacity = JSON_OBJECT_SIZE (10);
84  DynamicJsonDocument json (capacity);
85  json["status"] = "start";
86  json["device"] = CONTROLLER_NAME;
87  char version_buf[10];
88  snprintf (version_buf, 10, "%d.%d.%d",
90  json["version"] = String (version_buf);
91 
92  return sendJson (json);
93  }
94 
95 #if SUPPORT_HA_DISCOVERY
96 
100  void buildHADiscovery ();
101 #endif
102 
103  // ------------------------------------------------------------
104  // You may add additional method definitions that you need here
105  // ------------------------------------------------------------
106 
107  bool sendTemperature (float temp);
108 
109 };
110 
111 #endif
112 
CONTROLLER_CLASS_NAME::oneWire
OneWire * oneWire
Definition: ds18b20Controller.h:37
CONTROLLER_CLASS_NAME::configManagerStart
void configManagerStart()
Called when wifi manager starts config portal.
nodeMessageType
nodeMessageType
Message code definition.
Definition: EnigmaIOTNode.h:35
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::tempC
float tempC
Definition: ds18b20Controller.h:41
CONTROLLER_CLASS_NAME::saveConfig
bool saveConfig()
Saves output module configuration.
CONTROLLER_NAME
static const char * CONTROLLER_NAME
Definition: ds18b20Controller.h:20
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::tempSent
bool tempSent
Definition: ds18b20Controller.h:40
CONTROLLER_CLASS_NAME::sendCommandResp
bool sendCommandResp(const char *command, bool result)
Sends command processing response acknowledge.
haSensor.h
Home Assistant sensor integration.
CONTROLLER_CLASS_NAME::~CONTROLLER_CLASS_NAME
~CONTROLLER_CLASS_NAME()
nodePayloadEncoding_t
nodePayloadEncoding_t
Definition: EnigmaIOTNode.h:58
CONTROLLER_CLASS_NAME::insideThermometer
DeviceAddress insideThermometer
Definition: ds18b20Controller.h:39
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: ds18b20Controller.h:81
CONTROLLER_CLASS_NAME::sendTemperature
bool sendTemperature(float temp)
Definition: ds18b20Controller.cpp:35
CONTROLLER_CLASS_NAME::sensors
DallasTemperature * sensors
Definition: ds18b20Controller.h:38
status
@ status
Definition: GwOutput_generic.h:25
CONTROLLER_CLASS_NAME::loadConfig
bool loadConfig()
Loads output module configuration.
EnigmaIOTjsonController
Definition: EnigmaIOTjsonController.h:34