From f2cc5b98baac5eee7bba14f1ee1f7d10bc10b454 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 22 Oct 2020 18:58:14 +0200 Subject: [PATCH] rename classes --- lib/framework/MqttSettingsService.cpp | 8 +- lib/framework/MqttSettingsService.h | 2 +- ...EMSESPAPIService.cpp => WebAPIService.cpp} | 10 +- src/{EMSESPAPIService.h => WebAPIService.h} | 10 +- ...vicesService.cpp => WebDevicesService.cpp} | 18 +-- ...SPDevicesService.h => WebDevicesService.h} | 8 +- ...ingsService.cpp => WebSettingsService.cpp} | 22 ++- ...SettingsService.h => WebSettingsService.h} | 18 +-- ...StatusService.cpp => WebStatusService.cpp} | 16 +- ...SESPStatusService.h => WebStatusService.h} | 10 +- src/console.cpp | 14 +- src/{sensor.cpp => dallassensor.cpp} | 142 +++++++++--------- src/{sensor.h => dallassensor.h} | 26 ++-- src/devices/thermostat.cpp | 2 +- src/emsesp.cpp | 70 ++++----- src/emsesp.h | 43 +++--- src/mqtt.cpp | 2 +- src/shower.cpp | 2 +- src/system.cpp | 22 +-- src/telegram.cpp | 2 +- 20 files changed, 221 insertions(+), 226 deletions(-) rename src/{EMSESPAPIService.cpp => WebAPIService.cpp} (89%) rename src/{EMSESPAPIService.h => WebAPIService.h} (83%) rename src/{EMSESPDevicesService.cpp => WebDevicesService.cpp} (78%) rename src/{EMSESPDevicesService.h => WebDevicesService.h} (88%) rename src/{EMSESPSettingsService.cpp => WebSettingsService.cpp} (83%) rename src/{EMSESPSettingsService.h => WebSettingsService.h} (84%) rename src/{EMSESPStatusService.cpp => WebStatusService.cpp} (78%) rename src/{EMSESPStatusService.h => WebStatusService.h} (86%) rename src/{sensor.cpp => dallassensor.cpp} (72%) rename src/{sensor.h => dallassensor.h} (91%) diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index 359e14b0a..7fa65deac 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -4,9 +4,9 @@ namespace emsesp { class EMSESP { public: - static System system_; - static Mqtt mqtt_; - static Sensor sensor_; + static System system_; + static Mqtt mqtt_; + static DallasSensor dallassensor_; }; } // namespace emsesp @@ -169,7 +169,7 @@ void MqttSettingsService::configureMqtt() { _mqttClient.connect(); } - emsesp::EMSESP::sensor_.reload(); + emsesp::EMSESP::dallassensor_.reload(); } void MqttSettings::read(MqttSettings & settings, JsonObject & root) { diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index abdd40f82..9b88452e3 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -10,7 +10,7 @@ #include "../../src/system.h" #include "../../src/mqtt.h" -#include "../../src/sensor.h" +#include "../../src/dallassensor.h" #define MQTT_RECONNECTION_DELAY 1000 diff --git a/src/EMSESPAPIService.cpp b/src/WebAPIService.cpp similarity index 89% rename from src/EMSESPAPIService.cpp rename to src/WebAPIService.cpp index a08728342..0481dea4d 100644 --- a/src/EMSESPAPIService.cpp +++ b/src/WebAPIService.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include "EMSESPAPIService.h" +#include "WebAPIService.h" #include "emsesp.h" #include "command.h" #include "emsdevice.h" @@ -24,15 +24,15 @@ namespace emsesp { -EMSESPAPIService::EMSESPAPIService(AsyncWebServer * server) { - server->on(EMSESP_API_SERVICE_PATH, HTTP_GET, std::bind(&EMSESPAPIService::emsespAPIService, this, std::placeholders::_1)); +WebAPIService::WebAPIService(AsyncWebServer * server) { + server->on(EMSESP_API_SERVICE_PATH, HTTP_GET, std::bind(&WebAPIService::webAPIService, this, std::placeholders::_1)); } // http://ems-esp/api?device=boiler&cmd=wwtemp&data=20&id=1 -void EMSESPAPIService::emsespAPIService(AsyncWebServerRequest * request) { +void WebAPIService::webAPIService(AsyncWebServerRequest * request) { // see if the API is enabled bool api_enabled; - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { api_enabled = settings.api_enabled; }); + EMSESP::webSettingsService.read([&](WebSettings & settings) { api_enabled = settings.api_enabled; }); // must have device and cmd parameters if ((!request->hasParam(F_(device))) || (!request->hasParam(F_(cmd)))) { diff --git a/src/EMSESPAPIService.h b/src/WebAPIService.h similarity index 83% rename from src/EMSESPAPIService.h rename to src/WebAPIService.h index 1ecbc4490..a62a0224f 100644 --- a/src/EMSESPAPIService.h +++ b/src/WebAPIService.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EMSESPAPIService_h -#define EMSESPAPIService_h +#ifndef WebAPIService_h +#define WebAPIService_h #include #include @@ -27,12 +27,12 @@ namespace emsesp { -class EMSESPAPIService { +class WebAPIService { public: - EMSESPAPIService(AsyncWebServer * server); + WebAPIService(AsyncWebServer * server); private: - void emsespAPIService(AsyncWebServerRequest * request); + void webAPIService(AsyncWebServerRequest * request); }; } // namespace emsesp diff --git a/src/EMSESPDevicesService.cpp b/src/WebDevicesService.cpp similarity index 78% rename from src/EMSESPDevicesService.cpp rename to src/WebDevicesService.cpp index 7211a4e2d..f182c918e 100644 --- a/src/EMSESPDevicesService.cpp +++ b/src/WebDevicesService.cpp @@ -16,35 +16,35 @@ * along with this program. If not, see . */ -#include "EMSESPDevicesService.h" +#include "WebDevicesService.h" #include "emsesp.h" namespace emsesp { using namespace std::placeholders; // for `_1` etc -EMSESPDevicesService::EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager) +WebDevicesService::WebDevicesService(AsyncWebServer * server, SecurityManager * securityManager) : _device_dataHandler(DEVICE_DATA_SERVICE_PATH, - securityManager->wrapCallback(std::bind(&EMSESPDevicesService::device_data, this, _1, _2), AuthenticationPredicates::IS_AUTHENTICATED)) { + securityManager->wrapCallback(std::bind(&WebDevicesService::device_data, this, _1, _2), AuthenticationPredicates::IS_AUTHENTICATED)) { server->on(EMSESP_DEVICES_SERVICE_PATH, HTTP_GET, - securityManager->wrapRequest(std::bind(&EMSESPDevicesService::all_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED)); + securityManager->wrapRequest(std::bind(&WebDevicesService::all_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED)); server->on(SCAN_DEVICES_SERVICE_PATH, HTTP_GET, - securityManager->wrapRequest(std::bind(&EMSESPDevicesService::scan_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED)); + securityManager->wrapRequest(std::bind(&WebDevicesService::scan_devices, this, _1), AuthenticationPredicates::IS_AUTHENTICATED)); _device_dataHandler.setMethod(HTTP_POST); _device_dataHandler.setMaxContentLength(256); server->addHandler(&_device_dataHandler); } -void EMSESPDevicesService::scan_devices(AsyncWebServerRequest * request) { +void WebDevicesService::scan_devices(AsyncWebServerRequest * request) { EMSESP::scan_devices(); request->send(200); } -void EMSESPDevicesService::all_devices(AsyncWebServerRequest * request) { +void WebDevicesService::all_devices(AsyncWebServerRequest * request) { AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_EMSESP_DEVICE_SIZE); JsonObject root = response->getRoot(); @@ -63,7 +63,7 @@ void EMSESPDevicesService::all_devices(AsyncWebServerRequest * request) { } JsonArray sensors = root.createNestedArray("sensors"); - if (!EMSESP::sensor_devices().empty()) { + if (EMSESP::have_sensors()) { uint8_t i = 1; char s[8]; for (const auto & sensor : EMSESP::sensor_devices()) { @@ -78,7 +78,7 @@ void EMSESPDevicesService::all_devices(AsyncWebServerRequest * request) { request->send(response); } -void EMSESPDevicesService::device_data(AsyncWebServerRequest * request, JsonVariant & json) { +void WebDevicesService::device_data(AsyncWebServerRequest * request, JsonVariant & json) { if (json.is()) { AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_EMSESP_DEVICE_SIZE); #ifndef EMSESP_STANDALONE diff --git a/src/EMSESPDevicesService.h b/src/WebDevicesService.h similarity index 88% rename from src/EMSESPDevicesService.h rename to src/WebDevicesService.h index f91212fc0..3607b4f81 100644 --- a/src/EMSESPDevicesService.h +++ b/src/WebDevicesService.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EMSESPDevicesService_h -#define EMSESPDevicesService_h +#ifndef WebDevicesService_h +#define WebDevicesService_h #include #include @@ -32,9 +32,9 @@ namespace emsesp { -class EMSESPDevicesService { +class WebDevicesService { public: - EMSESPDevicesService(AsyncWebServer * server, SecurityManager * securityManager); + WebDevicesService(AsyncWebServer * server, SecurityManager * securityManager); private: void all_devices(AsyncWebServerRequest * request); diff --git a/src/EMSESPSettingsService.cpp b/src/WebSettingsService.cpp similarity index 83% rename from src/EMSESPSettingsService.cpp rename to src/WebSettingsService.cpp index 3441b4f11..dbb845f1f 100644 --- a/src/EMSESPSettingsService.cpp +++ b/src/WebSettingsService.cpp @@ -16,18 +16,18 @@ * along with this program. If not, see . */ -#include "EMSESPSettingsService.h" +#include "WebSettingsService.h" #include "emsesp.h" namespace emsesp { -EMSESPSettingsService::EMSESPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) - : _httpEndpoint(EMSESPSettings::read, EMSESPSettings::update, this, server, EMSESP_SETTINGS_SERVICE_PATH, securityManager) - , _fsPersistence(EMSESPSettings::read, EMSESPSettings::update, this, fs, EMSESP_SETTINGS_FILE) { +WebSettingsService::WebSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) + : _httpEndpoint(WebSettings::read, WebSettings::update, this, server, EMSESP_SETTINGS_SERVICE_PATH, securityManager) + , _fsPersistence(WebSettings::read, WebSettings::update, this, fs, EMSESP_SETTINGS_FILE) { addUpdateHandler([&](const String & originId) { onUpdate(); }, false); } -void EMSESPSettings::read(EMSESPSettings & settings, JsonObject & root) { +void WebSettings::read(WebSettings & settings, JsonObject & root) { root["tx_mode"] = settings.tx_mode; root["ems_bus_id"] = settings.ems_bus_id; root["syslog_level"] = settings.syslog_level; @@ -47,7 +47,7 @@ void EMSESPSettings::read(EMSESPSettings & settings, JsonObject & root) { root["analog_enabled"] = settings.analog_enabled; } -StateUpdateResult EMSESPSettings::update(JsonObject & root, EMSESPSettings & settings) { +StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) { settings.tx_mode = root["tx_mode"] | EMSESP_DEFAULT_TX_MODE; settings.ems_bus_id = root["ems_bus_id"] | EMSESP_DEFAULT_EMS_BUS_ID; settings.syslog_level = root["syslog_level"] | EMSESP_DEFAULT_SYSLOG_LEVEL; @@ -71,19 +71,17 @@ StateUpdateResult EMSESPSettings::update(JsonObject & root, EMSESPSettings & set // this is called after any of the settings have been persisted to the filesystem // either via the Web UI or via the Console -void EMSESPSettingsService::onUpdate() { +void WebSettingsService::onUpdate() { EMSESP::shower_.start(); - Sensor sensor_; // Dallas sensors - sensor_.start(); - + EMSESP::dallassensor_.start(); System::init(); } -void EMSESPSettingsService::begin() { +void WebSettingsService::begin() { _fsPersistence.readFromFS(); } -void EMSESPSettingsService::save() { +void WebSettingsService::save() { _fsPersistence.writeToFS(); } diff --git a/src/EMSESPSettingsService.h b/src/WebSettingsService.h similarity index 84% rename from src/EMSESPSettingsService.h rename to src/WebSettingsService.h index 4fd819903..46e1a724b 100644 --- a/src/EMSESPSettingsService.h +++ b/src/WebSettingsService.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EMSESPSettingsConfig_h -#define EMSESPSettingsConfig_h +#ifndef WebSettingsConfig_h +#define WebSettingsConfig_h #include #include @@ -60,7 +60,7 @@ namespace emsesp { -class EMSESPSettings { +class WebSettings { public: uint8_t tx_mode; uint8_t ems_bus_id; @@ -80,20 +80,20 @@ class EMSESPSettings { uint8_t bool_format; bool analog_enabled; - static void read(EMSESPSettings & settings, JsonObject & root); - static StateUpdateResult update(JsonObject & root, EMSESPSettings & settings); + static void read(WebSettings & settings, JsonObject & root); + static StateUpdateResult update(JsonObject & root, WebSettings & settings); }; -class EMSESPSettingsService : public StatefulService { +class WebSettingsService : public StatefulService { public: - EMSESPSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager); + WebSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager); void begin(); void save(); private: - HttpEndpoint _httpEndpoint; - FSPersistence _fsPersistence; + HttpEndpoint _httpEndpoint; + FSPersistence _fsPersistence; void onUpdate(); }; diff --git a/src/EMSESPStatusService.cpp b/src/WebStatusService.cpp similarity index 78% rename from src/EMSESPStatusService.cpp rename to src/WebStatusService.cpp index 1bbb08b3c..efeccb3da 100644 --- a/src/EMSESPStatusService.cpp +++ b/src/WebStatusService.cpp @@ -16,16 +16,16 @@ * along with this program. If not, see . */ -#include "EMSESPStatusService.h" +#include "WebStatusService.h" #include "emsesp.h" namespace emsesp { -EMSESPStatusService::EMSESPStatusService(AsyncWebServer * server, SecurityManager * securityManager) { +WebStatusService::WebStatusService(AsyncWebServer * server, SecurityManager * securityManager) { // rest endpoint for web page server->on(EMSESP_STATUS_SERVICE_PATH, HTTP_GET, - securityManager->wrapRequest(std::bind(&EMSESPStatusService::emsespStatusService, this, std::placeholders::_1), + securityManager->wrapRequest(std::bind(&WebStatusService::webStatusService, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)); // trigger on wifi connects/disconnects @@ -39,24 +39,24 @@ EMSESPStatusService::EMSESPStatusService(AsyncWebServer * server, SecurityManage } #ifdef ESP32 -void EMSESPStatusService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { +void WebStatusService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { EMSESP::logger().debug(F("WiFi Disconnected. Reason code=%d"), info.disconnected.reason); } -void EMSESPStatusService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { +void WebStatusService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { EMSESP::logger().debug(F("WiFi Connected with IP=%s, hostname=%s"), WiFi.localIP().toString().c_str(), WiFi.getHostname()); EMSESP::system_.send_heartbeat(); // send out heartbeat MQTT as soon as we have a connection } #elif defined(ESP8266) -void EMSESPStatusService::onStationModeDisconnected(const WiFiEventStationModeDisconnected & event) { +void WebStatusService::onStationModeDisconnected(const WiFiEventStationModeDisconnected & event) { EMSESP::logger().debug(F("WiFi Disconnected. Reason code=%d"), event.reason); } -void EMSESPStatusService::onStationModeGotIP(const WiFiEventStationModeGotIP & event) { +void WebStatusService::onStationModeGotIP(const WiFiEventStationModeGotIP & event) { EMSESP::logger().debug(F("WiFi Connected with IP=%s, hostname=%s"), event.ip.toString().c_str(), WiFi.hostname().c_str()); EMSESP::system_.send_heartbeat(); // send out heartbeat MQTT as soon as we have a connection } #endif -void EMSESPStatusService::emsespStatusService(AsyncWebServerRequest * request) { +void WebStatusService::webStatusService(AsyncWebServerRequest * request) { AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_EMSESP_STATUS_SIZE); JsonObject root = response->getRoot(); diff --git a/src/EMSESPStatusService.h b/src/WebStatusService.h similarity index 86% rename from src/EMSESPStatusService.h rename to src/WebStatusService.h index 8ee99071a..1f2b32269 100644 --- a/src/EMSESPStatusService.h +++ b/src/WebStatusService.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef EMSESPStatusService_h -#define EMSESPStatusService_h +#ifndef WebStatusService_h +#define WebStatusService_h #include #include @@ -30,12 +30,12 @@ namespace emsesp { -class EMSESPStatusService { +class WebStatusService { public: - EMSESPStatusService(AsyncWebServer * server, SecurityManager * securityManager); + WebStatusService(AsyncWebServer * server, SecurityManager * securityManager); private: - void emsespStatusService(AsyncWebServerRequest * request); + void webStatusService(AsyncWebServerRequest * request); #ifdef ESP32 static void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); diff --git a/src/console.cpp b/src/console.cpp index cce97625c..fc07e613b 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -177,8 +177,8 @@ void EMSESPShell::add_console_commands() { [](Shell & shell, const std::vector & arguments) { uint8_t device_id = Helpers::hextoint(arguments.front().c_str()); if ((device_id == 0x0B) || (device_id == 0x0D) || (device_id == 0x0A) || (device_id == 0x0F) || (device_id == 0x12)) { - EMSESP::emsespSettingsService.update( - [&](EMSESPSettings & settings) { + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { settings.ems_bus_id = device_id; shell.printfln(F_(bus_id_fmt), settings.ems_bus_id); return StateUpdateResult::CHANGED; @@ -206,8 +206,8 @@ void EMSESPShell::add_console_commands() { [](Shell & shell, const std::vector & arguments) { uint8_t tx_mode = std::strtol(arguments[0].c_str(), nullptr, 10); // save the tx_mode - EMSESP::emsespSettingsService.update( - [&](EMSESPSettings & settings) { + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { settings.tx_mode = tx_mode; shell.printfln(F_(tx_mode_fmt), settings.tx_mode); return StateUpdateResult::CHANGED; @@ -258,7 +258,7 @@ void EMSESPShell::add_console_commands() { CommandFlags::USER, flash_string_vector{F_(set)}, [](Shell & shell, const std::vector & arguments __attribute__((unused))) { - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.printfln(F_(tx_mode_fmt), settings.tx_mode); shell.printfln(F_(bus_id_fmt), settings.ems_bus_id); char buffer[4]; @@ -290,8 +290,8 @@ void EMSESPShell::add_console_commands() { flash_string_vector{F_(deviceid_mandatory)}, [](Shell & shell, const std::vector & arguments) { uint8_t value = Helpers::hextoint(arguments.front().c_str()); - EMSESP::emsespSettingsService.update( - [&](EMSESPSettings & settings) { + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { settings.master_thermostat = value; EMSESP::actual_master_thermostat(value); // set the internal value too char buffer[5]; diff --git a/src/sensor.cpp b/src/dallassensor.cpp similarity index 72% rename from src/sensor.cpp rename to src/dallassensor.cpp index 1e8008496..59b0462ec 100644 --- a/src/sensor.cpp +++ b/src/dallassensor.cpp @@ -18,7 +18,7 @@ // code originally written by nomis - https://github.com/nomis -#include "sensor.h" +#include "dallassensor.h" #include "emsesp.h" #ifdef ESP32 @@ -29,10 +29,10 @@ namespace emsesp { -uuid::log::Logger Sensor::logger_{F_(sensor), uuid::log::Facility::DAEMON}; +uuid::log::Logger DallasSensor::logger_{F_(sensor), uuid::log::Facility::DAEMON}; // start the 1-wire -void Sensor::start() { +void DallasSensor::start() { reload(); #ifndef EMSESP_STANDALONE @@ -48,8 +48,8 @@ void Sensor::start() { } // load the MQTT settings -void Sensor::reload() { - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { +void DallasSensor::reload() { + EMSESP::webSettingsService.read([&](WebSettings & settings) { dallas_gpio_ = settings.dallas_gpio; parasite_ = settings.dallas_parasite; }); @@ -60,7 +60,7 @@ void Sensor::reload() { } } -void Sensor::loop() { +void DallasSensor::loop() { #ifndef EMSESP_STANDALONE uint32_t time_now = uuid::get_uptime(); @@ -109,31 +109,31 @@ void Sensor::loop() { if ((t >= -550) && (t <= 1250)) { // check if we have this sensor already bool found = false; - for (auto & device : devices_) { - if (device.id() == get_id(addr)) { - changed_ |= (t != device.temperature_c); - device.temperature_c = t; - device.read = true; + for (auto & sensor : sensors_) { + if (sensor.id() == get_id(addr)) { + changed_ |= (t != sensor.temperature_c); + sensor.temperature_c = t; + sensor.read = true; found = true; break; } } // add new sensor - if (!found && (devices_.size() < (MAX_SENSORS - 1))) { - devices_.emplace_back(addr); - devices_.back().temperature_c = t; - devices_.back().read = true; + if (!found && (sensors_.size() < (MAX_SENSORS - 1))) { + sensors_.emplace_back(addr); + sensors_.back().temperature_c = t; + sensors_.back().read = true; changed_ = true; } } break; default: - LOG_ERROR(F("Unknown sensor %s"), Device(addr).to_string().c_str()); + LOG_ERROR(F("Unknown sensor %s"), Sensor(addr).to_string().c_str()); break; } } else { - LOG_ERROR(F("Invalid sensor %s"), Device(addr).to_string().c_str()); + LOG_ERROR(F("Invalid sensor %s"), Sensor(addr).to_string().c_str()); } } else { if (!parasite_) { @@ -141,21 +141,21 @@ void Sensor::loop() { } // check for missing sensors after some samples if (++scancnt_ > 5) { - for (auto & device : devices_) { - if (!device.read) { - device.temperature_c = EMS_VALUE_SHORT_NOTSET; + for (auto & sensor : sensors_) { + if (!sensor.read) { + sensor.temperature_c = EMS_VALUE_SHORT_NOTSET; changed_ = true; } - device.read = false; + sensor.read = false; } scancnt_ = 0; } else if (scancnt_ == -2) { // startup - firstscan_ = devices_.size(); - } else if ((scancnt_ <= 0) && (firstscan_ != devices_.size())) { // check 2 times for no change of sensorno. + firstscan_ = sensors_.size(); + } else if ((scancnt_ <= 0) && (firstscan_ != sensors_.size())) { // check 2 times for no change of sensor # scancnt_ = -3; - devices_.clear(); // restart scaning and clear to get correct numbering + sensors_.clear(); // restart scaning and clear to get correct numbering } - // LOG_DEBUG(F("Found %zu sensor(s). Adding them."), devices_.size()); // uncomment for debug + // LOG_DEBUG(F("Found %zu sensor(s). Adding them."), sensors_.size()); // uncomment for debug state_ = State::IDLE; } } @@ -163,7 +163,7 @@ void Sensor::loop() { #endif } -bool Sensor::temperature_convert_complete() { +bool DallasSensor::temperature_convert_complete() { #ifndef EMSESP_STANDALONE if (parasite_) { return true; // don't care, use the minimum time in loop @@ -177,10 +177,10 @@ bool Sensor::temperature_convert_complete() { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" -int16_t Sensor::get_temperature_c(const uint8_t addr[]) { +int16_t DallasSensor::get_temperature_c(const uint8_t addr[]) { #ifndef EMSESP_STANDALONE if (!bus_.reset()) { - LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Device(addr).to_string().c_str()); + LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Sensor(addr).to_string().c_str()); return EMS_VALUE_SHORT_NOTSET; } YIELD; @@ -192,13 +192,13 @@ int16_t Sensor::get_temperature_c(const uint8_t addr[]) { YIELD; if (!bus_.reset()) { - LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Device(addr).to_string().c_str()); + LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Sensor(addr).to_string().c_str()); return EMS_VALUE_SHORT_NOTSET; } YIELD; if (bus_.crc8(scratchpad, SCRATCHPAD_LEN - 1) != scratchpad[SCRATCHPAD_LEN - 1]) { - LOG_WARNING(F("Invalid scratchpad CRC: %02X%02X%02X%02X%02X%02X%02X%02X%02X from device %s"), + LOG_WARNING(F("Invalid scratchpad CRC: %02X%02X%02X%02X%02X%02X%02X%02X%02X from sensor %s"), scratchpad[0], scratchpad[1], scratchpad[2], @@ -208,7 +208,7 @@ int16_t Sensor::get_temperature_c(const uint8_t addr[]) { scratchpad[6], scratchpad[7], scratchpad[8], - Device(addr).to_string().c_str()); + Sensor(addr).to_string().c_str()); return EMS_VALUE_SHORT_NOTSET; } @@ -217,7 +217,7 @@ int16_t Sensor::get_temperature_c(const uint8_t addr[]) { if (addr[0] == TYPE_DS18S20) { raw_value = (raw_value << 3) + 12 - scratchpad[SCRATCHPAD_CNT_REM]; } else { - // Adjust based on device resolution + // Adjust based on sensor resolution int resolution = 9 + ((scratchpad[SCRATCHPAD_CONFIG] >> 5) & 0x3); switch (resolution) { case 9: @@ -242,26 +242,26 @@ int16_t Sensor::get_temperature_c(const uint8_t addr[]) { #pragma GCC diagnostic pop -const std::vector Sensor::devices() const { - return devices_; +const std::vector DallasSensor::sensors() const { + return sensors_; } // skip crc from id. -Sensor::Device::Device(const uint8_t addr[]) +DallasSensor::Sensor::Sensor(const uint8_t addr[]) : id_(((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16) | ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])) { } -uint64_t Sensor::get_id(const uint8_t addr[]) { +uint64_t DallasSensor::get_id(const uint8_t addr[]) { return (((uint64_t)addr[0] << 48) | ((uint64_t)addr[1] << 40) | ((uint64_t)addr[2] << 32) | ((uint64_t)addr[3] << 24) | ((uint64_t)addr[4] << 16) | ((uint64_t)addr[5] << 8) | ((uint64_t)addr[6])); } -uint64_t Sensor::Device::id() const { +uint64_t DallasSensor::Sensor::id() const { return id_; } -std::string Sensor::Device::to_string() const { +std::string DallasSensor::Sensor::to_string() const { std::string str(20, '\0'); snprintf_P(&str[0], str.capacity() + 1, @@ -274,7 +274,7 @@ std::string Sensor::Device::to_string() const { } // check to see if values have been updated -bool Sensor::updated_values() { +bool DallasSensor::updated_values() { if (changed_) { changed_ = false; return true; @@ -282,25 +282,26 @@ bool Sensor::updated_values() { return false; } -bool Sensor::command_info(const char * value, const int8_t id, JsonObject & output) { +bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject & output) { return (export_values(output)); } // creates JSON doc from values // returns false if empty -// e.g. sensor_data = {"sensor1":{"id":"28-EA41-9497-0E03-5F","temp":"23.30"},"sensor2":{"id":"28-233D-9497-0C03-8B","temp":"24.0"}} -bool Sensor::export_values(JsonObject & output) { - if (devices_.size() == 0) { +// e.g. sensor_data = {"sensor1":{"id":"28-EA41-9497-0E03-5F","temp":23.30},"sensor2":{"id":"28-233D-9497-0C03-8B","temp":24.0}} +bool DallasSensor::export_values(JsonObject & output) { + if (sensors_.size() == 0) { return false; } + uint8_t i = 1; // sensor count - for (const auto & device : devices_) { + for (const auto & sensor : sensors_) { char sensorID[10]; // sensor{1-n} snprintf_P(sensorID, 10, PSTR("sensor%d"), i++); JsonObject dataSensor = output.createNestedObject(sensorID); - dataSensor["id"] = device.to_string(); - if (Helpers::hasValue(device.temperature_c)) { - dataSensor["temp"] = (float)(device.temperature_c) / 10; + dataSensor["id"] = sensor.to_string(); + if (Helpers::hasValue(sensor.temperature_c)) { + dataSensor["temp"] = (float)(sensor.temperature_c) / 10; } } @@ -308,41 +309,37 @@ bool Sensor::export_values(JsonObject & output) { } // send all dallas sensor values as a JSON package to MQTT -// assumes there are devices -void Sensor::publish_values() { - uint8_t num_devices = devices_.size(); +void DallasSensor::publish_values() { + uint8_t num_sensors = sensors_.size(); - if (num_devices == 0) { + if (num_sensors == 0) { return; } - DynamicJsonDocument doc(100 * num_devices); - uint8_t sensor_no = 1; // sensor count + DynamicJsonDocument doc(100 * num_sensors); + uint8_t sensor_no = 1; uint8_t mqtt_format_ = Mqtt::mqtt_format(); - for (const auto & device : devices_) { + + for (const auto & sensor : sensors_) { char sensorID[10]; // sensor{1-n} snprintf_P(sensorID, 10, PSTR("sensor%d"), sensor_no); if (mqtt_format_ == Mqtt::Format::SINGLE) { // e.g. sensor_data = {"sensor1":23.3,"sensor2":24.0} - if (Helpers::hasValue(device.temperature_c)) { - doc[sensorID] = (float)(device.temperature_c) / 10; + if (Helpers::hasValue(sensor.temperature_c)) { + doc[sensorID] = (float)(sensor.temperature_c) / 10; } - } else if (mqtt_format_ == Mqtt::Format::NESTED) { - // e.g. sensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":"23.3"},"sensor2":{"id":"28-233D-9497-0C03","temp":"24.0"}} + } else { + // e.g. sensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":23.3},"sensor2":{"id":"28-233D-9497-0C03","temp":24.0}} JsonObject dataSensor = doc.createNestedObject(sensorID); - dataSensor["id"] = device.to_string(); - if (Helpers::hasValue(device.temperature_c)) { - dataSensor["temp"] = (float)(device.temperature_c) / 10; + dataSensor["id"] = sensor.to_string(); + if (Helpers::hasValue(sensor.temperature_c)) { + dataSensor["temp"] = (float)(sensor.temperature_c) / 10; } - } else if (mqtt_format_ == Mqtt::Format::HA) { - // e.g. sensor_data = {"sensor1":{"id":"28-EA41-9497-0E03","temp":"23.3"},"sensor2":{"id":"28-233D-9497-0C03","temp":"24.0"}} - JsonObject dataSensor = doc.createNestedObject(sensorID); - dataSensor["id"] = device.to_string(); - if (Helpers::hasValue(device.temperature_c)) { - dataSensor["temp"] = (float)(device.temperature_c) / 10; - } - // create the config if this hasn't already been done - // to e.g. homeassistant/sensor/ems-esp/dallas_28-233D-9497-0C03/config + } + + // create the HA MQTT config + // to e.g. homeassistant/sensor/ems-esp/dallas_28-233D-9497-0C03/config + if (mqtt_format_ == Mqtt::Format::HA) { if (!(registered_ha_[sensor_no - 1])) { StaticJsonDocument config; config["dev_cla"] = F("temperature"); @@ -361,7 +358,7 @@ void Sensor::publish_values() { snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no); config["name"] = str; - snprintf_P(str, sizeof(str), PSTR("dallas_%s"), device.to_string().c_str()); + snprintf_P(str, sizeof(str), PSTR("dallas_%s"), sensor.to_string().c_str()); config["uniq_id"] = str; JsonObject dev = config.createNestedObject("dev"); @@ -369,7 +366,7 @@ void Sensor::publish_values() { ids.add("ems-esp"); std::string topic(100, '\0'); - snprintf_P(&topic[0], 100, PSTR("homeassistant/sensor/ems-esp/dallas_%s/config"), device.to_string().c_str()); + snprintf_P(&topic[0], 100, PSTR("homeassistant/sensor/ems-esp/dallas_%s/config"), sensor.to_string().c_str()); Mqtt::publish_retain(topic, config.as(), true); // publish the config payload with retain flag registered_ha_[sensor_no - 1] = true; @@ -378,6 +375,7 @@ void Sensor::publish_values() { sensor_no++; // increment sensor count } + doc.shrinkToFit(); Mqtt::publish(F("sensor_data"), doc.as()); } diff --git a/src/sensor.h b/src/dallassensor.h similarity index 91% rename from src/sensor.h rename to src/dallassensor.h index feb1ffcb4..06abd1816 100644 --- a/src/sensor.h +++ b/src/dallassensor.h @@ -18,8 +18,8 @@ // code originally written by nomis - https://github.com/nomis -#ifndef EMSESP_SENSOR_H -#define EMSESP_SENSOR_H +#ifndef EMSESP_DALLASSENSOR_H +#define EMSESP_DALLASSENSOR_H #include #include @@ -36,12 +36,12 @@ namespace emsesp { -class Sensor { +class DallasSensor { public: - class Device { + class Sensor { public: - Device(const uint8_t addr[]); - ~Device() = default; + Sensor(const uint8_t addr[]); + ~Sensor() = default; uint64_t id() const; std::string to_string() const; @@ -53,8 +53,8 @@ class Sensor { const uint64_t id_; }; - Sensor() = default; - ~Sensor() = default; + DallasSensor() = default; + ~DallasSensor() = default; void start(); void loop(); @@ -62,10 +62,7 @@ class Sensor { void reload(); bool updated_values(); - bool command_info(const char * value, const int8_t id, JsonObject & output); - bool export_values(JsonObject & doc); - - const std::vector devices() const; + const std::vector sensors() const; private: static constexpr uint8_t MAX_SENSORS = 20; @@ -104,10 +101,13 @@ class Sensor { int16_t get_temperature_c(const uint8_t addr[]); uint64_t get_id(const uint8_t addr[]); + bool command_info(const char * value, const int8_t id, JsonObject & output); + bool export_values(JsonObject & doc); + uint32_t last_activity_ = uuid::get_uptime(); uint32_t last_publish_ = uuid::get_uptime(); State state_ = State::IDLE; - std::vector devices_; + std::vector sensors_; bool registered_ha_[MAX_SENSORS]; diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index d5a5cb23f..d32f949de 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -28,7 +28,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i : EMSdevice(device_type, device_id, product_id, version, name, flags, brand) { uint8_t actual_master_thermostat = EMSESP::actual_master_thermostat(); // what we're actually using uint8_t master_thermostat = EMSESP_DEFAULT_MASTER_THERMOSTAT; - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { master_thermostat = settings.master_thermostat; // what the user has defined }); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 7c8d5dc72..8298a618c 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -23,20 +23,20 @@ namespace emsesp { AsyncWebServer webServer(80); #if defined(ESP32) -ESP8266React EMSESP::esp8266React(&webServer, &SPIFFS); -EMSESPSettingsService EMSESP::emsespSettingsService = EMSESPSettingsService(&webServer, &SPIFFS, EMSESP::esp8266React.getSecurityManager()); +ESP8266React EMSESP::esp8266React(&webServer, &SPIFFS); +WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &SPIFFS, EMSESP::esp8266React.getSecurityManager()); #elif defined(ESP8266) -ESP8266React EMSESP::esp8266React(&webServer, &LittleFS); -EMSESPSettingsService EMSESP::emsespSettingsService = EMSESPSettingsService(&webServer, &LittleFS, EMSESP::esp8266React.getSecurityManager()); +ESP8266React EMSESP::esp8266React(&webServer, &LittleFS); +WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &LittleFS, EMSESP::esp8266React.getSecurityManager()); #elif defined(EMSESP_STANDALONE) -FS dummyFS; -ESP8266React EMSESP::esp8266React(&webServer, &dummyFS); -EMSESPSettingsService EMSESP::emsespSettingsService = EMSESPSettingsService(&webServer, &dummyFS, EMSESP::esp8266React.getSecurityManager()); +FS dummyFS; +ESP8266React EMSESP::esp8266React(&webServer, &dummyFS); +WebSettingsService EMSESP::webSettingsService = WebSettingsService(&webServer, &dummyFS, EMSESP::esp8266React.getSecurityManager()); #endif -EMSESPStatusService EMSESP::emsespStatusService = EMSESPStatusService(&webServer, EMSESP::esp8266React.getSecurityManager()); -EMSESPDevicesService EMSESP::emsespDevicesService = EMSESPDevicesService(&webServer, EMSESP::esp8266React.getSecurityManager()); -EMSESPAPIService EMSESP::emsespAPIService = EMSESPAPIService(&webServer); +WebStatusService EMSESP::webStatusService = WebStatusService(&webServer, EMSESP::esp8266React.getSecurityManager()); +WebDevicesService EMSESP::webDevicesService = WebDevicesService(&webServer, EMSESP::esp8266React.getSecurityManager()); +WebAPIService EMSESP::webAPIService = WebAPIService(&webServer); using DeviceFlags = emsesp::EMSdevice; using DeviceType = emsesp::EMSdevice::DeviceType; @@ -46,13 +46,13 @@ std::vector EMSESP::device_library_; // libary of uuid::log::Logger EMSESP::logger_{F_(emsesp), uuid::log::Facility::KERN}; // The services -RxService EMSESP::rxservice_; // incoming Telegram Rx handler -TxService EMSESP::txservice_; // outgoing Telegram Tx handler -Mqtt EMSESP::mqtt_; // mqtt handler -System EMSESP::system_; // core system services -Console EMSESP::console_; // telnet and serial console -Sensor EMSESP::sensor_; // Dallas sensors -Shower EMSESP::shower_; // Shower logic +RxService EMSESP::rxservice_; // incoming Telegram Rx handler +TxService EMSESP::txservice_; // outgoing Telegram Tx handler +Mqtt EMSESP::mqtt_; // mqtt handler +System EMSESP::system_; // core system services +Console EMSESP::console_; // telnet and serial console +DallasSensor EMSESP::dallassensor_; // Dallas sensors +Shower EMSESP::shower_; // Shower logic // static/common variables uint8_t EMSESP::actual_master_thermostat_ = EMSESP_DEFAULT_MASTER_THERMOSTAT; // which thermostat leads when multiple found @@ -140,7 +140,7 @@ void EMSESP::watch_id(uint16_t watch_id) { // this is called when the tx_mode is persisted in the FS either via Web UI or the console void EMSESP::init_tx() { uint8_t tx_mode; - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { tx_mode = settings.tx_mode; #ifndef EMSESP_FORCE_SERIAL @@ -204,7 +204,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) { if (bus_status() != BUS_STATUS_OFFLINE) { shell.printfln(F("EMS Bus info:")); - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { shell.printfln(F(" Tx mode: %d"), settings.tx_mode); }); + EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.printfln(F(" Tx mode: %d"), settings.tx_mode); }); shell.printfln(F(" Bus protocol: %s"), EMSbus::is_ht3() ? F("HT3") : F("Buderus")); shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count()); shell.printfln(F(" #read requests sent: %d"), txservice_.telegram_read_count()); @@ -335,8 +335,8 @@ void EMSESP::publish_other_values() { } void EMSESP::publish_sensor_values(const bool force) { - if (sensor_.updated_values() || force) { - sensor_.publish_values(); + if (dallassensor_.updated_values() || force) { + dallassensor_.publish_values(); } } @@ -862,8 +862,8 @@ void EMSESP::start() { LittleFS.begin(); #endif - esp8266React.begin(); // loads system settings (wifi, mqtt, etc) - emsespSettingsService.begin(); // load EMS-ESP specific settings + esp8266React.begin(); // loads system settings (wifi, mqtt, etc) + webSettingsService.begin(); // load EMS-ESP specific settings } // Load our library of known devices. Names are stored in Flash mem. @@ -872,12 +872,12 @@ void EMSESP::start() { #include "device_library.h" }; - console_.start(); // telnet and serial console - mqtt_.start(); // mqtt init - system_.start(); // starts syslog, uart, sets version, initializes LED. Requires pre-loaded settings. - shower_.start(); // initialize shower timer and shower alert - sensor_.start(); // dallas external sensors - webServer.begin(); // start web server + console_.start(); // telnet and serial console + mqtt_.start(); // mqtt init + system_.start(); // starts syslog, uart, sets version, initializes LED. Requires pre-loaded settings. + shower_.start(); // initialize shower timer and shower alert + dallassensor_.start(); // dallas external sensors + webServer.begin(); // start web server emsdevices.reserve(5); // reserve space for initially 5 devices to avoid mem @@ -897,12 +897,12 @@ void EMSESP::loop() { return; } - system_.loop(); // does LED and checks system health, and syslog service - shower_.loop(); // check for shower on/off - sensor_.loop(); // this will also send out via MQTT - mqtt_.loop(); // sends out anything in the queue via MQTT - console_.loop(); // telnet/serial console - rxservice_.loop(); // process any incoming Rx telegrams + system_.loop(); // does LED and checks system health, and syslog service + shower_.loop(); // check for shower on/off + dallassensor_.loop(); // this will also send out via MQTT + mqtt_.loop(); // sends out anything in the queue via MQTT + console_.loop(); // telnet/serial console + rxservice_.loop(); // process any incoming Rx telegrams // force a query on the EMS devices to fetch latest data at a set interval (1 min) if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) { diff --git a/src/emsesp.h b/src/emsesp.h index b249b1ba3..409b1aeec 100644 --- a/src/emsesp.h +++ b/src/emsesp.h @@ -34,17 +34,17 @@ #endif #include -#include "EMSESPStatusService.h" -#include "EMSESPDevicesService.h" -#include "EMSESPSettingsService.h" -#include "EMSESPAPIService.h" +#include "WebStatusService.h" +#include "WebDevicesService.h" +#include "WebSettingsService.h" +#include "WebAPIService.h" #include "emsdevice.h" #include "emsfactory.h" #include "telegram.h" #include "mqtt.h" #include "system.h" -#include "sensor.h" +#include "dallassensor.h" #include "console.h" #include "shower.h" #include "roomcontrol.h" @@ -108,12 +108,12 @@ class EMSESP { static void incoming_telegram(uint8_t * data, const uint8_t length); - static const std::vector sensor_devices() { - return sensor_.devices(); + static const std::vector sensor_devices() { + return dallassensor_.sensors(); } static bool have_sensors() { - return (!(sensor_.devices().empty())); + return (!(dallassensor_.sensors().empty())); } enum Watch : uint8_t { WATCH_OFF, WATCH_ON, WATCH_RAW }; @@ -155,20 +155,20 @@ class EMSESP { static std::vector> emsdevices; // services - static Mqtt mqtt_; - static System system_; - static Sensor sensor_; - static Console console_; - static Shower shower_; - static RxService rxservice_; - static TxService txservice_; + static Mqtt mqtt_; + static System system_; + static DallasSensor dallassensor_; + static Console console_; + static Shower shower_; + static RxService rxservice_; + static TxService txservice_; // web controllers - static ESP8266React esp8266React; - static EMSESPSettingsService emsespSettingsService; - static EMSESPStatusService emsespStatusService; - static EMSESPDevicesService emsespDevicesService; - static EMSESPAPIService emsespAPIService; + static ESP8266React esp8266React; + static WebSettingsService webSettingsService; + static WebStatusService webStatusService; + static WebDevicesService webDevicesService; + static WebAPIService webAPIService; static uuid::log::Logger logger() { return logger_; @@ -203,8 +203,7 @@ class EMSESP { static uint16_t read_id_; static uint16_t publish_id_; static bool tap_water_active_; - - static uint8_t unique_id_count_; + static uint8_t unique_id_count_; }; } // namespace emsesp diff --git a/src/mqtt.cpp b/src/mqtt.cpp index d47bc82ff..a16240db2 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -706,7 +706,7 @@ void Mqtt::register_mqtt_ha_binary_sensor(const __FlashStringHelper * name, cons snprintf_P(state_t, sizeof(state_t), PSTR("%s/%s"), hostname_.c_str(), entity); doc["stat_t"] = state_t; - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { if (settings.bool_format == BOOL_FORMAT_ONOFF) { doc[F("payload_on")] = F("on"); doc[F("payload_off")] = F("off"); diff --git a/src/shower.cpp b/src/shower.cpp index 2747c6051..17f8bf8ff 100644 --- a/src/shower.cpp +++ b/src/shower.cpp @@ -23,7 +23,7 @@ namespace emsesp { uuid::log::Logger Shower::logger_{F_(shower), uuid::log::Facility::CONSOLE}; void Shower::start() { - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { shower_timer_ = settings.shower_timer; shower_alert_ = settings.shower_alert; }); diff --git a/src/system.cpp b/src/system.cpp index b580db381..65e9c2403 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -76,7 +76,7 @@ void System::wifi_reconnect() { LOG_NOTICE("The wifi will reconnect..."); Shell::loop_all(); delay(1000); // wait a second - EMSESP::emsespSettingsService.save(); // local settings + EMSESP::webSettingsService.save(); // local settings EMSESP::esp8266React.getWiFiSettingsService()->callUpdateHandlers("local"); // in case we've changed ssid or password } @@ -111,7 +111,7 @@ uint8_t System::free_mem() { void System::syslog_init() { // fetch settings - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { syslog_level_ = settings.syslog_level; syslog_mark_interval_ = settings.syslog_mark_interval; syslog_host_ = settings.syslog_host; @@ -148,7 +148,7 @@ void System::start() { [&](WiFiSettings & wifiSettings) { LOG_INFO(F("System %s booted (EMS-ESP version %s)"), wifiSettings.hostname.c_str(), EMSESP_APP_VERSION); }); // these commands respond to the topic "system" and take a payload like {cmd:"", data:"", id:""} - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F("pin"), System::command_pin); Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F("send"), System::command_send); Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F("info"), System::command_info); @@ -165,7 +165,7 @@ void System::init() { set_led(); // init LED // set the boolean format used for rendering booleans - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { Helpers::bool_format(settings.bool_format); analog_enabled_ = settings.analog_enabled; }); @@ -177,7 +177,7 @@ void System::init() { // set the LED to on or off when in normal operating mode void System::set_led() { - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { hide_led_ = settings.hide_led; led_gpio_ = settings.led_gpio; if (led_gpio_) { @@ -479,7 +479,7 @@ void System::show_system(uuid::console::Shell & shell) { break; } - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.println(); shell.printfln(F("Syslog:")); shell.print(F_(1space)); @@ -717,7 +717,7 @@ bool System::check_upgrade() { LittleFS.setConfig(l_cfg); LittleFS.begin(); EMSESP::esp8266React.begin(); - EMSESP::emsespSettingsService.begin(); + EMSESP::webSettingsService.begin(); EMSESP::esp8266React.getWiFiSettingsService()->update( [&](WiFiSettings & wifiSettings) { @@ -796,8 +796,8 @@ bool System::check_upgrade() { Serial.println(); #endif custom_settings = doc["settings"]; - EMSESP::emsespSettingsService.update( - [&](EMSESPSettings & settings) { + EMSESP::webSettingsService.update( + [&](WebSettings & settings) { settings.tx_mode = custom_settings["tx_mode"] | EMSESP_DEFAULT_TX_MODE; settings.shower_alert = custom_settings["shower_alert"] | EMSESP_DEFAULT_SHOWER_ALERT; settings.shower_timer = custom_settings["shower_timer"] | EMSESP_DEFAULT_SHOWER_TIMER; @@ -913,7 +913,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp // node["password"] = settings.password; }); - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { char s[7]; JsonObject node = output.createNestedObject("Settings"); node["tx_mode"] = settings.tx_mode; @@ -968,7 +968,7 @@ bool System::command_report(const char * value, const int8_t id, JsonObject & ou node["mqtt_retain"] = Helpers::render_boolean(s, settings.mqtt_retain); }); - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { char s[7]; node["tx_mode"] = settings.tx_mode; node["ems_bus_id"] = settings.ems_bus_id; diff --git a/src/telegram.cpp b/src/telegram.cpp index 1819882fc..e41d5cf3d 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -236,7 +236,7 @@ void TxService::flush_tx_queue() { // send out request to EMS bus for all devices void TxService::start() { // grab the bus ID and tx_mode - EMSESP::emsespSettingsService.read([&](EMSESPSettings & settings) { + EMSESP::webSettingsService.read([&](WebSettings & settings) { ems_bus_id(settings.ems_bus_id); tx_mode(settings.tx_mode); });