mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
merged in Dallas changes from JewelZB
This commit is contained in:
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- system command to show ESP stats
|
- system command to show ESP stats
|
||||||
- crash command to see stack of last system crash, with .py files to track stack dump
|
- crash command to see stack of last system crash, with .py files to track stack dump
|
||||||
|
- publish dallas external temp sensors to MQTT (Thanks @JewelZB)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
13
src/ds18.cpp
13
src/ds18.cpp
@@ -25,10 +25,11 @@ DS18::~DS18() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
uint8_t DS18::setup(uint8_t gpio) {
|
uint8_t DS18::setup(uint8_t gpio, bool parasite) {
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
|
|
||||||
_gpio = gpio;
|
_gpio = gpio;
|
||||||
|
_parasite = (parasite ? 1 : 0);
|
||||||
|
|
||||||
// OneWire
|
// OneWire
|
||||||
if (_wire)
|
if (_wire)
|
||||||
@@ -62,8 +63,7 @@ void DS18::loop() {
|
|||||||
// Start conversion
|
// Start conversion
|
||||||
_wire->reset();
|
_wire->reset();
|
||||||
_wire->skip();
|
_wire->skip();
|
||||||
_wire->write(DS18_CMD_START_CONVERSION, DS18_PARASITE);
|
_wire->write(DS18_CMD_START_CONVERSION, _parasite);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Read scratchpads
|
// Read scratchpads
|
||||||
for (unsigned char index = 0; index < _devices.size(); index++) {
|
for (unsigned char index = 0; index < _devices.size(); index++) {
|
||||||
@@ -161,7 +161,7 @@ double DS18::getValue(unsigned char index) {
|
|||||||
uint8_t * data = _devices[index].data;
|
uint8_t * data = _devices[index].data;
|
||||||
|
|
||||||
if (OneWire::crc8(data, DS18_DATA_SIZE - 1) != data[DS18_DATA_SIZE - 1]) {
|
if (OneWire::crc8(data, DS18_DATA_SIZE - 1) != data[DS18_DATA_SIZE - 1]) {
|
||||||
return 0;
|
return DS18_CRC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t raw = (data[1] << 8) | data[0];
|
int16_t raw = (data[1] << 8) | data[0];
|
||||||
@@ -182,9 +182,6 @@ double DS18::getValue(unsigned char index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double value = (float)raw / 16.0;
|
double value = (float)raw / 16.0;
|
||||||
if (value == DS18_DISCONNECTED) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
#define DS18_CHIP_DS1825 0x3B
|
#define DS18_CHIP_DS1825 0x3B
|
||||||
|
|
||||||
#define DS18_DATA_SIZE 9
|
#define DS18_DATA_SIZE 9
|
||||||
#define DS18_PARASITE 1
|
|
||||||
#define DS18_DISCONNECTED -127
|
#define DS18_DISCONNECTED -127
|
||||||
|
#define DS18_CRC_ERROR -126
|
||||||
|
|
||||||
#define GPIO_NONE 0x99
|
#define GPIO_NONE 0x99
|
||||||
#define DS18_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
|
#define DS18_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
|
||||||
@@ -39,7 +39,7 @@ class DS18 {
|
|||||||
DS18();
|
DS18();
|
||||||
~DS18();
|
~DS18();
|
||||||
|
|
||||||
uint8_t setup(uint8_t gpio);
|
uint8_t setup(uint8_t gpio, bool parasite);
|
||||||
void loop();
|
void loop();
|
||||||
char * getDeviceString(char * s, unsigned char index);
|
char * getDeviceString(char * s, unsigned char index);
|
||||||
double getValue(unsigned char index);
|
double getValue(unsigned char index);
|
||||||
@@ -50,6 +50,7 @@ class DS18 {
|
|||||||
uint8_t loadDevices();
|
uint8_t loadDevices();
|
||||||
|
|
||||||
OneWire * _wire;
|
OneWire * _wire;
|
||||||
uint8_t _count; // # devices
|
uint8_t _count; // # devices
|
||||||
uint8_t _gpio; // the sensor pin
|
uint8_t _gpio; // the sensor pin
|
||||||
|
uint8_t _parasite; // parasite mode
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ DS18 ds18;
|
|||||||
#define PUBLISHVALUES_TIME 120 // every 2 minutes publish MQTT values
|
#define PUBLISHVALUES_TIME 120 // every 2 minutes publish MQTT values
|
||||||
Ticker publishValuesTimer;
|
Ticker publishValuesTimer;
|
||||||
|
|
||||||
|
#define PUBLISHSENSORVALUES_TIME 180 // every 3 minutes publish MQTT sensor values
|
||||||
|
Ticker publishSensorValuesTimer;
|
||||||
|
|
||||||
#define SYSTEMCHECK_TIME 20 // every 20 seconds check if Boiler is online
|
#define SYSTEMCHECK_TIME 20 // every 20 seconds check if Boiler is online
|
||||||
Ticker systemCheckTimer;
|
Ticker systemCheckTimer;
|
||||||
|
|
||||||
@@ -67,6 +70,7 @@ typedef struct {
|
|||||||
uint8_t dallas_sensors; // count of dallas sensors
|
uint8_t dallas_sensors; // count of dallas sensors
|
||||||
uint8_t led_gpio;
|
uint8_t led_gpio;
|
||||||
uint8_t dallas_gpio;
|
uint8_t dallas_gpio;
|
||||||
|
uint8_t dallas_parasite;
|
||||||
} _EMSESP_Status;
|
} _EMSESP_Status;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -414,6 +418,32 @@ void showInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send all dallas sensor values as a JSON package to MQTT
|
||||||
|
void publishSensorValues() {
|
||||||
|
StaticJsonDocument<MQTT_MAX_SIZE> doc;
|
||||||
|
bool hasdata = false;
|
||||||
|
|
||||||
|
// see if the sensor values have changed, if so send
|
||||||
|
//JsonObject & sensors = jsonBuffer.createObject();
|
||||||
|
JsonObject sensors = doc.to<JsonObject>();
|
||||||
|
for (uint8_t i = 0; i < EMSESP_Status.dallas_sensors; i++) {
|
||||||
|
double sensorValue = ds18.getValue(i);
|
||||||
|
if(sensorValue != DS18_DISCONNECTED && sensorValue != DS18_CRC_ERROR) {
|
||||||
|
char label[8] = {0};
|
||||||
|
char valuestr[8] = {0}; // for formatting temp
|
||||||
|
sprintf(label,"temp_%d",(i+1));
|
||||||
|
sensors[label] = _float_to_char(valuestr, sensorValue);
|
||||||
|
hasdata = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasdata) {
|
||||||
|
char data[MQTT_MAX_SIZE] = {0};
|
||||||
|
serializeJson(doc, data, sizeof(data));
|
||||||
|
myESP.mqttPublish(TOPIC_EXTERNAL_SENSORS, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send values via MQTT
|
// send values via MQTT
|
||||||
// a json object is created for the boiler and one for the thermostat
|
// a json object is created for the boiler and one for the thermostat
|
||||||
// CRC check is done to see if there are changes in the values since the last send to avoid too much wifi traffic
|
// CRC check is done to see if there are changes in the values since the last send to avoid too much wifi traffic
|
||||||
@@ -607,6 +637,11 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
|
|||||||
EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value
|
EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dallas_gpio
|
||||||
|
if (!(EMSESP_Status.dallas_gpio = json["dallas_parasite"])) {
|
||||||
|
EMSESP_Status.dallas_parasite = EMSESP_DALLAS_PARASITE; // default value
|
||||||
|
}
|
||||||
|
|
||||||
// thermostat_type
|
// thermostat_type
|
||||||
if (!(EMS_Thermostat.type_id = json["thermostat_type"])) {
|
if (!(EMS_Thermostat.type_id = json["thermostat_type"])) {
|
||||||
EMS_Thermostat.type_id = EMSESP_THERMOSTAT_TYPE; // set default
|
EMS_Thermostat.type_id = EMSESP_THERMOSTAT_TYPE; // set default
|
||||||
@@ -629,6 +664,7 @@ bool FSCallback(MYESP_FSACTION action, const JsonObject json) {
|
|||||||
json["led"] = EMSESP_Status.led_enabled;
|
json["led"] = EMSESP_Status.led_enabled;
|
||||||
json["led_gpio"] = EMSESP_Status.led_gpio;
|
json["led_gpio"] = EMSESP_Status.led_gpio;
|
||||||
json["dallas_gpio"] = EMSESP_Status.dallas_gpio;
|
json["dallas_gpio"] = EMSESP_Status.dallas_gpio;
|
||||||
|
json["dallas_parasite"] = EMSESP_Status.dallas_parasite;
|
||||||
json["thermostat_type"] = EMS_Thermostat.type_id;
|
json["thermostat_type"] = EMS_Thermostat.type_id;
|
||||||
json["boiler_type"] = EMS_Boiler.type_id;
|
json["boiler_type"] = EMS_Boiler.type_id;
|
||||||
json["test_mode"] = EMSESP_Status.test_mode;
|
json["test_mode"] = EMSESP_Status.test_mode;
|
||||||
@@ -686,6 +722,17 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
|
|||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dallas_parasite
|
||||||
|
if ((strcmp(setting, "dallas_parasite") == 0) && (wc == 2)) {
|
||||||
|
if (strcmp(value, "true") == 0) {
|
||||||
|
EMSESP_Status.dallas_parasite = true;
|
||||||
|
ok = true;
|
||||||
|
} else if (strcmp(value, "false") == 0) {
|
||||||
|
EMSESP_Status.dallas_parasite = false;
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// thermostat_type
|
// thermostat_type
|
||||||
if (strcmp(setting, "thermostat_type") == 0) {
|
if (strcmp(setting, "thermostat_type") == 0) {
|
||||||
EMS_Thermostat.type_id = ((wc == 2) ? (uint8_t)strtol(value, 0, 16) : EMS_ID_NONE);
|
EMS_Thermostat.type_id = ((wc == 2) ? (uint8_t)strtol(value, 0, 16) : EMS_ID_NONE);
|
||||||
@@ -704,6 +751,7 @@ bool SettingsCallback(MYESP_FSACTION action, uint8_t wc, const char * setting, c
|
|||||||
myDebug(" led=%s", EMSESP_Status.led_enabled ? "on" : "off");
|
myDebug(" led=%s", EMSESP_Status.led_enabled ? "on" : "off");
|
||||||
myDebug(" led_gpio=%d", EMSESP_Status.led_gpio);
|
myDebug(" led_gpio=%d", EMSESP_Status.led_gpio);
|
||||||
myDebug(" dallas_gpio=%d", EMSESP_Status.dallas_gpio);
|
myDebug(" dallas_gpio=%d", EMSESP_Status.dallas_gpio);
|
||||||
|
myDebug(" dallas_parasite=%s", EMSESP_Status.dallas_parasite ? "on" : "off");
|
||||||
|
|
||||||
if (EMS_Thermostat.type_id == EMS_ID_NONE) {
|
if (EMS_Thermostat.type_id == EMS_ID_NONE) {
|
||||||
myDebug(" thermostat_type=<not set>");
|
myDebug(" thermostat_type=<not set>");
|
||||||
@@ -997,6 +1045,13 @@ void initEMSESP() {
|
|||||||
EMSESP_Shower.doingColdShot = false;
|
EMSESP_Shower.doingColdShot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// publish external dallas sensor temperature values to MQTT
|
||||||
|
void do_publishSensorValues() {
|
||||||
|
if (EMSESP_Status.dallas_sensors != 0) {
|
||||||
|
publishSensorValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// call PublishValues without forcing, so using CRC to see if we really need to publish
|
// call PublishValues without forcing, so using CRC to see if we really need to publish
|
||||||
void do_publishValues() {
|
void do_publishValues() {
|
||||||
// don't publish if we're not connected to the EMS bus
|
// don't publish if we're not connected to the EMS bus
|
||||||
@@ -1177,6 +1232,7 @@ void setup() {
|
|||||||
if (!EMSESP_Status.test_mode) {
|
if (!EMSESP_Status.test_mode) {
|
||||||
publishValuesTimer.attach(PUBLISHVALUES_TIME, do_publishValues); // post MQTT values
|
publishValuesTimer.attach(PUBLISHVALUES_TIME, do_publishValues); // post MQTT values
|
||||||
regularUpdatesTimer.attach(REGULARUPDATES_TIME, do_regularUpdates); // regular reads from the EMS
|
regularUpdatesTimer.attach(REGULARUPDATES_TIME, do_regularUpdates); // regular reads from the EMS
|
||||||
|
publishSensorValuesTimer.attach(PUBLISHSENSORVALUES_TIME, do_publishSensorValues); // post MQTT sensor values
|
||||||
}
|
}
|
||||||
|
|
||||||
// set pin for LED
|
// set pin for LED
|
||||||
@@ -1187,7 +1243,8 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for Dallas sensors
|
// check for Dallas sensors
|
||||||
EMSESP_Status.dallas_sensors = ds18.setup(EMSESP_Status.dallas_gpio); // returns #sensors
|
EMSESP_Status.dallas_sensors = ds18.setup(EMSESP_Status.dallas_gpio, EMSESP_Status.dallas_parasite); // returns #sensors
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -49,6 +49,9 @@
|
|||||||
#define BOILER_SHOWER_ALERT 0 // enable (1) to send alert of cold water when shower time limit has exceeded
|
#define BOILER_SHOWER_ALERT 0 // enable (1) to send alert of cold water when shower time limit has exceeded
|
||||||
#define SHOWER_MAX_DURATION 420000 // in ms. 7 minutes, before trigger a shot of cold water
|
#define SHOWER_MAX_DURATION 420000 // in ms. 7 minutes, before trigger a shot of cold water
|
||||||
|
|
||||||
|
// MQTT for EXTERNAL SENSORS
|
||||||
|
#define TOPIC_EXTERNAL_SENSORS "sensors" // for sending sensor values to MQTT
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// THESE DEFAULT VALUES CAN ALSO BE SET AND STORED WITHTIN THE APPLICATION (see 'set' command) //
|
// THESE DEFAULT VALUES CAN ALSO BE SET AND STORED WITHTIN THE APPLICATION (see 'set' command) //
|
||||||
// ALTHOUGH YOU MAY ALSO HARDCODE THEM HERE BUT THEY WILL BE OVERWRITTEN WITH NEW RELEASE UPDATES //
|
// ALTHOUGH YOU MAY ALSO HARDCODE THEM HERE BUT THEY WILL BE OVERWRITTEN WITH NEW RELEASE UPDATES //
|
||||||
@@ -64,6 +67,7 @@
|
|||||||
// set this if using an external temperature sensor like a DS18B20
|
// set this if using an external temperature sensor like a DS18B20
|
||||||
// D5 is the default on bbqkees' board
|
// D5 is the default on bbqkees' board
|
||||||
#define EMSESP_DALLAS_GPIO D5
|
#define EMSESP_DALLAS_GPIO D5
|
||||||
|
#define EMSESP_DALLAS_PARASITE false
|
||||||
|
|
||||||
// By default the EMS bus will be scanned for known devices based on product ids in ems_devices.h
|
// By default the EMS bus will be scanned for known devices based on product ids in ems_devices.h
|
||||||
// You can override the Thermostat and Boiler types here
|
// You can override the Thermostat and Boiler types here
|
||||||
|
|||||||
Reference in New Issue
Block a user