From 0687f05bc0804ba989090c44866d697d26309b32 Mon Sep 17 00:00:00 2001 From: Th3maz1ng Date: Sat, 11 Jun 2022 12:05:56 +0200 Subject: [PATCH] Removed a warning in the WEBServer.h file and added a new api endpoint to get the software version --- src/app/WEBServer.h | 2 +- src/app/app.ino | 1 + src/app/webApi.cpp | 14 ++++++++++++++ src/app/webApi.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/WEBServer.h b/src/app/WEBServer.h index 5cd8e3d..e674461 100644 --- a/src/app/WEBServer.h +++ b/src/app/WEBServer.h @@ -374,7 +374,7 @@ class WEBServer : public TCPServer, public HttpConstants //Parsing done! #if 1//def DEBUG_WEBS Serial.println("Post params :"); - for(int i = 0; i < client->_httpRequestData.postParams.count(); i++) + for(unsigned int i = 0; i < client->_httpRequestData.postParams.count(); i++) { Serial.print(client->_httpRequestData.postParams.getParameter(i));Serial.print(" : ");Serial.println(client->_httpRequestData.postParams.getAt(i)->getString()); } diff --git a/src/app/app.ino b/src/app/app.ino index cf75444..7c34ea5 100644 --- a/src/app/app.ino +++ b/src/app/app.ino @@ -94,6 +94,7 @@ void setup() sab.getWebServer().addApiRoutine("/sab/io/set/level", &(ioSetLevelApi), &sab, WEBServer::GET); sab.getWebServer().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &sab, WEBServer::GET); sab.getWebServer().addApiRoutine("/sab/io/set/mode", &(ioSetModeApi), &sab, WEBServer::GET); + sab.getWebServer().addApiRoutine("/sab/firmwareinfo", &(fwInfoApi), &sab, WEBServer::GET); sab.getWebServer().addApiRoutine("/sab/ota/update", &(otaUpdateApi), NULL, WEBServer::POST); sab.getIoManager().setISROnIOChange(&(ioISR), GPIO_3_RX); diff --git a/src/app/webApi.cpp b/src/app/webApi.cpp index 67a9493..946f259 100644 --- a/src/app/webApi.cpp +++ b/src/app/webApi.cpp @@ -560,6 +560,20 @@ boolean ioSetModeApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, return true; } +boolean fwInfoApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, void *pData) +{ + (void)HRD; + (void)pData; + + char buffer[100] = ""; + + sprintf(buffer ,"{\"status\":\"ok\",\"version\":\"%s\"}", SOFT_VERSION); + + WEBServer::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); + wc->print(buffer); + return true; +} + boolean otaUpdateApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, void *pData) { (void)HRD; diff --git a/src/app/webApi.h b/src/app/webApi.h index ce107fa..4fca7f3 100644 --- a/src/app/webApi.h +++ b/src/app/webApi.h @@ -30,6 +30,7 @@ boolean ioGetLevelApi(WEBServer::HttpRequestData&, WiFiClient*, void* boolean ioSetLevelApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean ioGetModeApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean ioSetModeApi(WEBServer::HttpRequestData&, WiFiClient*, void*); +boolean fwInfoApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean otaUpdateApi(WEBServer::HttpRequestData&, WiFiClient*, void*); #endif