mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
included showing detection of external temperature sensors in startup and 'autodetect' also re-checks for new external sensors. #238
This commit is contained in:
20
src/ds18.cpp
20
src/ds18.cpp
@@ -18,23 +18,30 @@ DS18::DS18() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DS18::~DS18() {
|
DS18::~DS18() {
|
||||||
if (_wire)
|
if (_wire) {
|
||||||
delete _wire;
|
delete _wire;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
uint8_t DS18::setup(uint8_t gpio, bool parasite) {
|
void DS18::setup(uint8_t gpio, bool parasite) {
|
||||||
uint8_t count;
|
|
||||||
|
|
||||||
_gpio = gpio;
|
_gpio = gpio;
|
||||||
_parasite = (parasite ? 1 : 0);
|
_parasite = (parasite ? 1 : 0);
|
||||||
|
|
||||||
// OneWire
|
// OneWire
|
||||||
if (_wire)
|
if (_wire) {
|
||||||
delete _wire;
|
delete _wire;
|
||||||
|
}
|
||||||
_wire = new OneWire(_gpio);
|
_wire = new OneWire(_gpio);
|
||||||
|
}
|
||||||
|
|
||||||
// Search devices
|
// clear list and scan for devices
|
||||||
|
uint8_t DS18::scan() {
|
||||||
|
_devices.clear();
|
||||||
|
|
||||||
|
uint8_t count;
|
||||||
|
|
||||||
|
// start the search
|
||||||
count = loadDevices();
|
count = loadDevices();
|
||||||
|
|
||||||
// If no devices found check again pulling up the line
|
// If no devices found check again pulling up the line
|
||||||
@@ -48,6 +55,7 @@ uint8_t DS18::setup(uint8_t gpio, bool parasite) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scan every 2 seconds
|
// scan every 2 seconds
|
||||||
void DS18::loop() {
|
void DS18::loop() {
|
||||||
static uint32_t last = 0;
|
static uint32_t last = 0;
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class DS18 {
|
|||||||
DS18();
|
DS18();
|
||||||
~DS18();
|
~DS18();
|
||||||
|
|
||||||
uint8_t setup(uint8_t gpio, bool parasite);
|
void setup(uint8_t gpio, bool parasite);
|
||||||
|
uint8_t scan();
|
||||||
void loop();
|
void loop();
|
||||||
char * getDeviceString(char * s, unsigned char index);
|
char * getDeviceString(char * s, unsigned char index);
|
||||||
float getValue(unsigned char index);
|
float getValue(unsigned char index);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ static const command_t project_cmds[] PROGMEM = {
|
|||||||
{true, "shower_alert <on | off>", "stop hot water to send 3 cold burst warnings after max shower time is exceeded"},
|
{true, "shower_alert <on | off>", "stop hot water to send 3 cold burst warnings after max shower time is exceeded"},
|
||||||
{true, "publish_time <seconds>", "set frequency for publishing data to MQTT (0=automatic)"},
|
{true, "publish_time <seconds>", "set frequency for publishing data to MQTT (0=automatic)"},
|
||||||
{true, "tx_mode <n>", "changes Tx logic. 1=EMS generic, 2=EMS+, 3=HT3"},
|
{true, "tx_mode <n>", "changes Tx logic. 1=EMS generic, 2=EMS+, 3=HT3"},
|
||||||
{true, "master_thermostat [product id]", "product id to use as the master thermostat. Use no args for list."},
|
{true, "master_thermostat [product id]", "set default thermostat to use. Omit [product id] to show options."},
|
||||||
|
|
||||||
{false, "info", "show current values deciphered from the EMS messages"},
|
{false, "info", "show current values deciphered from the EMS messages"},
|
||||||
{false, "log <n | b | t | s | r | j | v | w [type ID]", "set logging to none, basic, thermostat, solar module, raw, jabber, verbose or watch a specific type"},
|
{false, "log <n | b | t | s | r | j | v | w [type ID]", "set logging to none, basic, thermostat, solar module, raw, jabber, verbose or watch a specific type"},
|
||||||
@@ -113,7 +113,7 @@ static const command_t project_cmds[] PROGMEM = {
|
|||||||
{false, "refresh", "fetch values from the EMS devices"},
|
{false, "refresh", "fetch values from the EMS devices"},
|
||||||
{false, "devices", "list detected EMS devices"},
|
{false, "devices", "list detected EMS devices"},
|
||||||
{false, "queue", "show current Tx queue"},
|
{false, "queue", "show current Tx queue"},
|
||||||
{false, "autodetect", "detect EMS devices and attempt to automatically set boiler and thermostat types"},
|
{false, "autodetect", "scan for EMS devices and external sensors"},
|
||||||
{false, "send XX ...", "send raw telegram data to EMS bus (XX are hex values)"},
|
{false, "send XX ...", "send raw telegram data to EMS bus (XX are hex values)"},
|
||||||
{false, "thermostat read <type ID>", "send read request to the thermostat for heating circuit hc 1-4"},
|
{false, "thermostat read <type ID>", "send read request to the thermostat for heating circuit hc 1-4"},
|
||||||
{false, "thermostat temp [hc] <degrees>", "set current thermostat temperature"},
|
{false, "thermostat temp [hc] <degrees>", "set current thermostat temperature"},
|
||||||
@@ -505,6 +505,17 @@ void showInfo() {
|
|||||||
myDebug_P(PSTR("")); // newline
|
myDebug_P(PSTR("")); // newline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scan for external Dallas sensors and display
|
||||||
|
void scanDallas() {
|
||||||
|
EMSESP_Settings.dallas_sensors = ds18.scan();
|
||||||
|
if (EMSESP_Settings.dallas_sensors) {
|
||||||
|
char buffer[128] = {0};
|
||||||
|
for (uint8_t i = 0; i < EMSESP_Settings.dallas_sensors; i++) {
|
||||||
|
myDebug_P(PSTR("External temperature sensor %s found"), ds18.getDeviceString(buffer, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send all dallas sensor values as a JSON package to MQTT
|
// send all dallas sensor values as a JSON package to MQTT
|
||||||
void publishSensorValues() {
|
void publishSensorValues() {
|
||||||
// don't send if MQTT is connected
|
// don't send if MQTT is connected
|
||||||
@@ -1222,6 +1233,8 @@ void TelnetCommandCallback(uint8_t wc, const char * commandLine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(first_cmd, "autodetect") == 0) {
|
if (strcmp(first_cmd, "autodetect") == 0) {
|
||||||
|
myDebug("Scanning for new EMS devices and attached external sensors...");
|
||||||
|
scanDallas();
|
||||||
ems_clearDeviceList();
|
ems_clearDeviceList();
|
||||||
ems_doReadCommand(EMS_TYPE_UBADevices, EMS_Boiler.device_id);
|
ems_doReadCommand(EMS_TYPE_UBADevices, EMS_Boiler.device_id);
|
||||||
ok = true;
|
ok = true;
|
||||||
@@ -1457,14 +1470,18 @@ void MQTTCallback(unsigned int type, const char * topic, const char * message) {
|
|||||||
const char * shower_alert = doc[TOPIC_SHOWER_ALERT];
|
const char * shower_alert = doc[TOPIC_SHOWER_ALERT];
|
||||||
if (shower_alert) {
|
if (shower_alert) {
|
||||||
EMSESP_Settings.shower_alert = ((shower_alert[0] - MYESP_MQTT_PAYLOAD_OFF) == 1);
|
EMSESP_Settings.shower_alert = ((shower_alert[0] - MYESP_MQTT_PAYLOAD_OFF) == 1);
|
||||||
myDebug_P(PSTR("Shower alert has been set to %s"), EMSESP_Settings.shower_alert ? "enabled" : "disabled");
|
if (ems_getLogging() != EMS_SYS_LOGGING_NONE) {
|
||||||
|
myDebug_P(PSTR("Shower alert has been set to %s"), EMSESP_Settings.shower_alert ? "enabled" : "disabled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes payload is "1" or "0"
|
// assumes payload is "1" or "0"
|
||||||
const char * shower_timer = doc[TOPIC_SHOWER_TIMER];
|
const char * shower_timer = doc[TOPIC_SHOWER_TIMER];
|
||||||
if (shower_timer) {
|
if (shower_timer) {
|
||||||
EMSESP_Settings.shower_timer = ((shower_timer[0] - MYESP_MQTT_PAYLOAD_OFF) == 1);
|
EMSESP_Settings.shower_timer = ((shower_timer[0] - MYESP_MQTT_PAYLOAD_OFF) == 1);
|
||||||
myDebug_P(PSTR("Shower timer has been set to %s"), EMSESP_Settings.shower_timer ? "enabled" : "disabled");
|
if (ems_getLogging() != EMS_SYS_LOGGING_NONE) {
|
||||||
|
myDebug_P(PSTR("Shower timer has been set to %s"), EMSESP_Settings.shower_timer ? "enabled" : "disabled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -1949,7 +1966,8 @@ void setup() {
|
|||||||
systemCheckTimer.attach(SYSTEMCHECK_TIME, do_systemCheck); // check if EMS is reachable
|
systemCheckTimer.attach(SYSTEMCHECK_TIME, do_systemCheck); // check if EMS is reachable
|
||||||
|
|
||||||
// check for Dallas sensors
|
// check for Dallas sensors
|
||||||
EMSESP_Settings.dallas_sensors = ds18.setup(EMSESP_Settings.dallas_gpio, EMSESP_Settings.dallas_parasite); // returns #sensors
|
ds18.setup(EMSESP_Settings.dallas_gpio, EMSESP_Settings.dallas_parasite);
|
||||||
|
scanDallas();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
32
src/ems.cpp
32
src/ems.cpp
@@ -2125,21 +2125,31 @@ void ems_printDevices() {
|
|||||||
have_unknowns = true;
|
have_unknowns = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
myDebug_P(PSTR(" %s: %s%s%s (DeviceID:0x%02X ProductID:%d Version:%s)"),
|
if ((it->device_type == EMS_DEVICE_TYPE_THERMOSTAT) && (EMS_Sys_Status.emsMasterThermostat == it->product_id)) {
|
||||||
device_type,
|
myDebug_P(PSTR(" %s: %s%s%s (DeviceID:0x%02X ProductID:%d Version:%s) [master]"),
|
||||||
COLOR_BOLD_ON,
|
device_type,
|
||||||
device_string,
|
COLOR_BOLD_ON,
|
||||||
COLOR_BOLD_OFF,
|
device_string,
|
||||||
it->device_id,
|
COLOR_BOLD_OFF,
|
||||||
it->product_id,
|
it->device_id,
|
||||||
it->version);
|
it->product_id,
|
||||||
}
|
it->version);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
myDebug_P(PSTR(" %s: %s%s%s (DeviceID:0x%02X ProductID:%d Version:%s)"),
|
||||||
|
device_type,
|
||||||
|
COLOR_BOLD_ON,
|
||||||
|
device_string,
|
||||||
|
COLOR_BOLD_OFF,
|
||||||
|
it->device_id,
|
||||||
|
it->product_id,
|
||||||
|
it->version);
|
||||||
|
}
|
||||||
|
}
|
||||||
myDebug_P(PSTR("")); // newline
|
myDebug_P(PSTR("")); // newline
|
||||||
|
|
||||||
if (have_unknowns) {
|
if (have_unknowns) {
|
||||||
myDebug_P(
|
myDebug_P(PSTR("One or more devices are not recognized by EMS-ESP. Please report this in GitHub."));
|
||||||
PSTR("You have a device is that is not yet known by EMS-ESP. Please report this as a GitHub issue so we can expand the EMS device library."));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myDebug_P(PSTR("No were devices recognized. This may be because Tx is disabled or failing."));
|
myDebug_P(PSTR("No were devices recognized. This may be because Tx is disabled or failing."));
|
||||||
|
|||||||
Reference in New Issue
Block a user