diff --git a/platformio.ini b/platformio.ini index a071319..475b250 100644 --- a/platformio.ini +++ b/platformio.ini @@ -63,7 +63,7 @@ lib_deps = mathieucarbou/AsyncTCP @ 3.2.14 ; https://github.com/mathieucarbou/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip mathieucarbou/ESPAsyncWebServer @ 3.3.22 - mathieucarbou/MycilaConfig @ 6.0.4 + mathieucarbou/MycilaConfig @ 7.0.3 mathieucarbou/MycilaDS18 @ 4.1.1 mathieucarbou/MycilaESPConnect @ 7.0.0 mathieucarbou/MycilaEasyDisplay @ 3.0.2 diff --git a/src/Website.cpp b/src/Website.cpp index 8b000cb..f3a0d73 100644 --- a/src/Website.cpp +++ b/src/Website.cpp @@ -4,8 +4,8 @@ */ #include -#include #include +#include #define HIDDEN_PWD "********" @@ -55,8 +55,8 @@ void YaSolR::WebsiteClass::initLayout() { config.set(KEY_OUTPUT2_DIMMER_LIMIT, "100", false); router.beginCalibration([]() { - config.set(KEY_OUTPUT1_RESISTANCE, Mycila::string::to_string(router.getOutputs()[0]->config.calibratedResistance, 2).c_str()); - config.set(KEY_OUTPUT2_RESISTANCE, Mycila::string::to_string(router.getOutputs()[1]->config.calibratedResistance, 2).c_str()); + config.set(KEY_OUTPUT1_RESISTANCE, Mycila::string::to_string(router.getOutputs()[0]->config.calibratedResistance, 2)); + config.set(KEY_OUTPUT2_RESISTANCE, Mycila::string::to_string(router.getOutputs()[1]->config.calibratedResistance, 2)); }); YaSolR::Website.initCards(); @@ -393,7 +393,7 @@ void YaSolR::WebsiteClass::initLayout() { _output1DimmerMapper.attachCallback([this](const char* value) { const char* comma = strchr(value, ','); if (comma != nullptr) { - config.set(KEY_OUTPUT1_DIMMER_MIN, std::string(value, comma - value).c_str()); + config.set(KEY_OUTPUT1_DIMMER_MIN, std::string(value, comma - value)); config.set(KEY_OUTPUT1_DIMMER_MAX, comma + 1); } _output1DimmerMapper.update(value); @@ -402,7 +402,7 @@ void YaSolR::WebsiteClass::initLayout() { _output2DimmerMapper.attachCallback([this](const char* value) { const char* comma = strchr(value, ','); if (comma != nullptr) { - config.set(KEY_OUTPUT2_DIMMER_MIN, std::string(value, comma - value).c_str()); + config.set(KEY_OUTPUT2_DIMMER_MIN, std::string(value, comma - value)); config.set(KEY_OUTPUT2_DIMMER_MAX, comma + 1); } _output2DimmerMapper.update(value); @@ -671,7 +671,7 @@ void YaSolR::WebsiteClass::initCards() { _displayType.update(config.get(KEY_DISPLAY_TYPE), "SH1106,SH1107,SSD1306"); _displaySpeed.update(config.getInt(KEY_DISPLAY_SPEED)); - _displayRotation.update((std::string(config.get(KEY_DISPLAY_ROTATION)) + "°").c_str(), "0°,90°,180°,270°"); + _displayRotation.update((config.getString(KEY_DISPLAY_ROTATION) + "°").c_str(), "0°,90°,180°,270°"); _output1RelayType.update(config.get(KEY_OUTPUT1_RELAY_TYPE), "NO,NC"); _output2RelayType.update(config.get(KEY_OUTPUT2_RELAY_TYPE), "NO,NC"); _relay1Type.update(config.get(KEY_RELAY1_TYPE), "NO,NC"); @@ -680,8 +680,8 @@ void YaSolR::WebsiteClass::initCards() { _relay2Load.update(load2); _output1ResistanceInput.update(config.get(KEY_OUTPUT1_RESISTANCE), config.getFloat(KEY_OUTPUT1_RESISTANCE) == 0 ? DASH_STATUS_DANGER : DASH_STATUS_SUCCESS); _output2ResistanceInput.update(config.get(KEY_OUTPUT2_RESISTANCE), config.getFloat(KEY_OUTPUT2_RESISTANCE) == 0 ? DASH_STATUS_DANGER : DASH_STATUS_SUCCESS); - _output1DimmerMapper.update((std::string(config.get(KEY_OUTPUT1_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT1_DIMMER_MAX)).c_str()); - _output2DimmerMapper.update((std::string(config.get(KEY_OUTPUT2_DIMMER_MIN)) + "," + config.get(KEY_OUTPUT2_DIMMER_MAX)).c_str()); + _output1DimmerMapper.update((config.getString(KEY_OUTPUT1_DIMMER_MIN) + "," + config.get(KEY_OUTPUT1_DIMMER_MAX)).c_str()); + _output2DimmerMapper.update((config.getString(KEY_OUTPUT2_DIMMER_MIN) + "," + config.get(KEY_OUTPUT2_DIMMER_MAX)).c_str()); _displayType.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); _displaySpeed.setDisplay(config.getBool(KEY_ENABLE_DISPLAY)); @@ -991,7 +991,7 @@ void YaSolR::WebsiteClass::resetPID() { void YaSolR::WebsiteClass::_sliderConfig(Card& card, const char* key) { card.attachCallback([key, &card](int value) { - config.set(key, std::to_string(value).c_str()); + config.set(key, std::to_string(value)); card.update(config.getInt(key)); dashboard.refreshCard(&card); }); @@ -999,7 +999,7 @@ void YaSolR::WebsiteClass::_sliderConfig(Card& card, const char* key) { void YaSolR::WebsiteClass::_percentageSlider(Card& card, const char* key) { card.attachCallback([key, &card](int value) { - config.set(key, std::to_string(value).c_str()); + config.set(key, std::to_string(value)); card.update(value); dashboard.refreshCard(&card); }); @@ -1023,7 +1023,7 @@ void YaSolR::WebsiteClass::_numConfig(Card& card, const char* key) { #ifdef APP_MODEL_PRO card.attachCallback([key, &card](const char* value) { if (value[0]) { - config.set(key, std::to_string(strtol(value, nullptr, 10)).c_str()); + config.set(key, std::to_string(strtol(value, nullptr, 10))); } else { config.unset(key); } @@ -1037,7 +1037,7 @@ void YaSolR::WebsiteClass::_pinConfig(Card& card, const char* key) { #ifdef APP_MODEL_PRO card.attachCallback([key, &card, this](const char* value) { if (value[0]) { - config.set(key, std::to_string(strtol(value, nullptr, 10)).c_str()); + config.set(key, std::to_string(strtol(value, nullptr, 10))); } else { config.unset(key); } diff --git a/src/init/Boot.cpp b/src/init/Boot.cpp index 63d4023..51a427c 100644 --- a/src/init/Boot.cpp +++ b/src/init/Boot.cpp @@ -66,7 +66,7 @@ Mycila::Task bootTask("Boot", [](void* params) { config.configure(KEY_MQTT_PUBLISH_INTERVAL, "5"); config.configure(KEY_MQTT_SECURED, YASOLR_FALSE); config.configure(KEY_MQTT_SERVER); - config.configure(KEY_MQTT_TOPIC, Mycila::AppInfo.defaultMqttClientId.c_str()); + config.configure(KEY_MQTT_TOPIC, Mycila::AppInfo.defaultMqttClientId); config.configure(KEY_MQTT_USERNAME); config.configure(KEY_NET_DNS); config.configure(KEY_NET_GATEWAY); @@ -109,30 +109,30 @@ Mycila::Task bootTask("Boot", [](void* params) { config.configure(KEY_PID_OUT_MIN, "-1000"); config.configure(KEY_PID_P_MODE, "2"); config.configure(KEY_PID_SETPOINT, "0"); - config.configure(KEY_PIN_DISPLAY_SCL, std::to_string(YASOLR_DISPLAY_CLOCK_PIN).c_str()); - config.configure(KEY_PIN_DISPLAY_SDA, std::to_string(YASOLR_DISPLAY_DATA_PIN).c_str()); - config.configure(KEY_PIN_JSY_RX, std::to_string(YASOLR_JSY_RX_PIN).c_str()); - config.configure(KEY_PIN_JSY_TX, std::to_string(YASOLR_JSY_TX_PIN).c_str()); - config.configure(KEY_PIN_LIGHTS_GREEN, std::to_string(YASOLR_LIGHTS_GREEN_PIN).c_str()); - config.configure(KEY_PIN_LIGHTS_RED, std::to_string(YASOLR_LIGHTS_RED_PIN).c_str()); - config.configure(KEY_PIN_LIGHTS_YELLOW, std::to_string(YASOLR_LIGHTS_YELLOW_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT1_DIMMER, std::to_string(YASOLR_OUTPUT1_DIMMER_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT1_DS18, std::to_string(YASOLR_OUTPUT1_TEMP_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT1_RELAY, std::to_string(YASOLR_OUTPUT1_RELAY_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT2_DIMMER, std::to_string(YASOLR_OUTPUT2_DIMMER_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT2_DS18, std::to_string(YASOLR_OUTPUT2_TEMP_PIN).c_str()); - config.configure(KEY_PIN_OUTPUT2_RELAY, std::to_string(YASOLR_OUTPUT2_RELAY_PIN).c_str()); - config.configure(KEY_PIN_PZEM_RX, std::to_string(YASOLR_PZEM_RX_PIN).c_str()); - config.configure(KEY_PIN_PZEM_TX, std::to_string(YASOLR_PZEM_TX_PIN).c_str()); - config.configure(KEY_PIN_RELAY1, std::to_string(YASOLR_RELAY1_PIN).c_str()); - config.configure(KEY_PIN_RELAY2, std::to_string(YASOLR_RELAY2_PIN).c_str()); - config.configure(KEY_PIN_ROUTER_DS18, std::to_string(YASOLR_SYSTEM_TEMP_PIN).c_str()); - config.configure(KEY_PIN_ZCD, std::to_string(YASOLR_ZCD_PIN).c_str()); + config.configure(KEY_PIN_DISPLAY_SCL, std::to_string(YASOLR_DISPLAY_CLOCK_PIN)); + config.configure(KEY_PIN_DISPLAY_SDA, std::to_string(YASOLR_DISPLAY_DATA_PIN)); + config.configure(KEY_PIN_JSY_RX, std::to_string(YASOLR_JSY_RX_PIN)); + config.configure(KEY_PIN_JSY_TX, std::to_string(YASOLR_JSY_TX_PIN)); + config.configure(KEY_PIN_LIGHTS_GREEN, std::to_string(YASOLR_LIGHTS_GREEN_PIN)); + config.configure(KEY_PIN_LIGHTS_RED, std::to_string(YASOLR_LIGHTS_RED_PIN)); + config.configure(KEY_PIN_LIGHTS_YELLOW, std::to_string(YASOLR_LIGHTS_YELLOW_PIN)); + config.configure(KEY_PIN_OUTPUT1_DIMMER, std::to_string(YASOLR_OUTPUT1_DIMMER_PIN)); + config.configure(KEY_PIN_OUTPUT1_DS18, std::to_string(YASOLR_OUTPUT1_TEMP_PIN)); + config.configure(KEY_PIN_OUTPUT1_RELAY, std::to_string(YASOLR_OUTPUT1_RELAY_PIN)); + config.configure(KEY_PIN_OUTPUT2_DIMMER, std::to_string(YASOLR_OUTPUT2_DIMMER_PIN)); + config.configure(KEY_PIN_OUTPUT2_DS18, std::to_string(YASOLR_OUTPUT2_TEMP_PIN)); + config.configure(KEY_PIN_OUTPUT2_RELAY, std::to_string(YASOLR_OUTPUT2_RELAY_PIN)); + config.configure(KEY_PIN_PZEM_RX, std::to_string(YASOLR_PZEM_RX_PIN)); + config.configure(KEY_PIN_PZEM_TX, std::to_string(YASOLR_PZEM_TX_PIN)); + config.configure(KEY_PIN_RELAY1, std::to_string(YASOLR_RELAY1_PIN)); + config.configure(KEY_PIN_RELAY2, std::to_string(YASOLR_RELAY2_PIN)); + config.configure(KEY_PIN_ROUTER_DS18, std::to_string(YASOLR_SYSTEM_TEMP_PIN)); + config.configure(KEY_PIN_ZCD, std::to_string(YASOLR_ZCD_PIN)); config.configure(KEY_RELAY1_LOAD, "0"); config.configure(KEY_RELAY1_TYPE, YASOLR_RELAY_TYPE_NO); config.configure(KEY_RELAY2_LOAD, "0"); config.configure(KEY_RELAY2_TYPE, YASOLR_RELAY_TYPE_NO); - config.configure(KEY_UDP_PORT, std::to_string(YASOLR_UDP_PORT).c_str()); + config.configure(KEY_UDP_PORT, std::to_string(YASOLR_UDP_PORT)); config.configure(KEY_WIFI_PASSWORD); config.configure(KEY_WIFI_SSID); diff --git a/src/init/Config.cpp b/src/init/Config.cpp index dc7cff0..57c8a7a 100644 --- a/src/init/Config.cpp +++ b/src/init/Config.cpp @@ -107,11 +107,11 @@ Mycila::Task initConfigTask("Init Config", [](void* params) { haDiscovery.setDiscoveryTopic(config.get(KEY_HA_DISCOVERY_TOPIC)); haDiscovery.setWillTopic((std::string(config.get(KEY_MQTT_TOPIC)) + YASOLR_MQTT_WILL_TOPIC).c_str()); haDiscovery.begin({ - .id = Mycila::AppInfo.defaultMqttClientId.c_str(), - .name = Mycila::AppInfo.defaultSSID.c_str(), - .version = Mycila::AppInfo.version.c_str(), - .model = (Mycila::AppInfo.name + " " + Mycila::AppInfo.model).c_str(), - .manufacturer = Mycila::AppInfo.manufacturer.c_str(), + .id = Mycila::AppInfo.defaultMqttClientId, + .name = Mycila::AppInfo.defaultSSID, + .version = Mycila::AppInfo.version, + .model = Mycila::AppInfo.name + " " + Mycila::AppInfo.model, + .manufacturer = Mycila::AppInfo.manufacturer, .url = std::string("http://") + espConnect.getIPAddress().toString().c_str(), }, config.get(KEY_MQTT_TOPIC), @@ -157,7 +157,7 @@ Mycila::Task initConfigTask("Init Config", [](void* params) { // Display if (config.getBool(KEY_ENABLE_DISPLAY)) { - const std::string displayType = config.get(KEY_DISPLAY_TYPE); + const std::string& displayType = config.getString(KEY_DISPLAY_TYPE); if (displayType == "SSD1306") display.begin(Mycila::EasyDisplayType::SSD1306, config.getLong(KEY_PIN_DISPLAY_SCL), config.getLong(KEY_PIN_DISPLAY_SDA), config.getLong(KEY_DISPLAY_ROTATION)); else if (displayType == "SH1107") diff --git a/src/init/Events.cpp b/src/init/Events.cpp index b8f14e5..57dab39 100644 --- a/src/init/Events.cpp +++ b/src/init/Events.cpp @@ -23,8 +23,8 @@ Mycila::Task initEventsTask("Init Events", [](void* params) { restartTask.resume(); }); - config.listen([](const char* k, const char* newValue) { - logger.info(TAG, "'%s' => '%s'", k, newValue); + config.listen([](const char* k, const std::string& newValue) { + logger.info(TAG, "'%s' => '%s'", k, newValue.c_str()); const std::string key = k; if (key == KEY_ENABLE_DEBUG) { @@ -199,7 +199,7 @@ Mycila::Task initEventsTask("Init Events", [](void* params) { } else if (key == KEY_ENABLE_DISPLAY) { display.end(); if (config.getBool(KEY_ENABLE_DISPLAY)) { - const std::string displayType = config.get(KEY_DISPLAY_TYPE); + const std::string& displayType = config.getString(KEY_DISPLAY_TYPE); if (displayType == "SSD1306") display.begin(Mycila::EasyDisplayType::SSD1306, config.getLong(KEY_PIN_DISPLAY_SCL), config.getLong(KEY_PIN_DISPLAY_SDA), config.getLong(KEY_DISPLAY_ROTATION)); else if (displayType == "SH1107") @@ -274,8 +274,8 @@ Mycila::Task initEventsTask("Init Events", [](void* params) { } else { logger.info(TAG, "Captive Portal: WiFi configured"); config.setBool(KEY_ENABLE_AP_MODE, false); - config.set(KEY_WIFI_SSID, espConnect.getConfiguredWiFiSSID().c_str()); - config.set(KEY_WIFI_PASSWORD, espConnect.getConfiguredWiFiPassword().c_str()); + config.set(KEY_WIFI_SSID, espConnect.getConfiguredWiFiSSID()); + config.set(KEY_WIFI_PASSWORD, espConnect.getConfiguredWiFiPassword()); } break; } diff --git a/src/init/MQTT.cpp b/src/init/MQTT.cpp index 70ce3f2..1f5696f 100644 --- a/src/init/MQTT.cpp +++ b/src/init/MQTT.cpp @@ -9,7 +9,7 @@ Mycila::Task initMqttSubscribersTask("Init MQTT Subscribers", [](void* params) { logger.info(TAG, "Initializing MQTT Subscribers"); - const std::string baseTopic = config.get(KEY_MQTT_TOPIC); + const std::string& baseTopic = config.getString(KEY_MQTT_TOPIC); // config @@ -20,7 +20,7 @@ Mycila::Task initMqttSubscribersTask("Init MQTT Subscribers", [](void* params) { const std::size_t start = topic.rfind("/", end - 1); const char* key = config.keyRef(topic.substr(start + 1, end - start - 1).c_str()); if (key) - config.set(key, payload.c_str()); + config.set(key, payload); }); // relays diff --git a/src/tasks/MQTT.cpp b/src/tasks/MQTT.cpp index 0478597..8ec4c7b 100644 --- a/src/tasks/MQTT.cpp +++ b/src/tasks/MQTT.cpp @@ -15,13 +15,13 @@ Mycila::Task mqttConfigTask("MQTT Config", Mycila::TaskType::ONCE, [](void* para bool secured = config.getBool(KEY_MQTT_SECURED); Mycila::MQTT::Config mqttConfig; - mqttConfig.server = config.get(KEY_MQTT_SERVER); + mqttConfig.server = config.getString(KEY_MQTT_SERVER); mqttConfig.port = static_cast(config.getLong(KEY_MQTT_PORT)); mqttConfig.secured = secured; - mqttConfig.username = config.get(KEY_MQTT_USERNAME); - mqttConfig.password = config.get(KEY_MQTT_PASSWORD); - mqttConfig.clientId = Mycila::AppInfo.defaultMqttClientId.c_str(); - mqttConfig.willTopic = std::string(config.get(KEY_MQTT_TOPIC)) + YASOLR_MQTT_WILL_TOPIC; + mqttConfig.username = config.getString(KEY_MQTT_USERNAME); + mqttConfig.password = config.getString(KEY_MQTT_PASSWORD); + mqttConfig.clientId = Mycila::AppInfo.defaultMqttClientId; + mqttConfig.willTopic = config.getString(KEY_MQTT_TOPIC) + YASOLR_MQTT_WILL_TOPIC; mqttConfig.keepAlive = YASOLR_MQTT_KEEPALIVE; if (secured) { @@ -48,7 +48,7 @@ Mycila::Task mqttConfigTask("MQTT Config", Mycila::TaskType::ONCE, [](void* para Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](void* params) { logger.debug(TAG, "Publishing static data to MQTT"); - const std::string baseTopic = config.get(KEY_MQTT_TOPIC); + const std::string& baseTopic = config.getString(KEY_MQTT_TOPIC); mqtt.publish((baseTopic + "/system/app/manufacturer").c_str(), Mycila::AppInfo.manufacturer.c_str(), true); mqtt.publish((baseTopic + "/system/app/model").c_str(), Mycila::AppInfo.model.c_str(), true); @@ -79,7 +79,7 @@ Mycila::Task mqttPublishStaticTask("MQTT Static", Mycila::TaskType::ONCE, [](voi Mycila::Task mqttPublishConfigTask("MQTT Config", Mycila::TaskType::ONCE, [](void* params) { logger.debug(TAG, "Publishing config to MQTT"); - const std::string baseTopic = config.get(KEY_MQTT_TOPIC); + const std::string& baseTopic = config.getString(KEY_MQTT_TOPIC); for (auto& key : config.keys()) { const char* value = config.get(key); @@ -90,7 +90,7 @@ Mycila::Task mqttPublishConfigTask("MQTT Config", Mycila::TaskType::ONCE, [](voi }); Mycila::Task mqttPublishTask("MQTT", [](void* params) { - const std::string baseTopic = config.get(KEY_MQTT_TOPIC); + const std::string& baseTopic = config.getString(KEY_MQTT_TOPIC); Mycila::System::Memory memory; Mycila::System::getMemory(memory);