@@ -609,7 +609,7 @@ void deserializeConfigFromFS() {
609609
610610 DEBUG_PRINTLN (F (" Reading settings from /cfg.json..." ));
611611
612- success = readObjectFromFile (" /cfg.json" , nullptr , &doc );
612+ success = readObjectFromFile (" /cfg.json" , nullptr , pDoc );
613613 if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS
614614 releaseJSONBufferLock ();
615615 #ifdef WLED_ADD_EEPROM_SUPPORT
@@ -630,7 +630,8 @@ void deserializeConfigFromFS() {
630630
631631 // NOTE: This routine deserializes *and* applies the configuration
632632 // Therefore, must also initialize ethernet from this function
633- bool needsSave = deserializeConfig (doc.as <JsonObject>(), true );
633+ JsonObject root = pDoc->as <JsonObject>();
634+ bool needsSave = deserializeConfig (root, true );
634635 releaseJSONBufferLock ();
635636
636637 if (needsSave) serializeConfig (); // usermods required new parameters
@@ -643,19 +644,21 @@ void serializeConfig() {
643644
644645 if (!requestJSONBufferLock (2 )) return ;
645646
646- JsonArray rev = doc.createNestedArray (" rev" );
647+ JsonObject root = pDoc->to <JsonObject>();
648+
649+ JsonArray rev = root.createNestedArray (" rev" );
647650 rev.add (1 ); // major settings revision
648651 rev.add (0 ); // minor settings revision
649652
650- doc [F (" vid" )] = VERSION;
653+ root [F (" vid" )] = VERSION;
651654
652- JsonObject id = doc .createNestedObject (" id" );
655+ JsonObject id = root .createNestedObject (" id" );
653656 id[F (" mdns" )] = cmDNS;
654657 id[F (" name" )] = serverDescription;
655658 id[F (" inv" )] = alexaInvocationName;
656659 id[F (" sui" )] = simplifiedUI;
657660
658- JsonObject nw = doc .createNestedObject (" nw" );
661+ JsonObject nw = root .createNestedObject (" nw" );
659662#ifndef WLED_DISABLE_ESPNOW
660663 nw[F (" espnow" )] = enableESPNow;
661664 nw[F (" linked_remote" )] = linked_remote;
@@ -677,7 +680,7 @@ void serializeConfig() {
677680 nw_ins_0_sn.add (staticSubnet[i]);
678681 }
679682
680- JsonObject ap = doc .createNestedObject (" ap" );
683+ JsonObject ap = root .createNestedObject (" ap" );
681684 ap[F (" ssid" )] = apSSID;
682685 ap[F (" pskl" )] = strlen (apPass);
683686 ap[F (" chan" )] = apChannel;
@@ -690,12 +693,12 @@ void serializeConfig() {
690693 ap_ip.add (2 );
691694 ap_ip.add (1 );
692695
693- JsonObject wifi = doc .createNestedObject (" wifi" );
696+ JsonObject wifi = root .createNestedObject (" wifi" );
694697 wifi[F (" sleep" )] = !noWifiSleep;
695698 wifi[F (" phy" )] = (int )force802_3g;
696699
697700 #ifdef WLED_USE_ETHERNET
698- JsonObject ethernet = doc .createNestedObject (" eth" );
701+ JsonObject ethernet = root .createNestedObject (" eth" );
699702 ethernet[" type" ] = ethernetType;
700703 if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
701704 JsonArray pins = ethernet.createNestedArray (" pin" );
@@ -718,7 +721,7 @@ void serializeConfig() {
718721 }
719722 #endif
720723
721- JsonObject hw = doc .createNestedObject (" hw" );
724+ JsonObject hw = root .createNestedObject (" hw" );
722725
723726 JsonObject hw_led = hw.createNestedObject (" led" );
724727 hw_led[F (" total" )] = strip.getLengthTotal (); // provided for compatibility on downgrade and per-output ABL
@@ -830,7 +833,7 @@ void serializeConfig() {
830833 // JsonObject hw_status = hw.createNestedObject("status");
831834 // hw_status["pin"] = -1;
832835
833- JsonObject light = doc .createNestedObject (F (" light" ));
836+ JsonObject light = root .createNestedObject (F (" light" ));
834837 light[F (" scale-bri" )] = briMultiplier;
835838 light[F (" pal-mode" )] = strip.paletteBlend ;
836839 light[F (" aseg" )] = autoSegments;
@@ -853,12 +856,12 @@ void serializeConfig() {
853856 light_nl[F (" tbri" )] = nightlightTargetBri;
854857 light_nl[" macro" ] = macroNl;
855858
856- JsonObject def = doc .createNestedObject (" def" );
859+ JsonObject def = root .createNestedObject (" def" );
857860 def[" ps" ] = bootPreset;
858861 def[" on" ] = turnOnAtBoot;
859862 def[" bri" ] = briS;
860863
861- JsonObject interfaces = doc .createNestedObject (" if" );
864+ JsonObject interfaces = root .createNestedObject (" if" );
862865
863866 JsonObject if_sync = interfaces.createNestedObject (" sync" );
864867 if_sync[F (" port0" )] = udpPort;
@@ -961,7 +964,7 @@ void serializeConfig() {
961964 if_ntp[F (" ln" )] = longitude;
962965 if_ntp[F (" lt" )] = latitude;
963966
964- JsonObject ol = doc .createNestedObject (" ol" );
967+ JsonObject ol = root .createNestedObject (" ol" );
965968 ol[F (" clock" )] = overlayCurrent;
966969 ol[F (" cntdwn" )] = countdownMode;
967970
@@ -971,7 +974,7 @@ void serializeConfig() {
971974 ol[F (" o5m" )] = analogClock5MinuteMarks;
972975 ol[F (" osec" )] = analogClockSecondsTrail;
973976
974- JsonObject timers = doc .createNestedObject (F (" timers" ));
977+ JsonObject timers = root .createNestedObject (F (" timers" ));
975978
976979 JsonObject cntdwn = timers.createNestedObject (F (" cntdwn" ));
977980 JsonArray goal = cntdwn.createNestedArray (F (" goal" ));
@@ -999,14 +1002,14 @@ void serializeConfig() {
9991002 }
10001003 }
10011004
1002- JsonObject ota = doc .createNestedObject (" ota" );
1005+ JsonObject ota = root .createNestedObject (" ota" );
10031006 ota[F (" lock" )] = otaLock;
10041007 ota[F (" lock-wifi" )] = wifiLock;
10051008 ota[F (" pskl" )] = strlen (otaPass);
10061009 ota[F (" aota" )] = aOtaEnabled;
10071010
10081011 #ifdef WLED_ENABLE_DMX
1009- JsonObject dmx = doc .createNestedObject (" dmx" );
1012+ JsonObject dmx = root .createNestedObject (" dmx" );
10101013 dmx[F (" chan" )] = DMXChannels;
10111014 dmx[F (" gap" )] = DMXGap;
10121015 dmx[" start" ] = DMXStart;
@@ -1020,11 +1023,11 @@ void serializeConfig() {
10201023 dmx[F (" e131proxy" )] = e131ProxyUniverse;
10211024 #endif
10221025
1023- JsonObject usermods_settings = doc .createNestedObject (" um" );
1026+ JsonObject usermods_settings = root .createNestedObject (" um" );
10241027 usermods.addToConfig (usermods_settings);
10251028
10261029 File f = WLED_FS.open (" /cfg.json" , " w" );
1027- if (f) serializeJson (doc , f);
1030+ if (f) serializeJson (root , f);
10281031 f.close ();
10291032 releaseJSONBufferLock ();
10301033
@@ -1037,19 +1040,21 @@ bool deserializeConfigSec() {
10371040
10381041 if (!requestJSONBufferLock (3 )) return false ;
10391042
1040- bool success = readObjectFromFile (" /wsec.json" , nullptr , &doc );
1043+ bool success = readObjectFromFile (" /wsec.json" , nullptr , pDoc );
10411044 if (!success) {
10421045 releaseJSONBufferLock ();
10431046 return false ;
10441047 }
10451048
1046- JsonObject nw_ins_0 = doc[" nw" ][" ins" ][0 ];
1049+ JsonObject root = pDoc->as <JsonObject>();
1050+
1051+ JsonObject nw_ins_0 = root[" nw" ][" ins" ][0 ];
10471052 getStringFromJson (clientPass, nw_ins_0[" psk" ], 65 );
10481053
1049- JsonObject ap = doc [" ap" ];
1054+ JsonObject ap = root [" ap" ];
10501055 getStringFromJson (apPass, ap[" psk" ] , 65 );
10511056
1052- [[maybe_unused]] JsonObject interfaces = doc [" if" ];
1057+ [[maybe_unused]] JsonObject interfaces = root [" if" ];
10531058
10541059#ifdef WLED_ENABLE_MQTT
10551060 JsonObject if_mqtt = interfaces[" mqtt" ];
@@ -1060,10 +1065,10 @@ bool deserializeConfigSec() {
10601065 getStringFromJson (hueApiKey, interfaces[" hue" ][F (" key" )], 47 );
10611066#endif
10621067
1063- getStringFromJson (settingsPIN, doc [" pin" ], 5 );
1068+ getStringFromJson (settingsPIN, root [" pin" ], 5 );
10641069 correctPIN = !strlen (settingsPIN);
10651070
1066- JsonObject ota = doc [" ota" ];
1071+ JsonObject ota = root [" ota" ];
10671072 getStringFromJson (otaPass, ota[F (" pwd" )], 33 );
10681073 CJSON (otaLock, ota[F (" lock" )]);
10691074 CJSON (wifiLock, ota[F (" lock-wifi" )]);
@@ -1078,17 +1083,19 @@ void serializeConfigSec() {
10781083
10791084 if (!requestJSONBufferLock (4 )) return ;
10801085
1081- JsonObject nw = doc.createNestedObject (" nw" );
1086+ JsonObject root = pDoc->to <JsonObject>();
1087+
1088+ JsonObject nw = root.createNestedObject (" nw" );
10821089
10831090 JsonArray nw_ins = nw.createNestedArray (" ins" );
10841091
10851092 JsonObject nw_ins_0 = nw_ins.createNestedObject ();
10861093 nw_ins_0[" psk" ] = clientPass;
10871094
1088- JsonObject ap = doc .createNestedObject (" ap" );
1095+ JsonObject ap = root .createNestedObject (" ap" );
10891096 ap[" psk" ] = apPass;
10901097
1091- [[maybe_unused]] JsonObject interfaces = doc .createNestedObject (" if" );
1098+ [[maybe_unused]] JsonObject interfaces = root .createNestedObject (" if" );
10921099#ifdef WLED_ENABLE_MQTT
10931100 JsonObject if_mqtt = interfaces.createNestedObject (" mqtt" );
10941101 if_mqtt[" psk" ] = mqttPass;
@@ -1098,16 +1105,16 @@ void serializeConfigSec() {
10981105 if_hue[F (" key" )] = hueApiKey;
10991106#endif
11001107
1101- doc [" pin" ] = settingsPIN;
1108+ root [" pin" ] = settingsPIN;
11021109
1103- JsonObject ota = doc .createNestedObject (" ota" );
1110+ JsonObject ota = root .createNestedObject (" ota" );
11041111 ota[F (" pwd" )] = otaPass;
11051112 ota[F (" lock" )] = otaLock;
11061113 ota[F (" lock-wifi" )] = wifiLock;
11071114 ota[F (" aota" )] = aOtaEnabled;
11081115
11091116 File f = WLED_FS.open (" /wsec.json" , " w" );
1110- if (f) serializeJson (doc , f);
1117+ if (f) serializeJson (root , f);
11111118 f.close ();
11121119 releaseJSONBufferLock ();
11131120}
0 commit comments