diff --git a/src/http_api.cpp b/src/http_api.cpp index f6c1b18ca74be1504e6ae082c2316cd2022a3936..fcedc8e5006687bfb3e0672ad04d842ec1ca8027 100644 --- a/src/http_api.cpp +++ b/src/http_api.cpp @@ -41,6 +41,31 @@ void handleAPIPort() } } +void handleInfoWiFiSTA() +{ + StaticJsonBuffer<128> jsonBuffer; + char buffer[129]; + JsonObject& root = jsonBuffer.createObject(); + IPAddress tmp_ip; + char tmp[16]; + + if(WiFi.status() == WL_CONNECTED) { + root["connected"] = true; + tmp_ip = WiFi.localIP(); + sprintf(tmp, "%d.%d.%d.%d", tmp_ip[0], tmp_ip[1], tmp_ip[2], tmp_ip[3]); + root["ip"] = tmp; + + tmp_ip = WiFi.subnetMask(); + sprintf(tmp, "%d.%d.%d.%d", tmp_ip[0], tmp_ip[1], tmp_ip[2], tmp_ip[3]); + root["netmask"] = tmp; + } else { + root["connected"] = false; + } + + root.printTo(buffer, 128); + server->send(200, "application/json", buffer); +} + void handleNotFound(){ String message = "File Not Found\n\n"; diff --git a/src/main.ino b/src/main.ino index b1d3e4c80037ceddc9f63092752fe28c029783ef..c30435321632f2948a2f769e1e2004816bff7a63 100644 --- a/src/main.ino +++ b/src/main.ino @@ -66,6 +66,7 @@ void setup() { server->on("/config/wifi/sta/ssid", handleSSID); server->on("/config/wifi/sta/password", handlePassword); server->on("/info/wifi/ssids", handleScanSSID); + server->on("/info/wifi/sta", handleInfoWiFiSTA); server->on("/setup", []() { server->setContentLength(sizeof(PAGE_setup)); server->sendHeader("Content-Encoding", "gzip"); diff --git a/src/sensor_node.h b/src/sensor_node.h index d7d4e4545fff0e55fca4428d4673d94d442ca2a9..a38d3815ce40a4cdab03a2e0e6163ed3a4c14c1c 100644 --- a/src/sensor_node.h +++ b/src/sensor_node.h @@ -66,6 +66,7 @@ class ArduRPC_SensorNode : public ArduRPCHandler void ICACHE_FLASH_ATTR handleAPIHostname(); void ICACHE_FLASH_ATTR handleAPIPort(); +void ICACHE_FLASH_ATTR handleInfoWiFiSTA(); void ICACHE_FLASH_ATTR handleNotFound(); void ICACHE_FLASH_ATTR handlePassword(); void ICACHE_FLASH_ATTR handleRegister();