diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index d2622f901..15ff0fdb5 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -94,12 +94,12 @@ void WS2812FX::setUpMatrix() { DEBUG_PRINT(F("Reading LED gap from ")); DEBUG_PRINTLN(fileName); // read the array into global JSON buffer - if (readObjectFromFile(fileName, nullptr, &doc)) { + if (readObjectFromFile(fileName, nullptr, pDoc)) { // the array is similar to ledmap, except it has only 3 values: // -1 ... missing pixel (do not increase pixel count) // 0 ... inactive pixel (it does count, but should be mapped out (-1)) // 1 ... active pixel (it will count and will be mapped) - JsonArray map = doc.as(); + JsonArray map = pDoc->as(); gapSize = map.size(); if (!map.isNull() && gapSize >= customMappingSize) { // not an empty map gapTable = new int8_t[gapSize]; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 42984a051..d4e4cf9a8 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1670,7 +1670,7 @@ bool WS2812FX::deserializeMap(uint8_t n) { if (!requestJSONBufferLock(7)) return false; - if (!readObjectFromFile(fileName, nullptr, &doc)) { + if (!readObjectFromFile(fileName, nullptr, pDoc)) { releaseJSONBufferLock(); return false; //if file does not exist just exit } @@ -1685,7 +1685,8 @@ bool WS2812FX::deserializeMap(uint8_t n) { customMappingTable = nullptr; } - JsonArray map = doc[F("map")]; + JsonObject root = pDoc->as(); + JsonArray map = root[F("map")]; if (!map.isNull() && map.size()) { // not an empty map customMappingSize = map.size(); customMappingTable = new uint16_t[customMappingSize]; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index b036dc1d4..948bcfada 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -609,7 +609,7 @@ void deserializeConfigFromFS() { DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); - success = readObjectFromFile("/cfg.json", nullptr, &doc); + success = readObjectFromFile("/cfg.json", nullptr, pDoc); if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS releaseJSONBufferLock(); #ifdef WLED_ADD_EEPROM_SUPPORT @@ -630,7 +630,8 @@ void deserializeConfigFromFS() { // NOTE: This routine deserializes *and* applies the configuration // Therefore, must also initialize ethernet from this function - bool needsSave = deserializeConfig(doc.as(), true); + JsonObject root = pDoc->as(); + bool needsSave = deserializeConfig(root, true); releaseJSONBufferLock(); if (needsSave) serializeConfig(); // usermods required new parameters @@ -643,19 +644,21 @@ void serializeConfig() { if (!requestJSONBufferLock(2)) return; - JsonArray rev = doc.createNestedArray("rev"); + JsonObject root = pDoc->as(); + + JsonArray rev = root.createNestedArray("rev"); rev.add(1); //major settings revision rev.add(0); //minor settings revision - doc[F("vid")] = VERSION; + root[F("vid")] = VERSION; - JsonObject id = doc.createNestedObject("id"); + JsonObject id = root.createNestedObject("id"); id[F("mdns")] = cmDNS; id[F("name")] = serverDescription; id[F("inv")] = alexaInvocationName; id[F("sui")] = simplifiedUI; - JsonObject nw = doc.createNestedObject("nw"); + JsonObject nw = root.createNestedObject("nw"); #ifndef WLED_DISABLE_ESPNOW nw[F("espnow")] = enableESPNow; nw[F("linked_remote")] = linked_remote; @@ -677,7 +680,7 @@ void serializeConfig() { nw_ins_0_sn.add(staticSubnet[i]); } - JsonObject ap = doc.createNestedObject("ap"); + JsonObject ap = root.createNestedObject("ap"); ap[F("ssid")] = apSSID; ap[F("pskl")] = strlen(apPass); ap[F("chan")] = apChannel; @@ -690,12 +693,12 @@ void serializeConfig() { ap_ip.add(2); ap_ip.add(1); - JsonObject wifi = doc.createNestedObject("wifi"); + JsonObject wifi = root.createNestedObject("wifi"); wifi[F("sleep")] = !noWifiSleep; //wifi[F("phy")] = 1; #ifdef WLED_USE_ETHERNET - JsonObject ethernet = doc.createNestedObject("eth"); + JsonObject ethernet = root.createNestedObject("eth"); ethernet["type"] = ethernetType; if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) { JsonArray pins = ethernet.createNestedArray("pin"); @@ -718,7 +721,7 @@ void serializeConfig() { } #endif - JsonObject hw = doc.createNestedObject("hw"); + JsonObject hw = root.createNestedObject("hw"); JsonObject hw_led = hw.createNestedObject("led"); hw_led[F("total")] = strip.getLengthTotal(); //provided for compatibility on downgrade and per-output ABL @@ -830,7 +833,7 @@ void serializeConfig() { //JsonObject hw_status = hw.createNestedObject("status"); //hw_status["pin"] = -1; - JsonObject light = doc.createNestedObject(F("light")); + JsonObject light = root.createNestedObject(F("light")); light[F("scale-bri")] = briMultiplier; light[F("pal-mode")] = strip.paletteBlend; light[F("aseg")] = autoSegments; @@ -853,12 +856,12 @@ void serializeConfig() { light_nl[F("tbri")] = nightlightTargetBri; light_nl["macro"] = macroNl; - JsonObject def = doc.createNestedObject("def"); + JsonObject def = root.createNestedObject("def"); def["ps"] = bootPreset; def["on"] = turnOnAtBoot; def["bri"] = briS; - JsonObject interfaces = doc.createNestedObject("if"); + JsonObject interfaces = root.createNestedObject("if"); JsonObject if_sync = interfaces.createNestedObject("sync"); if_sync[F("port0")] = udpPort; @@ -961,7 +964,7 @@ void serializeConfig() { if_ntp[F("ln")] = longitude; if_ntp[F("lt")] = latitude; - JsonObject ol = doc.createNestedObject("ol"); + JsonObject ol = root.createNestedObject("ol"); ol[F("clock")] = overlayCurrent; ol[F("cntdwn")] = countdownMode; @@ -971,7 +974,7 @@ void serializeConfig() { ol[F("o5m")] = analogClock5MinuteMarks; ol[F("osec")] = analogClockSecondsTrail; - JsonObject timers = doc.createNestedObject(F("timers")); + JsonObject timers = root.createNestedObject(F("timers")); JsonObject cntdwn = timers.createNestedObject(F("cntdwn")); JsonArray goal = cntdwn.createNestedArray(F("goal")); @@ -999,14 +1002,14 @@ void serializeConfig() { } } - JsonObject ota = doc.createNestedObject("ota"); + JsonObject ota = root.createNestedObject("ota"); ota[F("lock")] = otaLock; ota[F("lock-wifi")] = wifiLock; ota[F("pskl")] = strlen(otaPass); ota[F("aota")] = aOtaEnabled; #ifdef WLED_ENABLE_DMX - JsonObject dmx = doc.createNestedObject("dmx"); + JsonObject dmx = root.createNestedObject("dmx"); dmx[F("chan")] = DMXChannels; dmx[F("gap")] = DMXGap; dmx["start"] = DMXStart; @@ -1020,11 +1023,11 @@ void serializeConfig() { dmx[F("e131proxy")] = e131ProxyUniverse; #endif - JsonObject usermods_settings = doc.createNestedObject("um"); + JsonObject usermods_settings = root.createNestedObject("um"); usermods.addToConfig(usermods_settings); File f = WLED_FS.open("/cfg.json", "w"); - if (f) serializeJson(doc, f); + if (f) serializeJson(*pDoc, f); f.close(); releaseJSONBufferLock(); @@ -1037,19 +1040,21 @@ bool deserializeConfigSec() { if (!requestJSONBufferLock(3)) return false; - bool success = readObjectFromFile("/wsec.json", nullptr, &doc); + bool success = readObjectFromFile("/wsec.json", nullptr, pDoc); if (!success) { releaseJSONBufferLock(); return false; } - JsonObject nw_ins_0 = doc["nw"]["ins"][0]; + JsonObject root = pDoc->as(); + + JsonObject nw_ins_0 = root["nw"]["ins"][0]; getStringFromJson(clientPass, nw_ins_0["psk"], 65); - JsonObject ap = doc["ap"]; + JsonObject ap = root["ap"]; getStringFromJson(apPass, ap["psk"] , 65); - [[maybe_unused]] JsonObject interfaces = doc["if"]; + [[maybe_unused]] JsonObject interfaces = root["if"]; #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces["mqtt"]; @@ -1060,10 +1065,10 @@ bool deserializeConfigSec() { getStringFromJson(hueApiKey, interfaces["hue"][F("key")], 47); #endif - getStringFromJson(settingsPIN, doc["pin"], 5); + getStringFromJson(settingsPIN, root["pin"], 5); correctPIN = !strlen(settingsPIN); - JsonObject ota = doc["ota"]; + JsonObject ota = root["ota"]; getStringFromJson(otaPass, ota[F("pwd")], 33); CJSON(otaLock, ota[F("lock")]); CJSON(wifiLock, ota[F("lock-wifi")]); @@ -1078,17 +1083,19 @@ void serializeConfigSec() { if (!requestJSONBufferLock(4)) return; - JsonObject nw = doc.createNestedObject("nw"); + JsonObject root = pDoc->as(); + + JsonObject nw = root.createNestedObject("nw"); JsonArray nw_ins = nw.createNestedArray("ins"); JsonObject nw_ins_0 = nw_ins.createNestedObject(); nw_ins_0["psk"] = clientPass; - JsonObject ap = doc.createNestedObject("ap"); + JsonObject ap = root.createNestedObject("ap"); ap["psk"] = apPass; - [[maybe_unused]] JsonObject interfaces = doc.createNestedObject("if"); + [[maybe_unused]] JsonObject interfaces = root.createNestedObject("if"); #ifdef WLED_ENABLE_MQTT JsonObject if_mqtt = interfaces.createNestedObject("mqtt"); if_mqtt["psk"] = mqttPass; @@ -1098,16 +1105,16 @@ void serializeConfigSec() { if_hue[F("key")] = hueApiKey; #endif - doc["pin"] = settingsPIN; + root["pin"] = settingsPIN; - JsonObject ota = doc.createNestedObject("ota"); + JsonObject ota = root.createNestedObject("ota"); ota[F("pwd")] = otaPass; ota[F("lock")] = otaLock; ota[F("lock-wifi")] = wifiLock; ota[F("aota")] = aOtaEnabled; File f = WLED_FS.open("/wsec.json", "w"); - if (f) serializeJson(doc, f); + if (f) serializeJson(*pDoc, f); f.close(); releaseJSONBufferLock(); } diff --git a/wled00/ir.cpp b/wled00/ir.cpp index fa253b015..3da4d68be 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -643,8 +643,8 @@ void decodeIRJson(uint32_t code) // this may fail for two reasons: ir.json does not exist or IR code not found // if the IR code is not found readObjectFromFile() will clean() doc JSON document // so we can differentiate between the two - readObjectFromFile("/ir.json", objKey, &doc); - fdo = doc.as(); + readObjectFromFile("/ir.json", objKey, pDoc); + fdo = pDoc->as(); lastValidCode = 0; if (fdo.isNull()) { //the received code does not exist diff --git a/wled00/json.cpp b/wled00/json.cpp index 5b20baac1..9a94796f2 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1055,7 +1055,7 @@ void serveJson(AsyncWebServerRequest* request) servingClient = false; return; } - AsyncJsonResponse *response = new AsyncJsonResponse(&doc, subJson==JSON_PATH_FXDATA || subJson==JSON_PATH_EFFECTS); // will clear and convert JsonDocument into JsonArray if necessary + AsyncJsonResponse *response = new AsyncJsonResponse(pDoc, subJson==JSON_PATH_FXDATA || subJson==JSON_PATH_EFFECTS); // will clear and convert JsonDocument into JsonArray if necessary JsonVariant lDoc = response->getRoot(); diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp index a5caaf472..3c753a9a9 100644 --- a/wled00/mqtt.cpp +++ b/wled00/mqtt.cpp @@ -109,8 +109,8 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties return; } if (payloadStr[0] == '{') { //JSON API - deserializeJson(doc, payloadStr); - deserializeState(doc.as()); + deserializeJson(*pDoc, payloadStr); + deserializeState(pDoc->as()); } else { //HTTP API String apireq = "win"; apireq += '&'; // reduce flash string usage apireq += payloadStr; diff --git a/wled00/pin_manager.cpp b/wled00/pin_manager.cpp index a1ac59ce7..102acd0ea 100644 --- a/wled00/pin_manager.cpp +++ b/wled00/pin_manager.cpp @@ -238,7 +238,7 @@ bool PinManagerClass::isPinAllocated(byte gpio, PinOwner tag) // Check if supplied GPIO is ok to use bool PinManagerClass::isPinOk(byte gpio, bool output) { -#ifdef ESP32 +#ifdef ARDUINO_ARCH_ESP32 if (digitalPinIsValid(gpio)) { #if defined(CONFIG_IDF_TARGET_ESP32C3) // strapping pins: 2, 8, & 9 @@ -257,6 +257,9 @@ bool PinManagerClass::isPinOk(byte gpio, bool output) // GPIO46 is input only and pulled down #else if (gpio > 5 && gpio < 12) return false; //SPI flash pins + #ifdef BOARD_HAS_PSRAM + if (gpio == 16 || gpio == 17) return false; //PSRAM pins + #endif #endif if (output) return digitalPinCanOutput(gpio); else return true; diff --git a/wled00/presets.cpp b/wled00/presets.cpp index 975b68974..be6005492 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -27,7 +27,7 @@ static void doSaveState() { if (!requestJSONBufferLock(10)) return; // will set fileDoc initPresetsFile(); // just in case if someone deleted presets.json using /edit - JsonObject sObj = doc.to(); + JsonObject sObj = pDoc->to(); DEBUG_PRINTLN(F("Serialize current state")); if (playlistSave) { @@ -42,7 +42,7 @@ static void doSaveState() { /* #ifdef WLED_DEBUG DEBUG_PRINTLN(F("Serialized preset")); - serializeJson(doc,Serial); + serializeJson(*pDoc,Serial); DEBUG_PRINTLN(); #endif */ @@ -83,9 +83,9 @@ bool getPresetName(byte index, String& name) { if (!requestJSONBufferLock(9)) return false; bool presetExists = false; - if (readObjectFromFileUsingId(getFileName(), index, &doc)) + if (readObjectFromFileUsingId(getFileName(), index, pDoc)) { - JsonObject fdo = doc.as(); + JsonObject fdo = pDoc->as(); if (fdo["n"]) { name = (const char*)(fdo["n"]); presetExists = true; diff --git a/wled00/remote.cpp b/wled00/remote.cpp index e547903d2..c41d88421 100644 --- a/wled00/remote.cpp +++ b/wled00/remote.cpp @@ -123,8 +123,8 @@ static bool remoteJson(int button) sprintf_P(objKey, PSTR("\"%d\":"), button); // attempt to read command from remote.json - readObjectFromFile("/remote.json", objKey, &doc); - JsonObject fdo = doc.as(); + readObjectFromFile("/remote.json", objKey, pDoc); + JsonObject fdo = pDoc->as(); if (fdo.isNull()) { // the received button does not exist if (!WLED_FS.exists("/remote.json")) errorFlag = ERR_FS_RMLOAD; //warn if file itself doesn't exist diff --git a/wled00/set.cpp b/wled00/set.cpp index a63cd09c9..34f1d1ab0 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -625,7 +625,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) } } - JsonObject um = doc.createNestedObject("um"); + JsonObject um = pDoc->createNestedObject("um"); size_t args = request->args(); uint16_t j=0; diff --git a/wled00/udp.cpp b/wled00/udp.cpp index e00fe0766..4c55a9727 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -664,8 +664,8 @@ void handleNotifications() apireq += (char*)udpIn; handleSet(nullptr, apireq); } else if (udpIn[0] == '{') { //JSON API - DeserializationError error = deserializeJson(doc, udpIn); - JsonObject root = doc.as(); + DeserializationError error = deserializeJson(*pDoc, udpIn); + JsonObject root = pDoc->as(); if (!error && !root.isNull()) deserializeState(root); } releaseJSONBufferLock(); diff --git a/wled00/util.cpp b/wled00/util.cpp index 8eedee8f4..d6fa9fb18 100644 --- a/wled00/util.cpp +++ b/wled00/util.cpp @@ -209,6 +209,10 @@ bool isAsterisksOnly(const char* str, byte maxLen) //threading/network callback details: https://github.com/Aircoookie/WLED/pull/2336#discussion_r762276994 bool requestJSONBufferLock(uint8_t module) { + if (pDoc == nullptr) { + DEBUG_PRINTLN(F("ERROR: JSON buffer not allocated!")); + return false; + } unsigned long now = millis(); while (jsonBufferLock && millis()-now < 1000) delay(1); // wait for a second for buffer lock @@ -224,8 +228,8 @@ bool requestJSONBufferLock(uint8_t module) DEBUG_PRINT(F("JSON buffer locked. (")); DEBUG_PRINT(jsonBufferLock); DEBUG_PRINTLN(")"); - fileDoc = &doc; // used for applying presets (presets.cpp) - doc.clear(); + fileDoc = pDoc; // used for applying presets (presets.cpp) + pDoc->clear(); return true; } @@ -556,11 +560,12 @@ void enumerateLedmaps() { #ifndef ESP8266 if (requestJSONBufferLock(21)) { - if (readObjectFromFile(fileName, nullptr, &doc)) { + if (readObjectFromFile(fileName, nullptr, pDoc)) { size_t len = 0; - if (!doc["n"].isNull()) { + JsonObject root = pDoc->as(); + if (!root["n"].isNull()) { // name field exists - const char *name = doc["n"].as(); + const char *name = root["n"].as(); if (name != nullptr) len = strlen(name); if (len > 0 && len < 33) { ledmapNames[i-1] = new char[len+1]; diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 57a79d4d4..84140f9b1 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -346,6 +346,11 @@ void WLED::setup() DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) +/* + * The following code is obsolete as PinManager::isPinOK() will return false for reserved GPIO. + * Additionally xml.cpp will inform UI about reserved GPIO. + * + #if defined(CONFIG_IDF_TARGET_ESP32S3) // S3: reserve GPIO 33-37 for "octal" PSRAM managed_pin_type pins[] = { {33, true}, {34, true}, {35, true}, {36, true}, {37, true} }; @@ -363,12 +368,17 @@ void WLED::setup() managed_pin_type pins[] = { {16, true}, {17, true} }; pinManager.allocateMultiplePins(pins, sizeof(pins)/sizeof(managed_pin_type), PinOwner::SPI_RAM); #endif +*/ #if defined(WLED_USE_PSRAM) + pDoc = new PSRAMDynamicJsonDocument(2*JSON_BUFFER_SIZE); + if (!pDoc) pDoc = new PSRAMDynamicJsonDocument(JSON_BUFFER_SIZE); // falback if double sized buffer could not be allocated + // if the above still fails requestJsonBufferLock() will always return false preventing crashes if (psramFound()) { DEBUG_PRINT(F("Total PSRAM: ")); DEBUG_PRINT(ESP.getPsramSize()/1024); DEBUG_PRINTLN("kB"); DEBUG_PRINT(F("Free PSRAM : ")); DEBUG_PRINT(ESP.getFreePsram()/1024); DEBUG_PRINTLN("kB"); } #else + if (!pDoc) pDoc = &gDoc; // just in case ... (it should be globally assigned) DEBUG_PRINTLN(F("PSRAM not used.")); #endif #endif diff --git a/wled00/wled.h b/wled00/wled.h index 868403d3d..f799a7be9 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2312190 +#define VERSION 2312210 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG @@ -758,7 +758,12 @@ WLED_GLOBAL int8_t spi_sclk _INIT(SPISCLKPIN); #endif // global ArduinoJson buffer -WLED_GLOBAL StaticJsonDocument doc; +#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) +WLED_GLOBAL JsonDocument *pDoc _INIT(nullptr); +#else +WLED_GLOBAL StaticJsonDocument gDoc; +WLED_GLOBAL JsonDocument *pDoc _INIT(&gDoc); +#endif WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); // enable additional debug output diff --git a/wled00/wled_eeprom.cpp b/wled00/wled_eeprom.cpp index 7c9933a9a..90e7dd4b3 100644 --- a/wled00/wled_eeprom.cpp +++ b/wled00/wled_eeprom.cpp @@ -371,7 +371,7 @@ void deEEP() { DEBUGFS_PRINTLN(F("Allocating saving buffer for dEEP")); if (!requestJSONBufferLock(8)) return; - JsonObject sObj = doc.to(); + JsonObject sObj = pDoc->to(); sObj.createNestedObject("0"); EEPROM.begin(EEPSIZE); @@ -448,7 +448,7 @@ void deEEP() { releaseJSONBufferLock(); return; } - serializeJson(doc, f); + serializeJson(*pDoc, f); f.close(); releaseJSONBufferLock(); diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 4d920e340..c6e984035 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -115,21 +115,21 @@ void handleSerial() bool verboseResponse = false; if (!requestJSONBufferLock(16)) return; Serial.setTimeout(100); - DeserializationError error = deserializeJson(doc, Serial); + DeserializationError error = deserializeJson(*pDoc, Serial); if (error) { releaseJSONBufferLock(); return; } - verboseResponse = deserializeState(doc.as()); + verboseResponse = deserializeState(pDoc->as()); //only send response if TX pin is unused for other purposes if (verboseResponse && (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut)) { - doc.clear(); - JsonObject state = doc.createNestedObject("state"); + pDoc->clear(); + JsonObject state = pDoc->createNestedObject("state"); serializeState(state); - JsonObject info = doc.createNestedObject("info"); + JsonObject info = pDoc->createNestedObject("info"); serializeInfo(info); - serializeJson(doc, Serial); + serializeJson(*pDoc, Serial); Serial.println(); } releaseJSONBufferLock(); diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 7d9d1a1ec..dcb21990e 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -180,8 +180,8 @@ void initServer() if (!requestJSONBufferLock(14)) return; - DeserializationError error = deserializeJson(doc, (uint8_t*)(request->_tempObject)); - JsonObject root = doc.as(); + DeserializationError error = deserializeJson(*pDoc, (uint8_t*)(request->_tempObject)); + JsonObject root = pDoc->as(); if (error || root.isNull()) { releaseJSONBufferLock(); serveJsonError(request, 400, ERR_JSON); diff --git a/wled00/ws.cpp b/wled00/ws.cpp index a4deca4c4..7082a848d 100644 --- a/wled00/ws.cpp +++ b/wled00/ws.cpp @@ -38,8 +38,8 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp bool verboseResponse = false; if (!requestJSONBufferLock(11)) return; - DeserializationError error = deserializeJson(doc, data, len); - JsonObject root = doc.as(); + DeserializationError error = deserializeJson(*pDoc, data, len); + JsonObject root = pDoc->as(); if (error || root.isNull()) { releaseJSONBufferLock(); return; @@ -103,13 +103,13 @@ void sendDataWs(AsyncWebSocketClient * client) if (!requestJSONBufferLock(12)) return; - JsonObject state = doc.createNestedObject("state"); + JsonObject state = pDoc->createNestedObject("state"); serializeState(state); - JsonObject info = doc.createNestedObject("info"); + JsonObject info = pDoc->createNestedObject("info"); serializeInfo(info); - size_t len = measureJson(doc); - DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", doc.memoryUsage(), len); + size_t len = measureJson(*pDoc); + DEBUG_PRINTF("JSON buffer size: %u for WS request (%u).\n", pDoc->memoryUsage(), len); size_t heap1 = ESP.getFreeHeap(); DEBUG_PRINT(F("heap ")); DEBUG_PRINTLN(ESP.getFreeHeap()); @@ -136,7 +136,7 @@ void sendDataWs(AsyncWebSocketClient * client) } buffer->lock(); - serializeJson(doc, (char *)buffer->get(), len); + serializeJson(*pDoc, (char *)buffer->get(), len); DEBUG_PRINT(F("Sending WS data ")); if (client) { diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 9a7fc4acd..05842911b 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -133,7 +133,7 @@ void appendGPIOinfo() { // usermod pin reservations will become unnecessary when settings pages will read cfg.json directly if (requestJSONBufferLock(6)) { // if we can't allocate JSON buffer ignore usermod pins - JsonObject mods = doc.createNestedObject(F("um")); + JsonObject mods = pDoc->createNestedObject(F("um")); usermods.addToConfig(mods); if (!mods.isNull()) fillUMPins(mods); releaseJSONBufferLock();