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)
#define VERSION 1902202
#define VERSION 1902211
char versionString[] = "0.8.4-dev";

View File

@ -216,62 +216,75 @@ void initCon()
//fill string buffer with build info
void getBuildInfo()
void getJsonInfo()
{
olen = 0;
oappend("hard-coded build info:\r\n\n");
#ifdef ARDUINO_ARCH_ESP32
oappend("platform: esp32");
#else
oappend("platform: esp8266");
#endif
oappend("\r\nversion: ");
oappend("{\r\n\"ver\":\"");
oappend(versionString);
oappend("\r\nbuild: ");
oappend("\",\r\n\"vid\":");
oappendi(VERSION);
oappend("\r\neepver: ");
oappendi(EEPVER);
oappend("\r\nesp-core: ");
oappend(",\r\n\"leds\":{\r\n");
oappend("\"count\":");
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
oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\"");
oappend((char*)ESP.getSdkVersion());
#else
oappend(",\r\n\"arch\":\"esp8266\",\r\n\"core\":\"");
oappend((char*)ESP.getCoreVersion().c_str());
#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
oappend("alexa ");
oappend("\"alexa\",");
#endif
#ifndef WLED_DISABLE_BLYNK
oappend("blynk ");
oappend("\"blynk\",");
#endif
#ifndef WLED_DISABLE_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");
oappend("\"cronixie\",");
#endif
#ifdef WLED_DEBUG
oappend("debug: true\r\n");
#else
oappend("debug: false\r\n");
oappend("\"debug\",");
#endif
oappend("button-pin: gpio");
oappendi(BTNPIN);
oappend("\r\nstrip-pin: gpio");
oappendi(LEDPIN);
oappend("\r\nbrand: wled");
oappend("\r\nbuild-type: dev\r\n");
#ifdef USEFS
oappend("\"fs\",");
#endif
#ifndef WLED_DISABLE_HUESYNC
oappend("\"huesync\",");
#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);
});
server.on("/json/info", HTTP_ANY, [](AsyncWebServerRequest *request){
request->send(500, "application/json", "{\"error\":\"Not implemented\"}");
server.on("/json/info", HTTP_GET, [](AsyncWebServerRequest *request){
getJsonInfo();
request->send(200, "application/json", obuf);
});
server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){
request->send(500, "application/json", "{\"error\":\"Not implemented\"}");
});
//*******DEPRECATED*******
server.on("/version", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/plain", (String)VERSION);
});
@ -92,6 +94,11 @@ void initServer()
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){
String val = "";
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);
});
//*******END*******/
server.on("/u", HTTP_GET, [](AsyncWebServerRequest *request){
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);
});
server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){
getBuildInfo();
request->send(200, "text/plain", obuf);
});
//if OTA is allowed
if (!otaLock){
server.on("/edit", HTTP_GET, [](AsyncWebServerRequest *request){