dashboard: improve relay command responsiveness
This commit is contained in:
@@ -3829,6 +3829,8 @@ void handleSelectBms() {
|
||||
|
||||
|
||||
void handleSetRelayPost() {
|
||||
unsigned long startMs = millis();
|
||||
|
||||
DynamicJsonDocument doc(512);
|
||||
DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
|
||||
@@ -3840,20 +3842,34 @@ void handleSetRelayPost() {
|
||||
String relayId = doc["id"] | "";
|
||||
bool state = doc["state"] | false;
|
||||
|
||||
unsigned long applyStartMs = millis();
|
||||
if (!setRelayById(relayId, state)) {
|
||||
server.send(404, "application/json", "{\"ok\":false,\"error\":\"unknown_relay\"}");
|
||||
return;
|
||||
}
|
||||
unsigned long appliedMs = millis() - applyStartMs;
|
||||
|
||||
DynamicJsonDocument response(512);
|
||||
response["type"] = "relay_response";
|
||||
response["ok"] = true;
|
||||
response["id"] = relayId;
|
||||
response["state"] = state;
|
||||
response["applied_ms"] = appliedMs;
|
||||
response["total_ms"] = millis() - startMs;
|
||||
|
||||
String output;
|
||||
serializeJson(response, output);
|
||||
server.send(200, "application/json", output);
|
||||
|
||||
Serial.print("Relay ");
|
||||
Serial.print(relayId);
|
||||
Serial.print(" -> ");
|
||||
Serial.print(state ? "ON" : "OFF");
|
||||
Serial.print(" applied=");
|
||||
Serial.print(appliedMs);
|
||||
Serial.print("ms total=");
|
||||
Serial.print(millis() - startMs);
|
||||
Serial.println("ms");
|
||||
}
|
||||
|
||||
void handleGenericRelayRoute() {
|
||||
|
||||
Reference in New Issue
Block a user