Added ArduinoJSON

This commit is contained in:
cschwinne 2019-03-03 18:05:56 +01:00
parent bc125ad76c
commit cc1cfd70b8
5 changed files with 56 additions and 61 deletions

View File

@ -30,6 +30,7 @@ lib_deps_external =
ESPAsyncTCP@1.2.0 ESPAsyncTCP@1.2.0
AsyncTCP@1.0.3 AsyncTCP@1.0.3
EspAsyncWebServer@1.2.0 EspAsyncWebServer@1.2.0
ArduinoJson@5.13.5
IRremoteESP8266@2.5.5 IRremoteESP8266@2.5.5
#Time@1.5 #Time@1.5
#Timezone@1.2.1 #Timezone@1.2.1

View File

@ -40,6 +40,8 @@
#endif #endif
#include <ESPAsyncWebServer.h> #include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <ArduinoJson.h> //please use v5.13.x!
#include <EEPROM.h> #include <EEPROM.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <DNSServer.h> #include <DNSServer.h>
@ -51,6 +53,7 @@
#include "src/dependencies/timezone/Timezone.h" #include "src/dependencies/timezone/Timezone.h"
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA
#define ESPALEXA_ASYNC #define ESPALEXA_ASYNC
#define ESPALEXA_NO_SUBPAGE
#define ESPALEXA_MAXDEVICES 1 #define ESPALEXA_MAXDEVICES 1
#include "src/dependencies/espalexa/Espalexa.h" #include "src/dependencies/espalexa/Espalexa.h"
#endif #endif
@ -86,7 +89,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1903011 #define VERSION 1903031
char versionString[] = "0.8.4-dev"; char versionString[] = "0.8.4-dev";

View File

@ -216,79 +216,72 @@ void initCon()
//fill string buffer with build info //fill string buffer with build info
void getJsonInfo() void serveJsonInfo(AsyncWebServerRequest* request)
{ {
olen = 0; AsyncJsonResponse* response = new AsyncJsonResponse();
oappend("{\r\n\"ver\":\""); JsonObject& doc = response->getRoot();
oappend(versionString);
oappend("\",\r\n\"vid\":"); doc["ver"] = versionString;
oappendi(VERSION); doc["vid"] = VERSION;
oappend(",\r\n\"leds\":{\r\n");
oappend("\"count\":"); JsonObject& leds = doc.createNestedObject("leds");
oappendi(ledCount); leds["count"] = ledCount;
oappend(",\r\n\"rgbw\":"); leds["rgbw"] = useRGBW;
oappend((char*)(useRGBW?"true":"false")); JsonArray& leds_pin = leds.createNestedArray("pin");
oappend(",\r\n\"pin\":["); leds_pin.add(LEDPIN);
oappendi(LEDPIN);
oappend("],\r\n\"pwr\":"); leds["pwr"] = strip.currentMilliamps;
oappendi(strip.currentMilliamps); leds["maxpwr"] = strip.ablMilliampsMax;
oappend(",\r\n\"maxpwr\":"); leds["maxseg"] = 1;
oappendi(strip.ablMilliampsMax); doc["name"] = serverDescription;
oappend(",\r\n\"maxseg\":1},\r\n\"name\":\""); doc["udpport"] = udpPort;
oappend(serverDescription); doc["modecount"] = strip.getModeCount();
oappend("\",\r\n\"udpport\":"); doc["palettecount"] = strip.getPaletteCount();
oappendi(udpPort);
oappend(",\r\n\"modecount\":");
oappendi(strip.getModeCount());
oappend(",\r\n\"palettecount\":");
oappendi(strip.getPaletteCount());
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
oappend(",\r\n\"arch\":\"esp32\",\r\n\"core\":\""); doc["arch"] = "esp32";
oappend((char*)ESP.getSdkVersion()); doc["core"] = ESP.getSdkVersion();
doc["maxalloc"] = ESP.getMaxAllocHeap();
#else #else
oappend(",\r\n\"arch\":\"esp8266\",\r\n\"core\":\""); doc["arch"] = "esp8266";
oappend((char*)ESP.getCoreVersion().c_str()); doc["core"] = ESP.getCoreVersion();
doc["maxalloc"] = ESP.getMaxFreeBlockSize();
#endif #endif
oappend("\",\r\n\"uptime\":"); doc["freeheap"] = ESP.getFreeHeap();
oappendi(millis()/1000); doc["uptime"] = millis()/1000;
oappend(",\r\n\"freeheap\":");
oappendi(ESP.getFreeHeap()); JsonArray& opt = doc.createNestedArray("opt");
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\","); opt.add("alexa");
#endif #endif
#ifndef WLED_DISABLE_BLYNK #ifndef WLED_DISABLE_BLYNK
oappend("\"blynk\","); opt.add("blynk");
#endif #endif
#ifndef WLED_DISABLE_CRONIXIE #ifndef WLED_DISABLE_CRONIXIE
oappend("\"cronixie\","); opt.add("cronixie");
#endif #endif
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
oappend("\"debug\","); opt.add("debug");
#endif #endif
#ifdef USEFS #ifdef USEFS
oappend("\"fs\","); opt.add("fs");
#endif #endif
#ifndef WLED_DISABLE_HUESYNC #ifndef WLED_DISABLE_HUESYNC
oappend("\"huesync\","); opt.add("huesync");
#endif #endif
#ifndef WLED_DISABLE_MOBILE_UI #ifndef WLED_DISABLE_MOBILE_UI
oappend("\"mobile-ui\","); opt.add("mobile-ui");
#endif #endif
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
oappend("\"ota\"]"); opt.add("ota");
#else
oappend("\"no-ota\"]");
#endif #endif
oappend(",\r\n\"brand\":\"wled\",\r\n\"product\":\"DIY light\",\r\n\"btype\":\"dev\",\r\n\"mac\":\"");
oappend((char*)escapedMac.c_str()); doc["brand"] = "wled";
oappend("\"\r\n}"); doc["product"] = "DIY light";
doc["btype"] = "dev";
doc["mac"] = escapedMac;
response->setLength();
request->send(response);
} }

View File

@ -182,10 +182,10 @@ void handleNotifications()
//apply effects from notification //apply effects from notification
if (receiveNotificationEffects) if (receiveNotificationEffects)
{ {
effectCurrent = udpIn[8]; if (udpIn[8] < strip.getModeCount()) effectCurrent = udpIn[8];
effectSpeed = udpIn[9]; effectSpeed = udpIn[9];
if (udpIn[11] > 2) effectIntensity = udpIn[16]; 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) if (udpIn[11] > 3)

View File

@ -73,8 +73,7 @@ void initServer()
}); });
server.on("/json/info", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/json/info", HTTP_GET, [](AsyncWebServerRequest *request){
getJsonInfo(); serveJsonInfo(request);
request->send(200, "application/json", obuf);
}); });
server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){ server.on("/json", HTTP_ANY, [](AsyncWebServerRequest *request){
@ -95,8 +94,7 @@ void initServer()
}); });
server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/build", HTTP_GET, [](AsyncWebServerRequest *request){
getJsonInfo(); serveJsonInfo(request);
request->send(200, "application/json", obuf);
}); });
server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request){ server.on("/power", HTTP_GET, [](AsyncWebServerRequest *request){