Added /json/info page

This commit is contained in:
cschwinne 2019-02-21 16:32:15 +01:00
parent 4a4c537a0d
commit f86cdd8cde
3 changed files with 65 additions and 49 deletions

View File

@ -87,7 +87,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1902202 #define VERSION 1902211
char versionString[] = "0.8.4-dev"; char versionString[] = "0.8.4-dev";

View File

@ -216,62 +216,75 @@ void initCon()
//fill string buffer with build info //fill string buffer with build info
void getBuildInfo() void getJsonInfo()
{ {
olen = 0; olen = 0;
oappend("hard-coded build info:\r\n\n"); oappend("{\r\n\"ver\":\"");
#ifdef ARDUINO_ARCH_ESP32
oappend("platform: esp32");
#else
oappend("platform: esp8266");
#endif
oappend("\r\nversion: ");
oappend(versionString); oappend(versionString);
oappend("\r\nbuild: "); oappend("\",\r\n\"vid\":");
oappendi(VERSION); oappendi(VERSION);
oappend("\r\neepver: "); oappend(",\r\n\"leds\":{\r\n");
oappendi(EEPVER); oappend("\"count\":");
oappend("\r\nesp-core: "); oappendi(ledCount);
oappend(",\r\n\"rgbw\":");
oappend((char*)(useRGBW?"true":"false"));
oappend(",\r\n\"pin\":[");
oappendi(LEDPIN);
oappend("],\r\n\"pwr\":");
oappendi(strip.currentMilliamps);
oappend(",\r\n\"maxpwr\":");
oappendi(strip.ablMilliampsMax);
oappend(",\r\n\"maxseg\":1},\r\n\"name\":\"");
oappend(serverDescription);
oappend("\",\r\n\"udpport\":");
oappendi(udpPort);
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\"");
oappend((char*)ESP.getSdkVersion()); oappend((char*)ESP.getSdkVersion());
#else #else
oappend(",\r\n\"arch\":\"esp8266\",\r\n\"core\":\"");
oappend((char*)ESP.getCoreVersion().c_str()); oappend((char*)ESP.getCoreVersion().c_str());
#endif #endif
oappend("\r\nopt: "); oappend("\",\r\n\"uptime\":");
oappendi(millis()/1000);
oappend(",\r\n\"freeheap\":");
oappendi(ESP.getFreeHeap());
oappend(",\r\n\"maxalloc\":");
#ifdef ARDUINO_ARCH_ESP32
oappendi(ESP.getMaxAllocHeap());
#else
oappendi(ESP.getMaxFreeBlockSize());
#endif
oappend(",\r\n\"opt\":[");
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA
oappend("alexa "); oappend("\"alexa\",");
#endif #endif
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
oappend("blynk "); oappend("\"blynk\",");
#endif #endif
#ifndef WLED_DISABLE_CRONIXIE #ifndef WLED_DISABLE_CRONIXIE
oappend("cronixie "); oappend("\"cronixie\",");
#endif
#ifndef WLED_DISABLE_HUESYNC
oappend("huesync ");
#endif
#ifndef WLED_DISABLE_MOBILE_UI
oappend("mobile-ui ");
#endif
#ifndef WLED_DISABLE_OTA
oappend("ota");
#endif
#ifdef USEFS
oappend("\r\nspiffs: true\r\n");
#else
oappend("\r\nspiffs: false\r\n");
#endif #endif
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
oappend("debug: true\r\n"); oappend("\"debug\",");
#else
oappend("debug: false\r\n");
#endif #endif
oappend("button-pin: gpio"); #ifdef USEFS
oappendi(BTNPIN); oappend("\"fs\",");
oappend("\r\nstrip-pin: gpio"); #endif
oappendi(LEDPIN); #ifndef WLED_DISABLE_HUESYNC
oappend("\r\nbrand: wled"); oappend("\"huesync\",");
oappend("\r\nbuild-type: dev\r\n"); #endif
#ifndef WLED_DISABLE_MOBILE_UI
oappend("\"mobile-ui\",");
#endif
#ifndef WLED_DISABLE_OTA
oappend("\"ota\"]");
#else
oappend("\"no-ota\"]");
#endif
oappend(",\r\n\"brand\":\"wled\",\r\n\"btype\":\"dev\",\r\n\"mac\":\"");
oappend((char*)escapedMac.c_str());
oappend("\"\r\n}");
} }

View File

@ -72,14 +72,16 @@ void initServer()
request->send_P(200, "application/json", JSON_palette_names); request->send_P(200, "application/json", JSON_palette_names);
}); });
server.on("/json/info", HTTP_ANY, [](AsyncWebServerRequest *request){ server.on("/json/info", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(500, "application/json", "{\"error\":\"Not implemented\"}"); getJsonInfo();
request->send(200, "application/json", obuf);
}); });
server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){ server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){
request->send(500, "application/json", "{\"error\":\"Not implemented\"}"); request->send(500, "application/json", "{\"error\":\"Not implemented\"}");
}); });
//*******DEPRECATED*******
server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", (String)VERSION); request->send(200, "text/plain", (String)VERSION);
}); });
@ -92,6 +94,11 @@ void initServer()
request->send(200, "text/plain", (String)ESP.getFreeHeap()); request->send(200, "text/plain", (String)ESP.getFreeHeap());
}); });
server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){
getJsonInfo();
request->send(200, "application/json", obuf);
});
server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request){
String val = ""; String val = "";
if (strip.currentMilliamps == 0) if (strip.currentMilliamps == 0)
@ -104,6 +111,7 @@ void initServer()
} }
serveMessage(request, 200, val, "This is just an estimate (does not account for factors like wire resistance). It is NOT a measurement!", 254); serveMessage(request, 200, val, "This is just an estimate (does not account for factors like wire resistance). It is NOT a measurement!", 254);
}); });
//*******END*******/
server.on("/u", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/u", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", PAGE_usermod); request->send_P(200, "text/html", PAGE_usermod);
@ -113,11 +121,6 @@ void initServer()
serveMessage(request, 418, "418. I'm a teapot.", "(Tangible Embedded Advanced Project Of Twinkling)", 254); serveMessage(request, 418, "418. I'm a teapot.", "(Tangible Embedded Advanced Project Of Twinkling)", 254);
}); });
server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){
getBuildInfo();
request->send(200, "text/plain", obuf);
});
//if OTA is allowed //if OTA is allowed
if (!otaLock){ if (!otaLock){
server.on("/edit", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/edit", HTTP_GET, [](AsyncWebServerRequest *request){