From ffacc66d9e79eeac064114f005bb2b68343484c7 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 18 Jun 2019 22:13:30 +0200 Subject: [PATCH] fix how json default values are set --- lib/MyESP/MyESP.cpp | 8 ++--- src/ems-esp.cpp | 73 +++++++++++++-------------------------------- 2 files changed, 23 insertions(+), 58 deletions(-) diff --git a/lib/MyESP/MyESP.cpp b/lib/MyESP/MyESP.cpp index f8e278cb8..b552132b5 100644 --- a/lib/MyESP/MyESP.cpp +++ b/lib/MyESP/MyESP.cpp @@ -274,10 +274,6 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) { myDebug_P(PSTR("[WIFI] Could not create access point\n")); } - if (code == MESSAGE_ACCESSPOINT_DESTROYED) { - myDebug_P(PSTR("[WIFI] Access point destroyed\n")); - } - if (code == MESSAGE_WPS_START) { myDebug_P(PSTR("[WIFI] WPS started\n")); } @@ -1562,9 +1558,9 @@ bool MyESP::_fs_loadConfig() { value = json["mqtt_password"]; _mqtt_password = (value) ? strdup(value) : NULL; - _use_serial = (bool)json["use_serial"]; + _use_serial = (bool)json["use_serial"]; // defaults to off - _heartbeat = (bool)json["heartbeat"]; + _heartbeat = (bool)json["heartbeat"]; // defaults to off // callback for loading custom settings // ok is false if there's a problem loading a custom setting (e.g. does not exist) diff --git a/src/ems-esp.cpp b/src/ems-esp.cpp index 6ed516e39..d1c084506 100644 --- a/src/ems-esp.cpp +++ b/src/ems-esp.cpp @@ -96,18 +96,18 @@ typedef struct { command_t project_cmds[] = { {true, "led ", "toggle status LED on/off"}, - {true, "led_gpio ", "set the LED pin. Default is the onboard LED (D1=5)"}, - {true, "dallas_gpio ", "set the pin for external Dallas temperature sensors (D5=14)"}, - {true, "dallas_parasite ", "set to on if powering Dallas via parasite"}, - {true, "thermostat_type ", "set the thermostat type id (e.g. 10 for 0x10)"}, - {true, "boiler_type ", "set the boiler type id (e.g. 8 for 0x08)"}, - {true, "listen_mode ", "when on all automatic Tx is disabled"}, - {true, "shower_timer ", "notify via MQTT all shower durations"}, - {true, "shower_alert ", "send a warning of cold water after shower time is exceeded"}, - {true, "publish_time ", "set frequency for publishing to MQTT (0=off)"}, - {true, "heating_circuit <1 | 2>", "set the thermostat HC to work with if using multiple heating circuits"}, + {true, "led_gpio ", "set the LED pin. Default is the onboard LED 2. For external D1 use 5"}, + {true, "dallas_gpio ", "set the external Dallas temperature sensors pin. Default is 14 for D5"}, + {true, "dallas_parasite ", "set to on if powering Dallas sesnsors via parasite power"}, + {true, "thermostat_type ", "set the thermostat type ID (e.g. 10 for 0x10)"}, + {true, "boiler_type ", "set the boiler type ID (e.g. 8 for 0x08)"}, + {true, "listen_mode ", "when set to on all automatic Tx are disabled"}, + {true, "shower_timer ", "send MQTT notification on all shower durations"}, + {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=off)"}, + {true, "heating_circuit <1 | 2>", "set the main thermostat HC to work with (if using multiple heating circuits)"}, - {false, "info", "show data captured on the EMS bus"}, + {false, "info", "show current captured on the devices"}, {false, "log ", "set logging mode to none, basic, thermostat only, raw or verbose"}, #ifdef TESTS @@ -1016,56 +1016,25 @@ void runUnitTest(uint8_t test_num) { // callback for loading/saving settings to the file system (SPIFFS) bool FSCallback(MYESP_FSACTION action, const JsonObject json) { if (action == MYESP_FSACTION_LOAD) { - bool recreate_config = true; - - // led - EMSESP_Status.led = json["led"]; - - // led_gpio - if (!(EMSESP_Status.led_gpio = json["led_gpio"])) { - EMSESP_Status.led_gpio = EMSESP_LED_GPIO; // default value - } - - // dallas_gpio - if (!(EMSESP_Status.dallas_gpio = json["dallas_gpio"])) { - EMSESP_Status.dallas_gpio = EMSESP_DALLAS_GPIO; // default value - } - - // dallas_parasite + EMSESP_Status.led = json["led"]; + EMSESP_Status.led_gpio = json["led_gpio"] | EMSESP_LED_GPIO; + EMSESP_Status.dallas_gpio = json["dallas_gpio"] | EMSESP_DALLAS_GPIO; EMSESP_Status.dallas_parasite = json["dallas_parasite"]; - // thermostat_type - if (!(EMS_Thermostat.device_id = json["thermostat_type"])) { - EMS_Thermostat.device_id = EMSESP_THERMOSTAT_TYPE; // set default - } + EMS_Thermostat.device_id = json["thermostat_type"] | EMSESP_THERMOSTAT_TYPE; + EMS_Boiler.device_id = json["boiler_type"] | EMSESP_BOILER_TYPE; - // boiler_type - if (!(EMS_Boiler.device_id = json["boiler_type"])) { - EMS_Boiler.device_id = EMSESP_BOILER_TYPE; // set default - } + EMSESP_Status.shower_timer = json["shower_timer"]; + EMSESP_Status.shower_alert = json["shower_alert"]; + EMSESP_Status.publish_time = json["publish_time"] | DEFAULT_PUBLISHTIME; - // listen mode EMSESP_Status.listen_mode = json["listen_mode"]; ems_setTxDisabled(EMSESP_Status.listen_mode); - // shower_timer - EMSESP_Status.shower_timer = json["shower_timer"]; - - // shower_alert - EMSESP_Status.shower_alert = json["shower_alert"]; - - // publish_time - if (!(EMSESP_Status.publish_time = json["publish_time"])) { - EMSESP_Status.publish_time = DEFAULT_PUBLISHTIME; // default value - } - - // heating_circuit - if (!(EMSESP_Status.heating_circuit = json["heating_circuit"])) { - EMSESP_Status.heating_circuit = DEFAULT_HEATINGCIRCUIT; // default value - } + EMSESP_Status.heating_circuit = json["heating_circuit"] | DEFAULT_HEATINGCIRCUIT; ems_setThermostatHC(EMSESP_Status.heating_circuit); - return recreate_config; // return false if some settings are missing and we need to rebuild the file + return true; // return false if some settings are missing and we need to rebuild the file } if (action == MYESP_FSACTION_SAVE) {