@@ -609,7 +609,7 @@ void deserializeConfigFromFS() {
609
609
610
610
DEBUG_PRINTLN (F (" Reading settings from /cfg.json..." ));
611
611
612
- success = readObjectFromFile (" /cfg.json" , nullptr , &doc );
612
+ success = readObjectFromFile (" /cfg.json" , nullptr , pDoc );
613
613
if (!success) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS
614
614
releaseJSONBufferLock ();
615
615
#ifdef WLED_ADD_EEPROM_SUPPORT
@@ -630,7 +630,8 @@ void deserializeConfigFromFS() {
630
630
631
631
// NOTE: This routine deserializes *and* applies the configuration
632
632
// 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 );
634
635
releaseJSONBufferLock ();
635
636
636
637
if (needsSave) serializeConfig (); // usermods required new parameters
@@ -643,19 +644,21 @@ void serializeConfig() {
643
644
644
645
if (!requestJSONBufferLock (2 )) return ;
645
646
646
- JsonArray rev = doc.createNestedArray (" rev" );
647
+ JsonObject root = pDoc->to <JsonObject>();
648
+
649
+ JsonArray rev = root.createNestedArray (" rev" );
647
650
rev.add (1 ); // major settings revision
648
651
rev.add (0 ); // minor settings revision
649
652
650
- doc [F (" vid" )] = VERSION;
653
+ root [F (" vid" )] = VERSION;
651
654
652
- JsonObject id = doc .createNestedObject (" id" );
655
+ JsonObject id = root .createNestedObject (" id" );
653
656
id[F (" mdns" )] = cmDNS;
654
657
id[F (" name" )] = serverDescription;
655
658
id[F (" inv" )] = alexaInvocationName;
656
659
id[F (" sui" )] = simplifiedUI;
657
660
658
- JsonObject nw = doc .createNestedObject (" nw" );
661
+ JsonObject nw = root .createNestedObject (" nw" );
659
662
#ifndef WLED_DISABLE_ESPNOW
660
663
nw[F (" espnow" )] = enableESPNow;
661
664
nw[F (" linked_remote" )] = linked_remote;
@@ -677,7 +680,7 @@ void serializeConfig() {
677
680
nw_ins_0_sn.add (staticSubnet[i]);
678
681
}
679
682
680
- JsonObject ap = doc .createNestedObject (" ap" );
683
+ JsonObject ap = root .createNestedObject (" ap" );
681
684
ap[F (" ssid" )] = apSSID;
682
685
ap[F (" pskl" )] = strlen (apPass);
683
686
ap[F (" chan" )] = apChannel;
@@ -690,12 +693,12 @@ void serializeConfig() {
690
693
ap_ip.add (2 );
691
694
ap_ip.add (1 );
692
695
693
- JsonObject wifi = doc .createNestedObject (" wifi" );
696
+ JsonObject wifi = root .createNestedObject (" wifi" );
694
697
wifi[F (" sleep" )] = !noWifiSleep;
695
698
wifi[F (" phy" )] = (int )force802_3g;
696
699
697
700
#ifdef WLED_USE_ETHERNET
698
- JsonObject ethernet = doc .createNestedObject (" eth" );
701
+ JsonObject ethernet = root .createNestedObject (" eth" );
699
702
ethernet[" type" ] = ethernetType;
700
703
if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
701
704
JsonArray pins = ethernet.createNestedArray (" pin" );
@@ -718,7 +721,7 @@ void serializeConfig() {
718
721
}
719
722
#endif
720
723
721
- JsonObject hw = doc .createNestedObject (" hw" );
724
+ JsonObject hw = root .createNestedObject (" hw" );
722
725
723
726
JsonObject hw_led = hw.createNestedObject (" led" );
724
727
hw_led[F (" total" )] = strip.getLengthTotal (); // provided for compatibility on downgrade and per-output ABL
@@ -830,7 +833,7 @@ void serializeConfig() {
830
833
// JsonObject hw_status = hw.createNestedObject("status");
831
834
// hw_status["pin"] = -1;
832
835
833
- JsonObject light = doc .createNestedObject (F (" light" ));
836
+ JsonObject light = root .createNestedObject (F (" light" ));
834
837
light[F (" scale-bri" )] = briMultiplier;
835
838
light[F (" pal-mode" )] = strip.paletteBlend ;
836
839
light[F (" aseg" )] = autoSegments;
@@ -853,12 +856,12 @@ void serializeConfig() {
853
856
light_nl[F (" tbri" )] = nightlightTargetBri;
854
857
light_nl[" macro" ] = macroNl;
855
858
856
- JsonObject def = doc .createNestedObject (" def" );
859
+ JsonObject def = root .createNestedObject (" def" );
857
860
def[" ps" ] = bootPreset;
858
861
def[" on" ] = turnOnAtBoot;
859
862
def[" bri" ] = briS;
860
863
861
- JsonObject interfaces = doc .createNestedObject (" if" );
864
+ JsonObject interfaces = root .createNestedObject (" if" );
862
865
863
866
JsonObject if_sync = interfaces.createNestedObject (" sync" );
864
867
if_sync[F (" port0" )] = udpPort;
@@ -961,7 +964,7 @@ void serializeConfig() {
961
964
if_ntp[F (" ln" )] = longitude;
962
965
if_ntp[F (" lt" )] = latitude;
963
966
964
- JsonObject ol = doc .createNestedObject (" ol" );
967
+ JsonObject ol = root .createNestedObject (" ol" );
965
968
ol[F (" clock" )] = overlayCurrent;
966
969
ol[F (" cntdwn" )] = countdownMode;
967
970
@@ -971,7 +974,7 @@ void serializeConfig() {
971
974
ol[F (" o5m" )] = analogClock5MinuteMarks;
972
975
ol[F (" osec" )] = analogClockSecondsTrail;
973
976
974
- JsonObject timers = doc .createNestedObject (F (" timers" ));
977
+ JsonObject timers = root .createNestedObject (F (" timers" ));
975
978
976
979
JsonObject cntdwn = timers.createNestedObject (F (" cntdwn" ));
977
980
JsonArray goal = cntdwn.createNestedArray (F (" goal" ));
@@ -999,14 +1002,14 @@ void serializeConfig() {
999
1002
}
1000
1003
}
1001
1004
1002
- JsonObject ota = doc .createNestedObject (" ota" );
1005
+ JsonObject ota = root .createNestedObject (" ota" );
1003
1006
ota[F (" lock" )] = otaLock;
1004
1007
ota[F (" lock-wifi" )] = wifiLock;
1005
1008
ota[F (" pskl" )] = strlen (otaPass);
1006
1009
ota[F (" aota" )] = aOtaEnabled;
1007
1010
1008
1011
#ifdef WLED_ENABLE_DMX
1009
- JsonObject dmx = doc .createNestedObject (" dmx" );
1012
+ JsonObject dmx = root .createNestedObject (" dmx" );
1010
1013
dmx[F (" chan" )] = DMXChannels;
1011
1014
dmx[F (" gap" )] = DMXGap;
1012
1015
dmx[" start" ] = DMXStart;
@@ -1020,11 +1023,11 @@ void serializeConfig() {
1020
1023
dmx[F (" e131proxy" )] = e131ProxyUniverse;
1021
1024
#endif
1022
1025
1023
- JsonObject usermods_settings = doc .createNestedObject (" um" );
1026
+ JsonObject usermods_settings = root .createNestedObject (" um" );
1024
1027
usermods.addToConfig (usermods_settings);
1025
1028
1026
1029
File f = WLED_FS.open (" /cfg.json" , " w" );
1027
- if (f) serializeJson (doc , f);
1030
+ if (f) serializeJson (root , f);
1028
1031
f.close ();
1029
1032
releaseJSONBufferLock ();
1030
1033
@@ -1037,19 +1040,21 @@ bool deserializeConfigSec() {
1037
1040
1038
1041
if (!requestJSONBufferLock (3 )) return false ;
1039
1042
1040
- bool success = readObjectFromFile (" /wsec.json" , nullptr , &doc );
1043
+ bool success = readObjectFromFile (" /wsec.json" , nullptr , pDoc );
1041
1044
if (!success) {
1042
1045
releaseJSONBufferLock ();
1043
1046
return false ;
1044
1047
}
1045
1048
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 ];
1047
1052
getStringFromJson (clientPass, nw_ins_0[" psk" ], 65 );
1048
1053
1049
- JsonObject ap = doc [" ap" ];
1054
+ JsonObject ap = root [" ap" ];
1050
1055
getStringFromJson (apPass, ap[" psk" ] , 65 );
1051
1056
1052
- [[maybe_unused]] JsonObject interfaces = doc [" if" ];
1057
+ [[maybe_unused]] JsonObject interfaces = root [" if" ];
1053
1058
1054
1059
#ifdef WLED_ENABLE_MQTT
1055
1060
JsonObject if_mqtt = interfaces[" mqtt" ];
@@ -1060,10 +1065,10 @@ bool deserializeConfigSec() {
1060
1065
getStringFromJson (hueApiKey, interfaces[" hue" ][F (" key" )], 47 );
1061
1066
#endif
1062
1067
1063
- getStringFromJson (settingsPIN, doc [" pin" ], 5 );
1068
+ getStringFromJson (settingsPIN, root [" pin" ], 5 );
1064
1069
correctPIN = !strlen (settingsPIN);
1065
1070
1066
- JsonObject ota = doc [" ota" ];
1071
+ JsonObject ota = root [" ota" ];
1067
1072
getStringFromJson (otaPass, ota[F (" pwd" )], 33 );
1068
1073
CJSON (otaLock, ota[F (" lock" )]);
1069
1074
CJSON (wifiLock, ota[F (" lock-wifi" )]);
@@ -1078,17 +1083,19 @@ void serializeConfigSec() {
1078
1083
1079
1084
if (!requestJSONBufferLock (4 )) return ;
1080
1085
1081
- JsonObject nw = doc.createNestedObject (" nw" );
1086
+ JsonObject root = pDoc->to <JsonObject>();
1087
+
1088
+ JsonObject nw = root.createNestedObject (" nw" );
1082
1089
1083
1090
JsonArray nw_ins = nw.createNestedArray (" ins" );
1084
1091
1085
1092
JsonObject nw_ins_0 = nw_ins.createNestedObject ();
1086
1093
nw_ins_0[" psk" ] = clientPass;
1087
1094
1088
- JsonObject ap = doc .createNestedObject (" ap" );
1095
+ JsonObject ap = root .createNestedObject (" ap" );
1089
1096
ap[" psk" ] = apPass;
1090
1097
1091
- [[maybe_unused]] JsonObject interfaces = doc .createNestedObject (" if" );
1098
+ [[maybe_unused]] JsonObject interfaces = root .createNestedObject (" if" );
1092
1099
#ifdef WLED_ENABLE_MQTT
1093
1100
JsonObject if_mqtt = interfaces.createNestedObject (" mqtt" );
1094
1101
if_mqtt[" psk" ] = mqttPass;
@@ -1098,16 +1105,16 @@ void serializeConfigSec() {
1098
1105
if_hue[F (" key" )] = hueApiKey;
1099
1106
#endif
1100
1107
1101
- doc [" pin" ] = settingsPIN;
1108
+ root [" pin" ] = settingsPIN;
1102
1109
1103
- JsonObject ota = doc .createNestedObject (" ota" );
1110
+ JsonObject ota = root .createNestedObject (" ota" );
1104
1111
ota[F (" pwd" )] = otaPass;
1105
1112
ota[F (" lock" )] = otaLock;
1106
1113
ota[F (" lock-wifi" )] = wifiLock;
1107
1114
ota[F (" aota" )] = aOtaEnabled;
1108
1115
1109
1116
File f = WLED_FS.open (" /wsec.json" , " w" );
1110
- if (f) serializeJson (doc , f);
1117
+ if (f) serializeJson (root , f);
1111
1118
f.close ();
1112
1119
releaseJSONBufferLock ();
1113
1120
}
0 commit comments