Standardize API UART parity and update docs
This commit is contained in:
@@ -591,8 +591,8 @@ bool setRelayById(const String& relayId, bool enabled) {
|
||||
void sendRelayResponse(Stream& output, const String& relayId, bool enabled) {
|
||||
DynamicJsonDocument doc(256);
|
||||
doc["type"] = MSG_RELAY_RESPONSE;
|
||||
doc["relay"] = relayId;
|
||||
doc["enabled"] = enabled;
|
||||
doc["id"] = relayId;
|
||||
doc["state"] = enabled;
|
||||
doc["ok"] = true;
|
||||
serializeJson(doc, output);
|
||||
output.println();
|
||||
@@ -712,8 +712,15 @@ void handleUartMessage(const String& line) {
|
||||
}
|
||||
|
||||
if (strcmp(type, MSG_SET_RELAY) == 0 || strcmp(type, "set_relay") == 0) {
|
||||
String relayId = doc["relay"] | "";
|
||||
bool enabled = doc["enabled"] | false;
|
||||
String relayId = doc["id"] | "";
|
||||
if (relayId.length() == 0) {
|
||||
relayId = doc["relay"] | "";
|
||||
}
|
||||
|
||||
bool enabled = doc["state"] | false;
|
||||
if (doc["enabled"].is<bool>()) {
|
||||
enabled = doc["enabled"].as<bool>();
|
||||
}
|
||||
|
||||
if (!setRelayById(relayId, enabled)) {
|
||||
sendError(DashboardSerial, "unknown_relay");
|
||||
@@ -1631,9 +1638,8 @@ void handleSetRelayPost() {
|
||||
DynamicJsonDocument response(512);
|
||||
response["type"] = "relay_response";
|
||||
response["ok"] = true;
|
||||
response["relay"] = relayId;
|
||||
response["id"] = relayId;
|
||||
response["state"] = state;
|
||||
response["enabled"] = state;
|
||||
|
||||
String output;
|
||||
serializeJson(response, output);
|
||||
|
||||
Reference in New Issue
Block a user