11 auto scan_wifi_networks_handler = std::make_shared<HTTPRequestHandler>(
12 1 << HTTP_POST,
"/api/wifi/scan", [](httpd_req_t* req) {
14 networking->start_wifi_scan();
16 httpd_resp_set_status(req,
"202 Accepted");
17 httpd_resp_send(req,
"SCAN STARTED", 0);
21 server->add_handler(scan_wifi_networks_handler);
23 auto scan_results_handler = std::make_shared<HTTPRequestHandler>(
24 1 << HTTP_GET,
"/api/wifi/scan-results", [](httpd_req_t* req) {
26 std::vector<WiFiNetworkInfo> ssid_list;
27 int16_t result = networking->get_wifi_scan_results(ssid_list);
28 if (result == WIFI_SCAN_RUNNING) {
30 httpd_resp_set_status(req,
"202 Accepted");
31 httpd_resp_send(req,
"SCAN RUNNING", 0);
33 }
else if (result == WIFI_SCAN_FAILED) {
35 httpd_resp_set_status(req,
"400 Bad Request");
36 httpd_resp_send(req,
"SCAN FAILED", 0);
41 JsonArray networks = doc[
"networks"].to<JsonArray>();
42 for (
auto& ssid_info : ssid_list) {
43 JsonObject network = networks.add<JsonObject>();
44 ssid_info.as_json(network);
47 serializeJson(doc, json_str);
48 httpd_resp_set_type(req,
"application/json");
49 httpd_resp_send(req, json_str.c_str(), json_str.length());
53 server->add_handler(scan_results_handler);