new state endpoint

This commit is contained in:
Matthew Frost 2023-06-13 17:09:48 +02:00
parent a8b7891fe3
commit 4b4e9d87a0
3 changed files with 23 additions and 0 deletions

View file

@ -33,4 +33,5 @@
void unlockDoor(bool silent);
void lockDoor();
void toggleDoor();
String stateDoor();
#endif

View file

@ -56,3 +56,15 @@ void toggleDoor() {
#endif
}
String stateDoor() {
#ifdef RELAY1
int relayState = digitalRead(RELAY1_PIN);
// Toggle the relay based on the current state
if (relayState == LOW) {
return "Unlocked";
} else {
return "Locked";
}
#endif
}

View file

@ -337,6 +337,16 @@ void setup() {
request->send(200, "application/json", "{\"msg\":\"The content you are looking for was not found\"}");
});
#ifdef RELAY1
server.on("/state/relay1", HTTP_GET, [] (AsyncWebServerRequest *request) {
if(!request->authenticate(http_username, http_password))
return request->requestAuthentication();
AsyncWebServerResponse *response = request->beginResponse(200, "application/json", "{\"state\":\""+stateDoor()+"\"}");
request->send(response);
});
#endif
// Send a GET request to <ESP_IP>/gpio?output=<paramOutput>&state=<paramState>
server.on("/gpio", HTTP_GET, [] (AsyncWebServerRequest *request) {
String paramOutput;