Merge branch 'api-configuration-endpoint' into 'master'
add esp32 reset via api See merge request jonasled/webresetter-server!4
This commit is contained in:
commit
70e62fcd50
1 changed files with 7 additions and 6 deletions
13
src/main.cpp
13
src/main.cpp
|
|
@ -206,6 +206,12 @@ void handleReset()
|
|||
|
||||
Serial.println("Resetting device " + String(deviceID));
|
||||
|
||||
if(deviceID == 0) {
|
||||
server.send(200, "application/json", "{\"status\": \"ok\"}");
|
||||
server.close();
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
digitalWrite(RS484_TRANSMIT_GPIO, HIGH);
|
||||
Serial1.write(deviceID);
|
||||
Serial1.write(7);
|
||||
|
|
@ -213,7 +219,6 @@ void handleReset()
|
|||
Serial1.flush();
|
||||
delay(2);
|
||||
digitalWrite(RS484_TRANSMIT_GPIO, LOW);
|
||||
server.send(200, "application/json", "{\"status\": \"ok\"}");
|
||||
}
|
||||
|
||||
void handleAddressChange()
|
||||
|
|
@ -277,8 +282,6 @@ void handleConfigurationGet()
|
|||
server.send(400, "text/plain", "Bad request");
|
||||
return;
|
||||
}
|
||||
int deviceID = doc["deviceID"];
|
||||
int newDelay = doc["delay"];
|
||||
String providedApiKey = doc["apikey"];
|
||||
if (apikey != providedApiKey)
|
||||
{
|
||||
|
|
@ -303,15 +306,13 @@ void handleConfigurationSet()
|
|||
return;
|
||||
}
|
||||
// parse post body as json
|
||||
StaticJsonDocument<200> doc;
|
||||
StaticJsonDocument<500> doc;
|
||||
DeserializationError error = deserializeJson(doc, server.arg("plain"));
|
||||
if (error)
|
||||
{
|
||||
server.send(400, "text/plain", "Bad request");
|
||||
return;
|
||||
}
|
||||
int deviceID = doc["deviceID"];
|
||||
int newDelay = doc["delay"];
|
||||
String providedApiKey = doc["currentApikey"];
|
||||
doc.remove("currentApikey");
|
||||
if (apikey != providedApiKey)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue