diff --git a/interface/.env.development b/interface/.env.development index 874a0b994..2e6df040d 100644 --- a/interface/.env.development +++ b/interface/.env.development @@ -2,8 +2,8 @@ # Remember to also enable CORS in platformio.ini before uploading the code to the device. # ESP32 dev -REACT_APP_HTTP_ROOT=http://192.168.1.32 -REACT_APP_WEB_SOCKET_ROOT=ws://192.168.1.32 +REACT_APP_HTTP_ROOT=http://10.10.10.101 +REACT_APP_WEB_SOCKET_ROOT=ws://10.10.10.101 # ESP8266 dev #REACT_APP_HTTP_ROOT=http://10.10.10.140 diff --git a/interface/src/mqtt/MqttSettingsForm.tsx b/interface/src/mqtt/MqttSettingsForm.tsx index a9768bda8..7a865d930 100644 --- a/interface/src/mqtt/MqttSettingsForm.tsx +++ b/interface/src/mqtt/MqttSettingsForm.tsx @@ -151,6 +151,17 @@ class MqttSettingsForm extends React.Component { by Sensor ID by Number + + on/off + true/false + 1/0 +

- - Other - - - on/off - true/false - 1/0 - -

} variant="contained" color="primary" type="submit"> Save diff --git a/interface/src/project/EMSESPtypes.ts b/interface/src/project/EMSESPtypes.ts index f9f5c54f2..d1f67b953 100644 --- a/interface/src/project/EMSESPtypes.ts +++ b/interface/src/project/EMSESPtypes.ts @@ -16,7 +16,6 @@ export interface EMSESPSettings { led_gpio: number; hide_led: boolean; api_enabled: boolean; - bool_format: number; analog_enabled: boolean; trace_raw: boolean; } diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index 56104e303..cea52002e 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -46,7 +46,7 @@ void APSettingsService::manageAP() { } void APSettingsService::startAP() { - Serial.println(F("Starting software access point")); + // Serial.println(F("Starting software access point")); WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask); WiFi.softAP(_state.ssid.c_str(), _state.password.c_str()); if (!_dnsServer) { @@ -65,7 +65,7 @@ void APSettingsService::stopAP() { delete _dnsServer; _dnsServer = nullptr; } - Serial.println(F("Stopping software access point")); + // Serial.println(F("Stopping software access point")); WiFi.softAPdisconnect(true); } diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index f0a12b99d..008f882a3 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -185,6 +185,7 @@ void MqttSettings::read(MqttSettings & settings, JsonObject & root) { root["mqtt_qos"] = settings.mqtt_qos; root["mqtt_retain"] = settings.mqtt_retain; root["dallas_format"] = settings.dallas_format; + root["bool_format"] = settings.bool_format; root["ha_climate_format"] = settings.ha_climate_format; root["ha_enabled"] = settings.ha_enabled; } @@ -214,6 +215,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting newSettings.publish_time_sensor = root["publish_time_sensor"] | EMSESP_DEFAULT_PUBLISH_TIME; newSettings.dallas_format = root["dallas_format"] | EMSESP_DEFAULT_DALLAS_FORMAT; + newSettings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT; newSettings.ha_climate_format = root["ha_climate_format"] | EMSESP_DEFAULT_HA_CLIMATE_FORMAT; newSettings.ha_enabled = root["ha_enabled"] | EMSESP_DEFAULT_HA_ENABLED; diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index a22f0cbec..be48248f7 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -60,6 +60,8 @@ static String generateClientId() { #define FACTORY_MQTT_MAX_TOPIC_LENGTH 128 #endif + +#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off #define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid #define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp #define EMSESP_DEFAULT_MQTT_QOS 0 @@ -101,6 +103,7 @@ class MqttSettings { uint8_t mqtt_qos; bool mqtt_retain; uint8_t dallas_format; + uint8_t bool_format; uint8_t ha_climate_format; bool ha_enabled; diff --git a/src/WebSettingsService.cpp b/src/WebSettingsService.cpp index 1fc922b9f..f14aa7ce9 100644 --- a/src/WebSettingsService.cpp +++ b/src/WebSettingsService.cpp @@ -47,7 +47,6 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { root["led_gpio"] = settings.led_gpio; root["hide_led"] = settings.hide_led; root["api_enabled"] = settings.api_enabled; - root["bool_format"] = settings.bool_format; root["analog_enabled"] = settings.analog_enabled; } @@ -93,10 +92,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) } // other - snprintf_P(&crc_before[0], crc_before.capacity() + 1, PSTR("%d%d"), settings.bool_format, settings.analog_enabled); - settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT; + snprintf_P(&crc_before[0], crc_before.capacity() + 1, PSTR("%d"), settings.analog_enabled); settings.analog_enabled = root["analog_enabled"] | EMSESP_DEFAULT_ANALOG_ENABLED; - snprintf_P(&crc_after[0], crc_after.capacity() + 1, PSTR("%d%d"), settings.bool_format, settings.analog_enabled); + snprintf_P(&crc_after[0], crc_after.capacity() + 1, PSTR("%d"), settings.analog_enabled); if (crc_before != crc_after) { add_flags(ChangeFlags::OTHER); } diff --git a/src/WebSettingsService.h b/src/WebSettingsService.h index 2e75d79be..2f120b8b3 100644 --- a/src/WebSettingsService.h +++ b/src/WebSettingsService.h @@ -89,7 +89,6 @@ class WebSettings { uint8_t led_gpio; bool hide_led; bool api_enabled; - uint8_t bool_format; bool analog_enabled; static void read(WebSettings & settings, JsonObject & root); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index 243a014cb..d09a5a1d0 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -499,10 +499,10 @@ bool EMSdevice::generate_values_json_web(JsonObject & json) { data.add(*(uint8_t *)(dv.value_p) ? dv.options[0] : dv.options[1]); } else { // see how to render the value depending on the setting - if (Helpers::bool_format() == BOOL_FORMAT_ONOFF) { + if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF) { // on or off as strings data.add(*(uint8_t *)(dv.value_p) ? F_(on) : F_(off)); - } else if (Helpers::bool_format() == BOOL_FORMAT_TRUEFALSE) { + } else if (Mqtt::bool_format() == BOOL_FORMAT_TRUEFALSE) { // true or false values (not strings) data.add((bool)(*(uint8_t *)(dv.value_p)) ? true : false); } else { @@ -645,11 +645,11 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter has_value = true; } else { // see how to render the value depending on the setting - if (Helpers::bool_format() == BOOL_FORMAT_ONOFF) { + if (Mqtt::bool_format() == BOOL_FORMAT_ONOFF) { // on or off as strings json[name] = *(uint8_t *)(dv.value_p) ? F_(on) : F_(off); has_value = true; - } else if (Helpers::bool_format() == BOOL_FORMAT_TRUEFALSE) { + } else if (Mqtt::bool_format() == BOOL_FORMAT_TRUEFALSE) { // true or false values (not strings) json[name] = (bool)(*(uint8_t *)(dv.value_p)) ? true : false; has_value = true; diff --git a/src/helpers.cpp b/src/helpers.cpp index 81181d378..0c7e27a2d 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -17,11 +17,10 @@ */ #include "helpers.h" +#include "mqtt.h" namespace emsesp { -uint8_t Helpers::bool_format_ = BOOL_FORMAT_ONOFF; // on/off - // like itoa but for hex, and quicker // note: only for single byte hex values char * Helpers::hextoa(char * result, const uint8_t value) { @@ -125,9 +124,10 @@ char * Helpers::smallitoa(char * result, const uint16_t value) { // work out how to display booleans char * Helpers::render_boolean(char * result, bool value) { - if (bool_format() == BOOL_FORMAT_ONOFF) { + uint8_t bool_format_ = Mqtt::bool_format(); + if (bool_format_ == BOOL_FORMAT_ONOFF) { strlcpy(result, value ? "on" : "off", 5); - } else if (bool_format() == BOOL_FORMAT_TRUEFALSE) { + } else if (bool_format_ == BOOL_FORMAT_TRUEFALSE) { strlcpy(result, value ? "true" : "false", 7); } else { strlcpy(result, value ? "1" : "0", 2); diff --git a/src/helpers.h b/src/helpers.h index 2e9365364..91c8df200 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -23,8 +23,6 @@ #include "telegram.h" // for EMS_VALUE_* settings -enum { BOOL_FORMAT_ONOFF = 1, BOOL_FORMAT_TRUEFALSE, BOOL_FORMAT_NUMBERS }; // matches Web UI settings - // #define FJSON(x) x #define FJSON(x) F(x) @@ -68,20 +66,9 @@ class Helpers { static bool value2string(const char * v, std::string & value); static bool value2enum(const char * v, uint8_t & value, const flash_string_vector & strs); - static void bool_format(uint8_t bool_format) { - bool_format_ = bool_format; - } - - static uint8_t bool_format() { - return bool_format_; - } - #ifdef EMSESP_STANDALONE static char * ultostr(char * ptr, uint32_t value, const uint8_t base); #endif - - private: - static uint8_t bool_format_; }; } // namespace emsesp diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 1126a307e..6aaf5f0df 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -36,6 +36,7 @@ uint32_t Mqtt::publish_time_sensor_; uint32_t Mqtt::publish_time_other_; bool Mqtt::mqtt_enabled_; uint8_t Mqtt::dallas_format_; +uint8_t Mqtt::bool_format_; uint8_t Mqtt::ha_climate_format_; bool Mqtt::ha_enabled_; @@ -467,6 +468,7 @@ void Mqtt::on_connect() { ha_enabled_ = mqttSettings.ha_enabled; ha_climate_format_ = mqttSettings.ha_climate_format; dallas_format_ = mqttSettings.dallas_format; + bool_format_ = mqttSettings.bool_format; }); // first time to connect diff --git a/src/mqtt.h b/src/mqtt.h index c760a767d..67bf9f292 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -50,6 +50,8 @@ using uuid::console::Shell; #define MAX_MQTT_MESSAGES 20 #endif +enum { BOOL_FORMAT_ONOFF = 1, BOOL_FORMAT_TRUEFALSE, BOOL_FORMAT_10 }; // matches Web UI settings + namespace emsesp { using mqtt_subfunction_p = std::function; @@ -156,6 +158,10 @@ class Mqtt { return dallas_format_; } + static uint8_t bool_format() { + return bool_format_; + } + static bool ha_enabled() { return ha_enabled_; } @@ -265,6 +271,7 @@ class Mqtt { static uint32_t publish_time_sensor_; static bool mqtt_enabled_; static uint8_t dallas_format_; + static uint8_t bool_format_; static uint8_t ha_climate_format_; static bool ha_enabled_; }; diff --git a/src/system.cpp b/src/system.cpp index 9b92f1c51..a02521e7c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -258,7 +258,6 @@ void System::start(uint32_t heap_start) { void System::other_init() { // set the boolean format used for rendering booleans EMSESP::webSettingsService.read([&](WebSettings & settings) { - Helpers::bool_format(settings.bool_format); analog_enabled_ = settings.analog_enabled; }); } @@ -767,7 +766,6 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject & EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) { JsonObject node = json.createNestedObject("WIFI"); node["ssid"] = settings.ssid; - // node["password"] = settings.password; node["hostname"] = settings.hostname; node["static_ip_config"] = settings.staticIPConfig; JsonUtils::writeIP(node, "local_ip", settings.localIP); @@ -782,7 +780,6 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject & JsonObject node = json.createNestedObject("AP"); node["provision_mode"] = settings.provisionMode; node["ssid"] = settings.ssid; - // node["password"] = settings.password; node["local_ip"] = settings.localIP.toString(); node["gateway_ip"] = settings.gatewayIP.toString(); node["subnet_mask"] = settings.subnetMask.toString(); @@ -790,17 +787,15 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject & #endif EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & settings) { - char s[7]; JsonObject node = json.createNestedObject("MQTT"); - node["enabled"] = Helpers::render_boolean(s, settings.enabled); - // node["password"] = settings.password; + node["enabled"] = settings.enabled; #ifndef EMSESP_STANDALONE node["host"] = settings.host; node["port"] = settings.port; node["username"] = settings.username; node["client_id"] = settings.clientId; node["keep_alive"] = settings.keepAlive; - node["clean_session"] = Helpers::render_boolean(s, settings.cleanSession); + node["clean_session"] = settings.cleanSession; #endif node["publish_time_boiler"] = settings.publish_time_boiler; node["publish_time_thermostat"] = settings.publish_time_thermostat; @@ -809,52 +804,48 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject & node["publish_time_other"] = settings.publish_time_other; node["publish_time_sensor"] = settings.publish_time_sensor; node["dallas_format"] = settings.dallas_format; + node["bool_format"] = settings.bool_format; node["ha_climate_format"] = settings.ha_climate_format; node["ha_enabled"] = settings.ha_enabled; node["mqtt_qos"] = settings.mqtt_qos; - node["mqtt_retain"] = Helpers::render_boolean(s, settings.mqtt_retain); + node["mqtt_retain"] = settings.mqtt_retain; }); #ifndef EMSESP_STANDALONE EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) { - char s[7]; JsonObject node = json.createNestedObject("NTP"); - node["enabled"] = Helpers::render_boolean(s, settings.enabled); + node["enabled"] = settings.enabled; node["server"] = settings.server; node["tz_label"] = settings.tzLabel; node["tz_format"] = settings.tzFormat; }); EMSESP::esp8266React.getOTASettingsService()->read([&](OTASettings & settings) { - char s[7]; JsonObject node = json.createNestedObject("OTA"); - node["enabled"] = Helpers::render_boolean(s, settings.enabled); + node["enabled"] = settings.enabled; node["port"] = settings.port; - // node["password"] = settings.password; }); #endif EMSESP::webSettingsService.read([&](WebSettings & settings) { - char s[7]; JsonObject node = json.createNestedObject("Settings"); node["tx_mode"] = settings.tx_mode; node["ems_bus_id"] = settings.ems_bus_id; - node["syslog_enabled"] = Helpers::render_boolean(s, settings.syslog_enabled); + node["syslog_enabled"] = settings.syslog_enabled; node["syslog_level"] = settings.syslog_level; node["syslog_mark_interval"] = settings.syslog_mark_interval; node["syslog_host"] = settings.syslog_host; node["master_thermostat"] = settings.master_thermostat; - node["shower_timer"] = Helpers::render_boolean(s, settings.shower_timer); - node["shower_alert"] = Helpers::render_boolean(s, settings.shower_alert); + node["shower_timer"] = settings.shower_timer; + node["shower_alert"] = settings.shower_alert; node["rx_gpio"] = settings.rx_gpio; node["tx_gpio"] = settings.tx_gpio; node["dallas_gpio"] = settings.dallas_gpio; - node["dallas_parasite"] = Helpers::render_boolean(s, settings.dallas_parasite); + node["dallas_parasite"] = settings.dallas_parasite; node["led_gpio"] = settings.led_gpio; - node["hide_led"] = Helpers::render_boolean(s, settings.hide_led); - node["api_enabled"] = Helpers::render_boolean(s, settings.api_enabled); - node["bool_format"] = settings.bool_format; - node["analog_enabled"] = Helpers::render_boolean(s, settings.analog_enabled); + node["hide_led"] = settings.hide_led; + node["api_enabled"] = settings.api_enabled; + node["analog_enabled"] = settings.analog_enabled; }); return true;