dashboard: add temperature high alerts
This commit is contained in:
@@ -40,7 +40,9 @@ void loadDefaultConfig() {
|
||||
i < appConfig.tempSensorCount,
|
||||
false,
|
||||
"cabin",
|
||||
i + 1
|
||||
i + 1,
|
||||
false,
|
||||
90.0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,6 +113,14 @@ void loadConfig() {
|
||||
(prefix + "priority").c_str(),
|
||||
appConfig.tempSensors[i].priority
|
||||
);
|
||||
appConfig.tempSensors[i].highAlertEnabled = preferences.getBool(
|
||||
(prefix + "high_alert_enabled").c_str(),
|
||||
appConfig.tempSensors[i].highAlertEnabled
|
||||
);
|
||||
appConfig.tempSensors[i].highAlertF = preferences.getFloat(
|
||||
(prefix + "high_alert_f").c_str(),
|
||||
appConfig.tempSensors[i].highAlertF
|
||||
);
|
||||
}
|
||||
|
||||
appConfig.bms.enabled = preferences.getBool("bms_enabled", appConfig.bms.enabled);
|
||||
@@ -203,7 +213,11 @@ void printConfig() {
|
||||
Serial.print(" / group ");
|
||||
Serial.print(appConfig.tempSensors[i].group);
|
||||
Serial.print(" / priority ");
|
||||
Serial.println(appConfig.tempSensors[i].priority);
|
||||
Serial.print(appConfig.tempSensors[i].priority);
|
||||
Serial.print(" / high alert ");
|
||||
Serial.print(appConfig.tempSensors[i].highAlertEnabled ? "on" : "off");
|
||||
Serial.print(" @ ");
|
||||
Serial.println(appConfig.tempSensors[i].highAlertF);
|
||||
}
|
||||
|
||||
Serial.println(" BMS:");
|
||||
|
||||
@@ -24,6 +24,8 @@ struct TempSensorConfig {
|
||||
bool weather;
|
||||
String group;
|
||||
int priority;
|
||||
bool highAlertEnabled;
|
||||
float highAlertF;
|
||||
};
|
||||
|
||||
struct BmsConfig {
|
||||
|
||||
@@ -1196,6 +1196,14 @@ function renderConfigControls(data){
|
||||
<label class="inputHelp" for="tempPriority${i}">Priority</label>
|
||||
<input id="tempPriority${i}" type="number" min="1" max="99" step="1" placeholder="1" oninput="markConfigFieldTouched('tempPriority${i}')">
|
||||
|
||||
<div class="tempAlertConfig">
|
||||
<label class="tempCheck">
|
||||
<input id="tempHighAlertEnabled${i}" type="checkbox" onchange="markConfigFieldTouched('tempHighAlertEnabled${i}')">
|
||||
High Alert
|
||||
</label>
|
||||
<input id="tempHighAlertF${i}" type="number" min="-40" max="200" step="1" placeholder="90" oninput="markConfigFieldTouched('tempHighAlertF${i}')">
|
||||
</div>
|
||||
|
||||
<div class="tempConfigControls">
|
||||
<label class="tempCheck">
|
||||
<input id="tempEnabled${i}" type="checkbox" onchange="markConfigFieldTouched('tempEnabled${i}'); saveTempConfig()">
|
||||
@@ -1234,6 +1242,16 @@ function renderConfigControls(data){
|
||||
if(priority && !configTouched["tempPriority"+i] && document.activeElement!==priority){
|
||||
priority.value=t.priority||i+1;
|
||||
}
|
||||
|
||||
const highAlertEnabled=$("tempHighAlertEnabled"+i);
|
||||
if(highAlertEnabled && !configTouched["tempHighAlertEnabled"+i] && document.activeElement!==highAlertEnabled){
|
||||
highAlertEnabled.checked=!!t.high_alert_enabled;
|
||||
}
|
||||
|
||||
const highAlertF=$("tempHighAlertF"+i);
|
||||
if(highAlertF && !configTouched["tempHighAlertF"+i] && document.activeElement!==highAlertF){
|
||||
highAlertF.value=t.high_alert_f ?? 90;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1278,6 +1296,8 @@ async function saveTempConfig(){
|
||||
const weather=$("tempWeather"+i)?.checked || false;
|
||||
const group=$("tempGroup"+i)?.value || temps[i].group || "cabin";
|
||||
const priority=parseInt($("tempPriority"+i)?.value || temps[i].priority || (i+1),10);
|
||||
const highAlertEnabled=$("tempHighAlertEnabled"+i)?.checked || false;
|
||||
const highAlertF=parseFloat($("tempHighAlertF"+i)?.value || temps[i].high_alert_f || 90);
|
||||
|
||||
await fetch(api("/config/temp"),{
|
||||
method:"POST",
|
||||
@@ -1289,7 +1309,9 @@ async function saveTempConfig(){
|
||||
enabled:enabled,
|
||||
weather:weather,
|
||||
group:group,
|
||||
priority:priority
|
||||
priority:priority,
|
||||
high_alert_enabled:highAlertEnabled,
|
||||
high_alert_f:highAlertF
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -1299,7 +1321,7 @@ async function saveTempConfig(){
|
||||
alert("Temperature config saved");
|
||||
clearConfigTouched([
|
||||
"tempEnabledCount",
|
||||
...temps.flatMap((_,i)=>["tempName"+i,"tempEnabled"+i,"tempWeather"+i,"tempGroup"+i,"tempPriority"+i])
|
||||
...temps.flatMap((_,i)=>["tempName"+i,"tempEnabled"+i,"tempWeather"+i,"tempGroup"+i,"tempPriority"+i,"tempHighAlertEnabled"+i,"tempHighAlertF"+i])
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2029,6 +2051,8 @@ void buildConfigDocument(JsonObject doc) {
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
temp["high_alert_enabled"] = appConfig.tempSensors[i].highAlertEnabled;
|
||||
temp["high_alert_f"] = appConfig.tempSensors[i].highAlertF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2224,6 +2248,8 @@ void applyImportedConfig(JsonObject doc) {
|
||||
if (temp["weather"].is<bool>()) appConfig.tempSensors[index].weather = temp["weather"].as<bool>();
|
||||
if (temp["group"].is<String>()) appConfig.tempSensors[index].group = temp["group"].as<String>();
|
||||
if (temp["priority"].is<int>()) appConfig.tempSensors[index].priority = temp["priority"].as<int>();
|
||||
if (temp["high_alert_enabled"].is<bool>()) appConfig.tempSensors[index].highAlertEnabled = temp["high_alert_enabled"].as<bool>();
|
||||
if (temp["high_alert_f"].is<float>()) appConfig.tempSensors[index].highAlertF = temp["high_alert_f"].as<float>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2331,9 +2357,15 @@ void buildStatusDocument(JsonDocument& doc) {
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
temp["high_alert_enabled"] = appConfig.tempSensors[i].highAlertEnabled;
|
||||
temp["high_alert_f"] = appConfig.tempSensors[i].highAlertF;
|
||||
temp["online"] = sensors.online[i];
|
||||
if (sensors.online[i]) {
|
||||
temp["temperature_f"] = sensors.tempsF[i];
|
||||
temp["high_alert"] =
|
||||
appConfig.tempSensors[i].highAlertEnabled &&
|
||||
sensors.tempOnline[i] &&
|
||||
sensors.tempsF[i] > appConfig.tempSensors[i].highAlertF;
|
||||
} else {
|
||||
temp["temperature_f"] = nullptr;
|
||||
}
|
||||
@@ -2477,6 +2509,8 @@ void sendConfigResponse(Stream& output, bool ok = true) {
|
||||
temp["weather"] = appConfig.tempSensors[i].weather;
|
||||
temp["group"] = appConfig.tempSensors[i].group;
|
||||
temp["priority"] = appConfig.tempSensors[i].priority;
|
||||
temp["high_alert_enabled"] = appConfig.tempSensors[i].highAlertEnabled;
|
||||
temp["high_alert_f"] = appConfig.tempSensors[i].highAlertF;
|
||||
}
|
||||
|
||||
serializeJson(doc, output);
|
||||
@@ -3460,6 +3494,8 @@ void handleUpdateTempSensorConfig() {
|
||||
if (doc["weather"].is<bool>()) appConfig.tempSensors[index].weather = doc["weather"].as<bool>();
|
||||
if (doc["group"].is<String>()) appConfig.tempSensors[index].group = doc["group"].as<String>();
|
||||
if (doc["priority"].is<int>()) appConfig.tempSensors[index].priority = doc["priority"].as<int>();
|
||||
if (doc["high_alert_enabled"].is<bool>()) appConfig.tempSensors[index].highAlertEnabled = doc["high_alert_enabled"].as<bool>();
|
||||
if (doc["high_alert_f"].is<float>()) appConfig.tempSensors[index].highAlertF = doc["high_alert_f"].as<float>();
|
||||
|
||||
sendOkConfig();
|
||||
}
|
||||
@@ -3602,6 +3638,8 @@ void handleTempClear() {
|
||||
appConfig.tempSensors[i].weather = false;
|
||||
appConfig.tempSensors[i].group = "cabin";
|
||||
appConfig.tempSensors[i].priority = i + 1;
|
||||
appConfig.tempSensors[i].highAlertEnabled = false;
|
||||
appConfig.tempSensors[i].highAlertF = 90.0;
|
||||
sensors.tempsF[i] = -127.0;
|
||||
sensors.online[i] = false;
|
||||
}
|
||||
@@ -3640,6 +3678,8 @@ void handleTempClear() {
|
||||
appConfig.tempSensors[configIndex].weather = false;
|
||||
appConfig.tempSensors[configIndex].group = "cabin";
|
||||
appConfig.tempSensors[configIndex].priority = configIndex + 1;
|
||||
appConfig.tempSensors[configIndex].highAlertEnabled = false;
|
||||
appConfig.tempSensors[configIndex].highAlertF = 90.0;
|
||||
sensors.tempsF[configIndex] = -127.0;
|
||||
sensors.online[configIndex] = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user