Add configurable device name API
This commit is contained in:
@@ -310,6 +310,12 @@ void handleDebugSerial() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.startsWith("devicename ")) {
|
||||
appConfig.deviceName = command.substring(11);
|
||||
Serial.println("OK device name updated");
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.startsWith("relayname ")) {
|
||||
int firstSpace = command.indexOf(' ');
|
||||
int secondSpace = command.indexOf(' ', firstSpace + 1);
|
||||
@@ -458,6 +464,22 @@ void handleGetConfig() {
|
||||
sendConfigJson();
|
||||
}
|
||||
|
||||
void handleUpdateDeviceConfig() {
|
||||
DynamicJsonDocument doc(512);
|
||||
DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
|
||||
if (error) {
|
||||
server.send(400, "application/json", "{\"ok\":false,\"error\":\"invalid_json\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (doc["device_name"].is<String>()) {
|
||||
appConfig.deviceName = doc["device_name"].as<String>();
|
||||
}
|
||||
|
||||
sendOkConfig();
|
||||
}
|
||||
|
||||
void handleUpdateRelayConfig() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
@@ -616,6 +638,7 @@ void setup() {
|
||||
server.on("/relay/relay_2/off", HTTP_GET, handleGenericRelayRoute);
|
||||
|
||||
server.on("/config", HTTP_GET, handleGetConfig);
|
||||
server.on("/config/device", HTTP_POST, handleUpdateDeviceConfig);
|
||||
server.on("/config/relay", HTTP_POST, handleUpdateRelayConfig);
|
||||
server.on("/config/bms", HTTP_POST, handleUpdateBmsConfig);
|
||||
server.on("/config/temp", HTTP_POST, handleUpdateTempSensorConfig);
|
||||
|
||||
Reference in New Issue
Block a user