diff --git a/src/ds18.cpp b/src/ds18.cpp index fbaa1ed55..cf7157709 100644 --- a/src/ds18.cpp +++ b/src/ds18.cpp @@ -18,23 +18,30 @@ DS18::DS18() { } DS18::~DS18() { - if (_wire) + if (_wire) { delete _wire; + } } // init -uint8_t DS18::setup(uint8_t gpio, bool parasite) { - uint8_t count; - +void DS18::setup(uint8_t gpio, bool parasite) { _gpio = gpio; _parasite = (parasite ? 1 : 0); // OneWire - if (_wire) + if (_wire) { delete _wire; + } _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(); // 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; } + // scan every 2 seconds void DS18::loop() { static uint32_t last = 0; diff --git a/src/ds18.h b/src/ds18.h index 3e2dd717e..aa1c2986f 100644 --- a/src/ds18.h +++ b/src/ds18.h @@ -36,7 +36,8 @@ class DS18 { DS18(); ~DS18(); - uint8_t setup(uint8_t gpio, bool parasite); + void setup(uint8_t gpio, bool parasite); + uint8_t scan(); void loop(); char * getDeviceString(char * s, unsigned char index); float getValue(unsigned char index); diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index b802e584a..01b5f0394 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -100,7 +100,7 @@ static const command_t project_cmds[] PROGMEM = { {true, "shower_alert ", "stop hot water to send 3 cold burst warnings after max shower time is exceeded"}, {true, "publish_time ", "set frequency for publishing data to MQTT (0=automatic)"}, {true, "tx_mode ", "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, "log ", "send read request to the thermostat for heating circuit hc 1-4"}, {false, "thermostat temp [hc] ", "set current thermostat temperature"}, @@ -505,6 +505,17 @@ void showInfo() { 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 void publishSensorValues() { // 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) { + myDebug("Scanning for new EMS devices and attached external sensors..."); + scanDallas(); ems_clearDeviceList(); ems_doReadCommand(EMS_TYPE_UBADevices, EMS_Boiler.device_id); 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]; if (shower_alert) { 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" const char * shower_timer = doc[TOPIC_SHOWER_TIMER]; if (shower_timer) { 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; @@ -1949,7 +1966,8 @@ void setup() { systemCheckTimer.attach(SYSTEMCHECK_TIME, do_systemCheck); // check if EMS is reachable // 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(); } // diff --git a/src/ems.cpp b/src/ems.cpp index 11f1e4fbc..b070a3fa5 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -2125,21 +2125,31 @@ void ems_printDevices() { have_unknowns = true; } - 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); - } + if ((it->device_type == EMS_DEVICE_TYPE_THERMOSTAT) && (EMS_Sys_Status.emsMasterThermostat == it->product_id)) { + myDebug_P(PSTR(" %s: %s%s%s (DeviceID:0x%02X ProductID:%d Version:%s) [master]"), + device_type, + COLOR_BOLD_ON, + device_string, + COLOR_BOLD_OFF, + it->device_id, + 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 if (have_unknowns) { - myDebug_P( - 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.")); + myDebug_P(PSTR("One or more devices are not recognized by EMS-ESP. Please report this in GitHub.")); } } else { myDebug_P(PSTR("No were devices recognized. This may be because Tx is disabled or failing."));