Prevent config corruption by checking whether memory allocation was successfull. (onBattery)
This commit is contained in:
parent
d6d274f078
commit
d0e1da7b1d
@ -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_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_Lower_Power_Limit = root["lower_power_limit"].as<float>();
|
||||||
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
|
config.Huawei.Auto_Power_Upper_Power_Limit = root["upper_power_limit"].as<float>();
|
||||||
Configuration.write();
|
|
||||||
|
WebApi.writeConfig(retMsg);
|
||||||
retMsg["type"] = "success";
|
|
||||||
retMsg["message"] = "Settings saved!";
|
|
||||||
retMsg["code"] = WebApiError::GenericSuccess;
|
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
@ -108,11 +108,8 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
|
|||||||
config.Battery.JkBmsInterface = root["jkbms_interface"].as<uint8_t>();
|
config.Battery.JkBmsInterface = root["jkbms_interface"].as<uint8_t>();
|
||||||
config.Battery.JkBmsPollingInterval = root["jkbms_polling_interval"].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));
|
strlcpy(config.Battery.MqttTopic, root["mqtt_topic"].as<String>().c_str(), sizeof(config.Battery.MqttTopic));
|
||||||
Configuration.write();
|
|
||||||
|
WebApi.writeConfig(retMsg);
|
||||||
retMsg["type"] = "success";
|
|
||||||
retMsg["message"] = "Settings saved!";
|
|
||||||
retMsg["code"] = WebApiError::GenericSuccess;
|
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
@ -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.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;
|
config.PowerLimiter.FullSolarPassThroughStopVoltage = static_cast<int>(root["full_solar_passthrough_stop_voltage"].as<float>() * 100) / 100.0;
|
||||||
|
|
||||||
|
WebApi.writeConfig(retMsg);
|
||||||
|
|
||||||
Configuration.write();
|
|
||||||
|
|
||||||
PowerLimiter.calcNextInverterRestart();
|
|
||||||
|
|
||||||
retMsg["type"] = "success";
|
|
||||||
retMsg["message"] = "Settings saved!";
|
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
|
PowerLimiter.calcNextInverterRestart();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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));
|
strlcpy(config.PowerMeter.Http_Phase[i].JsonPath, phase["json_path"].as<String>().c_str(), sizeof(config.PowerMeter.Http_Phase[i].JsonPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration.write();
|
WebApi.writeConfig(retMsg);
|
||||||
|
|
||||||
retMsg["type"] = "success";
|
|
||||||
retMsg["message"] = "Settings saved!";
|
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
@ -115,14 +115,11 @@ void WebApiVedirectClass::onVedirectAdminPost(AsyncWebServerRequest* request)
|
|||||||
config.Vedirect.Enabled = root["vedirect_enabled"].as<bool>();
|
config.Vedirect.Enabled = root["vedirect_enabled"].as<bool>();
|
||||||
config.Vedirect.VerboseLogging = root["verbose_logging"].as<bool>();
|
config.Vedirect.VerboseLogging = root["verbose_logging"].as<bool>();
|
||||||
config.Vedirect.UpdatesOnly = root["vedirect_updatesonly"].as<bool>();
|
config.Vedirect.UpdatesOnly = root["vedirect_updatesonly"].as<bool>();
|
||||||
Configuration.write();
|
|
||||||
|
|
||||||
VictronMppt.updateSettings();
|
WebApi.writeConfig(retMsg);
|
||||||
|
|
||||||
retMsg["type"] = "success";
|
|
||||||
retMsg["message"] = "Settings saved!";
|
|
||||||
retMsg["code"] = WebApiError::GenericSuccess;
|
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|
||||||
|
VictronMppt.updateSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user