Skip to content

Commit

Permalink
Added ArduinoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Mar 3, 2019
1 parent bc125ad commit cc1cfd7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 61 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ lib_deps_external =
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
#[email protected]
#[email protected]
Expand Down
5 changes: 4 additions & 1 deletion wled00/wled00.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#endif

#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <ArduinoJson.h> //please use v5.13.x!
#include <EEPROM.h>
#include <WiFiUdp.h>
#include <DNSServer.h>
Expand All @@ -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
Expand Down Expand Up @@ -86,7 +89,7 @@


//version code in format yymmddb (b = daily build)
#define VERSION 1903011
#define VERSION 1903031
char versionString[] = "0.8.4-dev";


Expand Down
101 changes: 47 additions & 54 deletions wled00/wled05_init.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
#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\n\"uptime\":");
oappendi(millis()/1000);
oappend(",\r\n\"freeheap\":");
oappendi(ESP.getFreeHeap());
oappend(",\r\n\"maxalloc\":");
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
oappendi(ESP.getMaxAllocHeap());
doc["arch"] = "esp32";
doc["core"] = ESP.getSdkVersion();
doc["maxalloc"] = ESP.getMaxAllocHeap();
#else
oappendi(ESP.getMaxFreeBlockSize());
doc["arch"] = "esp8266";
doc["core"] = ESP.getCoreVersion();
doc["maxalloc"] = 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);
}


Expand Down
4 changes: 2 additions & 2 deletions wled00/wled07_notify.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions wled00/wled18_server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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){
Expand Down

0 comments on commit cc1cfd7

Please sign in to comment.