| 98 | } |
| 99 | |
| 100 | void onAjaxNetworkList(HttpRequest& request, HttpResponse& response) |
| 101 | { |
| 102 | JsonObjectStream* stream = new JsonObjectStream(4096); |
| 103 | JsonObject json = stream->getRoot(); |
| 104 | |
| 105 | json["status"] = (bool)true; |
| 106 | |
| 107 | bool connected = WifiStation.isConnected(); |
| 108 | json["connected"] = connected; |
| 109 | if(connected) { |
| 110 | // Copy full string to JSON buffer memory |
| 111 | json["network"] = WifiStation.getSSID(); |
| 112 | } |
| 113 | |
| 114 | JsonArray netlist = json.createNestedArray("available"); |
| 115 | for(auto nw : networks) { |
| 116 | if(nw->hidden) { |
| 117 | continue; |
| 118 | } |
| 119 | JsonObject item = netlist.createNestedObject(); |
| 120 | item["id"] = nw->getHashId(); |
| 121 | // Copy full string to JSON buffer memory |
| 122 | item["title"] = nw->ssid; |
| 123 | item["signal"] = nw->rssi; |
| 124 | item["encryption"] = nw->getAuthorizationMethodName(); |
| 125 | } |
| 126 | |
| 127 | response.setAllowCrossDomainOrigin("*"); |
| 128 | response.sendDataStream(stream, MIME_JSON); |
| 129 | } |
| 130 | |
| 131 | void makeConnection() |
| 132 | { |
nothing calls this directly
no test coverage detected