diff --git a/platformio.ini b/platformio.ini index 322e1122..7dbb2b8f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,6 +30,7 @@ lib_deps_external = ESPAsyncTCP@1.2.0 AsyncTCP@1.0.3 EspAsyncWebServer@1.2.0 + ArduinoJson@5.13.5 IRremoteESP8266@2.5.5 #Time@1.5 #Timezone@1.2.1 diff --git a/wled00/wled00.ino b/wled00/wled00.ino index c3953a9a..379f7770 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -40,6 +40,8 @@ #endif #include +#include +#include //please use v5.13.x! #include #include #include @@ -51,6 +53,7 @@ #include "src/dependencies/timezone/Timezone.h" #ifndef WLED_DISABLE_ALEXA #define ESPALEXA_ASYNC + #define ESPALEXA_NO_SUBPAGE #define ESPALEXA_MAXDEVICES 1 #include "src/dependencies/espalexa/Espalexa.h" #endif @@ -86,7 +89,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1903011 +#define VERSION 1903031 char versionString[] = "0.8.4-dev"; diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 856aeeac..82323041 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -216,79 +216,72 @@ void initCon() //fill string buffer with build info -void getJsonInfo() +void serveJsonInfo(AsyncWebServerRequest* request) { - olen = 0; - oappend("{\r\n\"ver\":\""); - oappend(versionString); - oappend("\",\r\n\"vid\":"); - oappendi(VERSION); - 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); - oappend(",\r\n\"modecount\":"); - oappendi(strip.getModeCount()); - oappend(",\r\n\"palettecount\":"); - oappendi(strip.getPaletteCount()); + AsyncJsonResponse* response = new AsyncJsonResponse(); + JsonObject& doc = response->getRoot(); + + doc["ver"] = versionString; + doc["vid"] = VERSION; + + JsonObject& leds = doc.createNestedObject("leds"); + leds["count"] = ledCount; + leds["rgbw"] = useRGBW; + JsonArray& leds_pin = leds.createNestedArray("pin"); + leds_pin.add(LEDPIN); + + leds["pwr"] = strip.currentMilliamps; + leds["maxpwr"] = strip.ablMilliampsMax; + leds["maxseg"] = 1; + doc["name"] = serverDescription; + doc["udpport"] = udpPort; + doc["modecount"] = strip.getModeCount(); + doc["palettecount"] = strip.getPaletteCount(); #ifdef ARDUINO_ARCH_ESP32 - oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\""); - oappend((char*)ESP.getSdkVersion()); + doc["arch"] = "esp32"; + doc["core"] = ESP.getSdkVersion(); + doc["maxalloc"] = ESP.getMaxAllocHeap(); #else - oappend(",\r\n\"arch\":\"esp8266\",\r\n\"core\":\""); - oappend((char*)ESP.getCoreVersion().c_str()); + doc["arch"] = "esp8266"; + doc["core"] = ESP.getCoreVersion(); + doc["maxalloc"] = ESP.getMaxFreeBlockSize(); #endif - 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\":["); + doc["freeheap"] = ESP.getFreeHeap(); + doc["uptime"] = millis()/1000; + + JsonArray& opt = doc.createNestedArray("opt"); #ifndef WLED_DISABLE_ALEXA - oappend("\"alexa\","); + opt.add("alexa"); #endif #ifndef WLED_DISABLE_BLYNK - oappend("\"blynk\","); + opt.add("blynk"); #endif #ifndef WLED_DISABLE_CRONIXIE - oappend("\"cronixie\","); + opt.add("cronixie"); #endif #ifdef WLED_DEBUG - oappend("\"debug\","); + opt.add("debug"); #endif #ifdef USEFS - oappend("\"fs\","); + opt.add("fs"); #endif #ifndef WLED_DISABLE_HUESYNC - oappend("\"huesync\","); + opt.add("huesync"); #endif #ifndef WLED_DISABLE_MOBILE_UI - oappend("\"mobile-ui\","); + opt.add("mobile-ui"); #endif - #ifndef WLED_DISABLE_OTA - oappend("\"ota\"]"); - #else - oappend("\"no-ota\"]"); + #ifndef WLED_DISABLE_OTA + opt.add("ota"); #endif - oappend(",\r\n\"brand\":\"wled\",\r\n\"product\":\"DIY light\",\r\n\"btype\":\"dev\",\r\n\"mac\":\""); - oappend((char*)escapedMac.c_str()); - oappend("\"\r\n}"); + + doc["brand"] = "wled"; + doc["product"] = "DIY light"; + doc["btype"] = "dev"; + doc["mac"] = escapedMac; + + response->setLength(); + request->send(response); } diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index 9008cbe8..7d58094a 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -182,10 +182,10 @@ void handleNotifications() //apply effects from notification if (receiveNotificationEffects) { - effectCurrent = udpIn[8]; + if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8]; effectSpeed = udpIn[9]; if (udpIn[11] > 2) effectIntensity = udpIn[16]; - if (udpIn[11] > 4) effectPalette = udpIn[19]; + if (udpIn[11] > 4 && udpIn[19] < strip.getPaletteCount()) effectPalette = udpIn[19]; } if (udpIn[11] > 3) diff --git a/wled00/wled18_server.ino b/wled00/wled18_server.ino index 657a5461..5a911513 100644 --- a/wled00/wled18_server.ino +++ b/wled00/wled18_server.ino @@ -73,8 +73,7 @@ void initServer() }); server.on("/json/info", HTTP_GET, [](AsyncWebServerRequest *request){ - getJsonInfo(); - request->send(200, "application/json", obuf); + serveJsonInfo(request); }); server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){ @@ -95,8 +94,7 @@ void initServer() }); server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){ - getJsonInfo(); - request->send(200, "application/json", obuf); + serveJsonInfo(request); }); server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request){