From 723132a0825adf2fde2940f1aa7d43ff285c08ba Mon Sep 17 00:00:00 2001 From: anschrammh Date: Mon, 20 Jan 2020 08:14:49 +0100 Subject: [PATCH] Added a new api call to get the nearby access points --- src/app/webApi.cpp | 19 ++++++++++++++++++- src/app/webApi.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/webApi.cpp b/src/app/webApi.cpp index 60beb51..fa2fe39 100644 --- a/src/app/webApi.cpp +++ b/src/app/webApi.cpp @@ -38,7 +38,10 @@ boolean nextViewApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, { SAB *p = (SAB *)pData; char buffer[200]; - if(p->getScreenManager().displayNextView()) + + p->getScreenManager().displayNextView(); + + if(p->getScreenManager().getError() == OK) sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"ViewUID\" : \"%d\" }", p->getScreenManager().getCurrentViewUID()); else sprintf(buffer, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"failed\", \"message\" : \"%s\" }", p->getScreenManager().getErrorMessage()); @@ -215,6 +218,20 @@ boolean staWifiInfoApi(WEBServer::HttpRequestData &HRD, WiFiClient *w return true; }*/ +boolean apScannerApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, void *pData) +{ + uint8_t number = WiFi.scanNetworks(); + wc->print("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n["); + + for(uint8_t i(0); i < number; i++) + { + wc->printf("%s{\"SSID\":\"%s\",\"RSSI\":%d,\"Protected\":\"%s\"}", i == 0 ? "":",", WiFi.SSID(i).c_str(), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "No":"Yes"); + } + + wc->print("]"); + return true; +} + boolean systemInfoApi(WEBServer::HttpRequestData &HRD, WiFiClient *wc, void *pData) { SAB *p = (SAB *)pData; diff --git a/src/app/webApi.h b/src/app/webApi.h index 28323af..22be93b 100644 --- a/src/app/webApi.h +++ b/src/app/webApi.h @@ -19,6 +19,7 @@ typedef struct sdCardApiPacket boolean sdCardUnmountApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean sdCardMountApi(WEBServer::HttpRequestData&, WiFiClient*, void*); +boolean apScannerApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean staWifiInfoApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean apWifiInfoApi(WEBServer::HttpRequestData&, WiFiClient*, void*); boolean espRestartApi(WEBServer::HttpRequestData&, WiFiClient*, void*);