Updated all the webApi functions signatures because of the callback

prototype update. Added the CORS policy : Access-Control-Allow-Origin: *
to be able to make JS ajax requets without getting rejected.
This commit is contained in:
anschrammh 2022-10-17 23:57:10 +02:00
parent c9ead83204
commit 785df2ac11
4 changed files with 68 additions and 67 deletions

View File

@ -104,7 +104,6 @@ class WEBServer : public TCPServer<T>, public HttpConstants
{ {
client->printf("\r\n%s: %s", _httpHeadersDictionary.getParameter(i), _httpHeadersDictionary.getAt(i) ? _httpHeadersDictionary.getAt(i)->getString() : ""); client->printf("\r\n%s: %s", _httpHeadersDictionary.getParameter(i), _httpHeadersDictionary.getAt(i) ? _httpHeadersDictionary.getAt(i)->getString() : "");
} }
//client->print("\r\nAccess-Control-Allow-Origin: *");
client->print("\r\n\r\n"); client->print("\r\n\r\n");
} }

View File

@ -74,6 +74,8 @@ void setup()
sab.getRtcManager().setDateTime(sab.getRTC_DS3231().now()); sab.getRtcManager().setDateTime(sab.getRTC_DS3231().now());
} }
sab.getWebServerManager().getWEBServer().addHttpHeader("Access-Control-Allow-Origin", "*");
sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/web/apitester", &(apiTesterApi), NULL); sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/web/apitester", &(apiTesterApi), NULL);
sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/view/next", &(nextViewApi), &sab, WEBServer<WEBClient>::GET); sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/view/next", &(nextViewApi), &sab, WEBServer<WEBClient>::GET);
sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/view/reloadcfg", &(reloadViewApi), &sab, WEBServer<WEBClient>::GET); sab.getWebServerManager().getWEBServer().addApiRoutine("/sab/view/reloadcfg", &(reloadViewApi), &sab, WEBServer<WEBClient>::GET);

View File

@ -2,18 +2,18 @@
#include "webApi.h" #include "webApi.h"
#include "tasks.h" #include "tasks.h"
boolean apiTesterApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient* wc, void* pData) boolean apiTesterApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient* wc, void* pData)
{ {
(void)HRD; (void)HRD;
(void)pData; (void)pData;
char buffer[] = "{\"status\":\"ok\",\"API\":\"available\"}"; char buffer[] = "{\"status\":\"ok\",\"API\":\"available\"}";
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean viewByUIDApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean viewByUIDApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[200]; char buffer[200];
@ -33,12 +33,12 @@ boolean viewByUIDApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
else else
strcpy(buffer, "{\"status\":\"failed\",\"message\":\"UID parameter empty\"}"); strcpy(buffer, "{\"status\":\"failed\",\"message\":\"UID parameter empty\"}");
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean nextViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean nextViewApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -49,12 +49,12 @@ boolean nextViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
else else
sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage()); sprintf(buffer, "{\"status\":\"failed\",\"message\":\"%s\"}", p->getScreenManager().getErrorMessage());
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean reloadViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean reloadViewApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -65,12 +65,12 @@ boolean reloadViewApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
else else
strcpy(buffer, "{\"status\":\"failed\",\"message\":\"unable to reload config\"}"); strcpy(buffer, "{\"status\":\"failed\",\"message\":\"unable to reload config\"}");
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean rtcGetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean rtcGetTimeApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -78,13 +78,13 @@ boolean rtcGetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
DateTime d = p->getRtcManager().getDateTime(); DateTime d = p->getRtcManager().getDateTime();
sprintf(buffer, "{\"status\":\"ok\",\"date\":\"%d/%d/%d\",\"time\":\"%d:%d:%d\"}", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second()); sprintf(buffer, "{\"status\":\"ok\",\"date\":\"%d/%d/%d\",\"time\":\"%d:%d:%d\"}", d.day(), d.month(), d.year(), d.hour(), d.minute(), d.second());
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean rtcSetTimeApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[200]; char buffer[200];
@ -128,12 +128,12 @@ boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
{ {
strcpy(buffer,"{\"status\":\"failed\",\"message\":\"datetime parameter is empty\"}"); strcpy(buffer,"{\"status\":\"failed\",\"message\":\"datetime parameter is empty\"}");
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean sdCardActionApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean sdCardActionApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SdCardApiPacket *pV = (SdCardApiPacket*)pData; SdCardApiPacket *pV = (SdCardApiPacket*)pData;
SAB *p = (SAB *)pV->pSab; SAB *p = (SAB *)pV->pSab;
@ -176,19 +176,19 @@ boolean sdCardActionApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *
} }
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean espRestartApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean espRestartApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *sab = (SAB*)pData; SAB *sab = (SAB*)pData;
char buffer[200]; char buffer[200];
sprintf(buffer,"{\"status\":\"ok\",\"message\":\"module %s in 10 seconds\"}",strstr(HRD.httpResource,"reset") == NULL ? "restarting" : "resetting"); sprintf(buffer,"{\"status\":\"ok\",\"message\":\"module %s in 10 seconds\"}",strstr(HRD.httpResource,"reset") == NULL ? "restarting" : "resetting");
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
sab->getTaskSchedulerManager().addTask(sab->getTaskSchedulerManager().findFreeTaskId(), TaskSchedulerManagerHelper::Schedule::scheduleBuilder() sab->getTaskSchedulerManager().addTask(sab->getTaskSchedulerManager().findFreeTaskId(), TaskSchedulerManagerHelper::Schedule::scheduleBuilder()
@ -199,12 +199,12 @@ boolean espRestartApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
return true; return true;
} }
boolean espResetApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean espResetApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
return espRestartApi(HRD, wc, pData); return espRestartApi(ws, HRD, wc, pData);
} }
boolean sdCardSizeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean sdCardSizeApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -215,12 +215,12 @@ boolean sdCardSizeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
else else
sprintf(buffer,"{\"status\":\"ok\",\"card\":\"present\",\"size\":\"%.2f\",\"unit\":\"GByte\"}",size); sprintf(buffer,"{\"status\":\"ok\",\"card\":\"present\",\"size\":\"%.2f\",\"unit\":\"GByte\"}",size);
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean staWifiInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean staWifiInfoApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -229,12 +229,12 @@ boolean staWifiInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *w
sprintf(buffer,"{\"status\":\"ok\",\"RSSI\":%d,\"RSSI2\":%d,\"local IP\":\"%u.%u.%u.%u\",\"MAC\":\"%s\"}", p->getConnectivityManager().RSSI(), p->getConnectivityManager().RSSIPercent(), IP[0], IP[1], IP[2], IP[3], p->getConnectivityManager().macAddress().c_str()); sprintf(buffer,"{\"status\":\"ok\",\"RSSI\":%d,\"RSSI2\":%d,\"local IP\":\"%u.%u.%u.%u\",\"MAC\":\"%s\"}", p->getConnectivityManager().RSSI(), p->getConnectivityManager().RSSIPercent(), IP[0], IP[1], IP[2], IP[3], p->getConnectivityManager().macAddress().c_str());
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean apWifiInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean apWifiInfoApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[300]; char buffer[300];
@ -260,17 +260,17 @@ boolean apWifiInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
p->getConnectivityManager().softAPPSK().c_str()); p->getConnectivityManager().softAPPSK().c_str());
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean apScannerApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean apScannerApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
(void)pData; (void)pData;
uint8_t number = WiFi.scanNetworks(); uint8_t number = WiFi.scanNetworks();
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON));
wc->print("["); wc->print("[");
for(uint8_t i(0); i < number; i++) for(uint8_t i(0); i < number; i++)
@ -282,7 +282,7 @@ boolean apScannerApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
return true; return true;
} }
boolean systemInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean systemInfoApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -294,13 +294,13 @@ boolean systemInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
TimeSpan ts(p->getUpTime()); TimeSpan ts(p->getUpTime());
sprintf(buffer, "{\"status\":\"ok\",\"version\":\"%s\",\"CPU freq\":%u,\"free RAM\":%u,\"heap frag\":%u,\"max block\":%u,\"nb views\":%u,\"up time\":{\"days\":%d,\"hours\":%d,\"minutes\":%d,\"seconds\":%d},\"temperature\":{\"level\":%.2f, \"unit\":\"°C\"}}", p->getSoftVersion(), ESP.getCpuFreqMHz(), freeMem, frag, biggestContigMemBlock, p->getScreenManager().getViewCount(), ts.days(), ts.hours(), ts.minutes(), ts.seconds(), p->getRTC_DS3231().getTemperature()); sprintf(buffer, "{\"status\":\"ok\",\"version\":\"%s\",\"CPU freq\":%u,\"free RAM\":%u,\"heap frag\":%u,\"max block\":%u,\"nb views\":%u,\"up time\":{\"days\":%d,\"hours\":%d,\"minutes\":%d,\"seconds\":%d},\"temperature\":{\"level\":%.2f, \"unit\":\"°C\"}}", p->getSoftVersion(), ESP.getCpuFreqMHz(), freeMem, frag, biggestContigMemBlock, p->getScreenManager().getViewCount(), ts.days(), ts.hours(), ts.minutes(), ts.seconds(), p->getRTC_DS3231().getTemperature());
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean powerInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean powerInfoApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -309,12 +309,12 @@ boolean powerInfoApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
sprintf(buffer,"{\"status\":\"ok\",\"power type\":\"%s\",\"level\":\"%u\",\"unit\":\"%%\"}", pi.powerType == PowerManager::USB ? "USB" : "BAT", pi.level); sprintf(buffer,"{\"status\":\"ok\",\"power type\":\"%s\",\"level\":\"%u\",\"unit\":\"%%\"}", pi.powerType == PowerManager::USB ? "USB" : "BAT", pi.level);
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
/* Changing the MCU frequency on the fly isn"t supported anymore by the SDK. /* Changing the MCU frequency on the fly isn"t supported anymore by the SDK.
boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean powerSettingsApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[300]; char buffer[300];
@ -341,14 +341,14 @@ boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient
strcpy(buffer, "{\"status\":\"error\",\"message\":\"Parameter FREQ expected\"}"); strcpy(buffer, "{\"status\":\"error\",\"message\":\"Parameter FREQ expected\"}");
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
*/ */
boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean ioGetLevelApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
boolean *ioState = (boolean *)pData; boolean *ioState = (boolean *)pData;
char buffer[300] = ""; char buffer[300] = "";
@ -404,12 +404,12 @@ boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
strcat(buffer,"}"); strcat(buffer,"}");
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean ioSetLevelApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[300] = ""; char buffer[300] = "";
@ -451,12 +451,12 @@ boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc
p->getIOManager().getPcf().digitalReadAll(ioState);//We retrieve the IO state p->getIOManager().getPcf().digitalReadAll(ioState);//We retrieve the IO state
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]); sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%d\",\"P1\":\"%d\",\"P2\":\"%d\",\"P3\":\"%d\",\"P4\":\"%d\",\"P5\":\"%d\",\"P6\":\"%d\",\"P7\":\"%d\"}",ioState[0],ioState[1],ioState[2],ioState[3],ioState[4],ioState[5],ioState[6],ioState[7]);
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean ioGetModeApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
boolean ioMode[8] = {0}; boolean ioMode[8] = {0};
@ -524,12 +524,12 @@ boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
strcat(buffer," }"); strcat(buffer," }");
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean ioSetModeApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
char buffer[300] = ""; char buffer[300] = "";
@ -572,12 +572,12 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
p->getIOManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT p->getIOManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN); sprintf(buffer,"{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
return true; return true;
} }
boolean otaUpdateUploadApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean otaUpdateUploadApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
(void)HRD; (void)HRD;
(void)pData; (void)pData;
@ -600,13 +600,13 @@ boolean otaUpdateUploadApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClien
} }
Serial.println("#"); Serial.println("#");
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::TEXT_PLAIN), 2); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::TEXT_PLAIN), 2);
wc->print("OK"); wc->print("OK");
return true; return true;
} }
boolean otaUpdateRemoteApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData) boolean otaUpdateRemoteApi(WEBServer<WEBClient> *ws, WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc, void *pData)
{ {
SAB *p = (SAB *)pData; SAB *p = (SAB *)pData;
@ -650,7 +650,7 @@ boolean otaUpdateRemoteApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClien
} }
} }
WEBServer<WEBClient>::sendHTTPHeader(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer)); ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::APPLICATION_JSON), strlen(buffer));
wc->print(buffer); wc->print(buffer);
if(updateDevice) if(updateDevice)

