Skip to content

Commit

Permalink
Prevent config corruption by checking whether memory allocation was s…
Browse files Browse the repository at this point in the history
…uccessfull. (onBattery)
  • Loading branch information
helgeerbe committed Jan 7, 2024
1 parent d6d274f commit d0e1da7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/WebApi_Huawei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,8 @@ void WebApiHuaweiClass::onAdminPost(AsyncWebServerRequest* request)
config.Huawei.Auto_Power_Enable_Voltage_Limit = root["enable_voltage_limit"].as<float>();
config.Huawei.Auto_Power_Lower_Power_Limit = root["lower_power_limit"].as<float>();
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
Configuration.write();

retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
retMsg["code"] = WebApiError::GenericSuccess;

WebApi.writeConfig(retMsg);

response->setLength();
request->send(response);
Expand Down
7 changes: 2 additions & 5 deletions src/WebApi_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
config.Battery.JkBmsInterface = root["jkbms_interface"].as<uint8_t>();
config.Battery.JkBmsPollingInterval = root["jkbms_polling_interval"].as<uint8_t>();
strlcpy(config.Battery.MqttTopic, root["mqtt_topic"].as<String>().c_str(), sizeof(config.Battery.MqttTopic));
Configuration.write();

retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
retMsg["code"] = WebApiError::GenericSuccess;

WebApi.writeConfig(retMsg);

response->setLength();
request->send(response);
Expand Down
11 changes: 3 additions & 8 deletions src/WebApi_powerlimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,10 @@ void WebApiPowerLimiterClass::onAdminPost(AsyncWebServerRequest* request)
config.PowerLimiter.FullSolarPassThroughStartVoltage = static_cast<int>(root["full_solar_passthrough_start_voltage"].as<float>() * 100) / 100.0;
config.PowerLimiter.FullSolarPassThroughStopVoltage = static_cast<int>(root["full_solar_passthrough_stop_voltage"].as<float>() * 100) / 100.0;



Configuration.write();

PowerLimiter.calcNextInverterRestart();

retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
WebApi.writeConfig(retMsg);

response->setLength();
request->send(response);

PowerLimiter.calcNextInverterRestart();
}
5 changes: 1 addition & 4 deletions src/WebApi_powermeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,7 @@ void WebApiPowerMeterClass::onAdminPost(AsyncWebServerRequest* request)
strlcpy(config.PowerMeter.Http_Phase[i].JsonPath, phase["json_path"].as<String>().c_str(), sizeof(config.PowerMeter.Http_Phase[i].JsonPath));
}

Configuration.write();

retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
WebApi.writeConfig(retMsg);

response->setLength();
request->send(response);
Expand Down
9 changes: 3 additions & 6 deletions src/WebApi_vedirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
config.Vedirect.Enabled = root["vedirect_enabled"].as<bool>();
config.Vedirect.VerboseLogging = root["verbose_logging"].as<bool>();
config.Vedirect.UpdatesOnly = root["vedirect_updatesonly"].as<bool>();
Configuration.write();

VictronMppt.updateSettings();

retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
retMsg["code"] = WebApiError::GenericSuccess;
WebApi.writeConfig(retMsg);

response->setLength();
request->send(response);

VictronMppt.updateSettings();
}

0 comments on commit d0e1da7

Please sign in to comment.