Skip to content

Commit

Permalink
mathieucarbou/MycilaConfig @ 7.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Nov 14, 2024
1 parent e28765b commit e3f884d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/Website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
#include <YaSolRWebsite.h>

#include <unordered_map>
#include <string>
#include <unordered_map>

#define HIDDEN_PWD "********"

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand Down Expand Up @@ -991,15 +991,15 @@ 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);
});
}

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);
});
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
42 changes: 21 additions & 21 deletions src/init/Boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/init/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions src/init/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/init/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/tasks/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e3f884d

Please sign in to comment.