View File

@ -3,34 +3,34 @@
#include "SAB.h" #include "SAB.h"
#include "views.h" #include "views.h"
boolean apiTesterApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean apiTesterApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean nextViewApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean nextViewApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean reloadViewApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean reloadViewApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean viewByUIDApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean viewByUIDApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean rtcGetTimeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean rtcGetTimeApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean rtcSetTimeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean rtcSetTimeApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean sdCardSizeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean sdCardSizeApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
typedef struct sdCardApiPacket typedef struct sdCardApiPacket
{ {
SAB *pSab; SAB *pSab;
View1Packet *pView; View1Packet *pView;
} SdCardApiPacket; } SdCardApiPacket;
boolean sdCardActionApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean sdCardActionApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean apScannerApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean apScannerApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean staWifiInfoApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean staWifiInfoApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean apWifiInfoApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean apWifiInfoApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean espRestartApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean espRestartApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean espResetApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean espResetApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean systemInfoApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean systemInfoApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean powerInfoApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean powerInfoApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean powerSettingsApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean powerSettingsApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioGetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean ioGetLevelApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioSetLevelApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean ioSetLevelApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean ioGetModeApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean ioSetModeApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean otaUpdateUploadApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean otaUpdateUploadApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
boolean otaUpdateRemoteApi(WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*); boolean otaUpdateRemoteApi(WEBServer<WEBClient>*, WEBServer<WEBClient>::HttpRequestData&, WiFiClient*, void*);
#endif #endif