Add ESP32 alarms system status and debug commands
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include "relays.h"
|
||||
#include "sensors.h"
|
||||
#include "bms.h"
|
||||
#include "alarms.h"
|
||||
#include "system_status.h"
|
||||
|
||||
WebServer server(80);
|
||||
HardwareSerial DashboardSerial(2);
|
||||
@@ -56,6 +58,7 @@ void buildStatusDocument(JsonDocument& doc) {
|
||||
battery["cell_min_voltage"] = bmsData.cellMinVoltage;
|
||||
battery["cell_max_voltage"] = bmsData.cellMaxVoltage;
|
||||
battery["cell_delta_mv"] = bmsData.cellDeltaMv;
|
||||
battery["cells_valid"] = bmsData.cellsValid;
|
||||
} else {
|
||||
battery["source"] = "placeholder";
|
||||
battery["connected"] = false;
|
||||
@@ -113,6 +116,21 @@ void buildStatusDocument(JsonDocument& doc) {
|
||||
JsonObject network = doc.createNestedObject("network");
|
||||
network["wifi_enabled"] = true;
|
||||
network["uart_connected"] = true;
|
||||
|
||||
JsonObject alarmObj = doc.createNestedObject("alarms");
|
||||
alarmObj["low_soc"] = alarms.lowSoc;
|
||||
alarmObj["critical_soc"] = alarms.criticalSoc;
|
||||
alarmObj["low_voltage"] = alarms.lowVoltage;
|
||||
alarmObj["high_battery_temp"] = alarms.highBatteryTemp;
|
||||
alarmObj["cell_imbalance"] = alarms.cellImbalance;
|
||||
alarmObj["bms_disconnected"] = alarms.bmsDisconnected;
|
||||
|
||||
JsonObject system = doc.createNestedObject("system");
|
||||
system["firmware_name"] = FIRMWARE_NAME;
|
||||
system["firmware_version"] = FIRMWARE_VERSION;
|
||||
system["build_date"] = __DATE__;
|
||||
system["build_time"] = __TIME__;
|
||||
system["uptime_seconds"] = millis() / 1000;
|
||||
}
|
||||
|
||||
void sendStatus(Stream& output, bool pretty = false) {
|
||||
@@ -214,6 +232,51 @@ void pollDashboardUart() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handleDebugSerial() {
|
||||
if (!Serial.available()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String command = Serial.readStringUntil('\n');
|
||||
command.trim();
|
||||
|
||||
if (command == "status") {
|
||||
sendStatus(Serial, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "relay starlink on") {
|
||||
setRelayByName("starlink", true);
|
||||
Serial.println("OK starlink on");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "relay starlink off") {
|
||||
setRelayByName("starlink", false);
|
||||
Serial.println("OK starlink off");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "relay fridge on") {
|
||||
setRelayByName("fridge", true);
|
||||
Serial.println("OK fridge on");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == "relay fridge off") {
|
||||
setRelayByName("fridge", false);
|
||||
Serial.println("OK fridge off");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.length() > 0) {
|
||||
Serial.print("Unknown command: ");
|
||||
Serial.println(command);
|
||||
Serial.println("Commands: status, relay starlink on/off, relay fridge on/off");
|
||||
}
|
||||
}
|
||||
|
||||
void handleStatus() {
|
||||
DynamicJsonDocument doc(2048);
|
||||
buildStatusDocument(doc);
|
||||
@@ -305,7 +368,9 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
server.handleClient();
|
||||
handleDebugSerial();
|
||||
updateBms();
|
||||
updateAlarms();
|
||||
pollDashboardUart();
|
||||
|
||||
static unsigned long lastSensorUpdate = 0;
|
||||
|
||||
Reference in New Issue
Block a user