Commit de81be18 authored by PhiBo's avatar PhiBo 🚀

Add new handler to return ip address

parent 3cfce3b9
......@@ -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";
......
......@@ -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");
......
......@@ -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();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment