esp8266-react-framework/lib/framework/APStatus.cpp

24 lines
869 B
C++
Raw Normal View History

#include <APStatus.h>
2019-07-14 21:13:26 +00:00
APStatus::APStatus(SecurityManager* securityManager) :_securityManager(securityManager) {}
void APStatus::init(AsyncWebServer *server){
server->on(AP_STATUS_SERVICE_PATH, HTTP_GET,
_securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
);
}
void APStatus::apStatus(AsyncWebServerRequest *request) {
AsyncJsonResponse * response = new AsyncJsonResponse(MAX_AP_STATUS_SIZE);
JsonObject root = response->getRoot();
WiFiMode_t currentWiFiMode = WiFi.getMode();
root["active"] = (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA);
root["ip_address"] = WiFi.softAPIP().toString();
root["mac_address"] = WiFi.softAPmacAddress();
root["station_num"] = WiFi.softAPgetStationNum();
response->setLength();
request->send(response);
}