Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to ArduinoJson 7.1.0 #777

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ESPixelStick/ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void TestHeap(uint32_t Id)
DEBUG_V(String("Allocate JSON document. Size = ") + String(20 * 1024));
DEBUG_V(String("Heap Before: ") + ESP.getFreeHeap());
{
DynamicJsonDocument jsonDoc(20 * 1024);
JsonDocument jsonDoc;
}
DEBUG_V(String(" Heap After: ") + ESP.getFreeHeap());
}
Expand Down Expand Up @@ -371,11 +371,11 @@ bool deserializeCore (JsonObject & json)
return DataHasBeenAccepted;
}

void deserializeCoreHandler (DynamicJsonDocument & jsonDoc)
void deserializeCoreHandler (JsonDocument & jsonDoc)
{
// DEBUG_START;

// extern void PrettyPrint(DynamicJsonDocument & jsonStuff, String Name);
// extern void PrettyPrint(JsonDocument & jsonStuff, String Name);
// PrettyPrint(jsonDoc, "deserializeCoreHandler");

JsonObject json = jsonDoc.as<JsonObject>();
Expand All @@ -392,8 +392,8 @@ void SaveConfig()
ConfigSaveNeeded = false;

// Create buffer and root object
DynamicJsonDocument jsonConfigDoc(2048);
JsonObject JsonConfig = jsonConfigDoc.createNestedObject(CN_system);
JsonDocument jsonConfigDoc;
JsonObject JsonConfig = jsonConfigDoc[CN_system].to<JsonObject>();

GetConfig(JsonConfig);

Expand Down Expand Up @@ -438,7 +438,7 @@ void GetConfig (JsonObject & json)
json[CN_cfgver] = CurrentConfigVersion;

// Device
JsonObject device = json.createNestedObject(CN_device);
JsonObject device = json[CN_device].to<JsonObject>();
device[CN_id] = config.id;
device[CN_blanktime] = config.BlankDelay;

Expand All @@ -459,8 +459,8 @@ String serializeCore(bool pretty)
// DEBUG_START;

// Create buffer and root object
DynamicJsonDocument jsonConfigDoc(2048);
JsonObject JsonConfig = jsonConfigDoc.createNestedObject();
JsonDocument jsonConfigDoc;
JsonObject JsonConfig = jsonConfigDoc.add<JsonObject>();

String jsonConfigString;

Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct {
} config_t;

String serializeCore (bool pretty = false);
void deserializeCoreHandler (DynamicJsonDocument& jsonDoc);
void deserializeCoreHandler (JsonDocument& jsonDoc);
bool deserializeCore (JsonObject & json);
bool dsDevice (JsonObject & json);
bool dsNetwork (JsonObject & json);
Expand Down
18 changes: 2 additions & 16 deletions ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,21 +606,9 @@ bool c_FileMgr::LoadFlashFile (const String& FileName, DeserializationHandler Ha
size_t JsonDocSize = file.size () * 3;
// DEBUG_V(String("Allocate JSON document. Size = ") + String(JsonDocSize));
// DEBUG_V(String("Heap: ") + ESP.getFreeHeap());
DynamicJsonDocument jsonDoc(JsonDocSize);
JsonDocument jsonDoc;
// DEBUG_V(String("jsonDoc.capacity: ") + String(jsonDoc.capacity()));

// did we get enough memory?
if(jsonDoc.capacity() < JsonDocSize)
{
logcon (String(CN_stars) + CfgFileMessagePrefix + String (F ("Could Not Allocate enough memory to process config ")) + CN_stars);

// DEBUG_V(String("Allocate JSON document. Size = ") + String(JsonDocSize));
// DEBUG_V(String("Heap: ") + ESP.getFreeHeap());
// DEBUG_V(String("jsonDoc.capacity: ") + String(jsonDoc.capacity()));
file.close ();
break;
}

// DEBUG_V ("Convert File to JSON document");
DeserializationError error = deserializeJson (jsonDoc, file);
file.close ();
Expand All @@ -639,12 +627,10 @@ bool c_FileMgr::LoadFlashFile (const String& FileName, DeserializationHandler Ha
break;
}

// extern void PrettyPrint(DynamicJsonDocument & jsonStuff, String Name);
// extern void PrettyPrint(JsonDocument & jsonStuff, String Name);
// PrettyPrint(jsonDoc, CfgFileMessagePrefix);

// DEBUG_V ();
jsonDoc.garbageCollect ();

logcon (CfgFileMessagePrefix + String (F ("loaded.")));

// DEBUG_V ();
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/FileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class c_FileMgr

bool handleFileUpload (const String & filename, size_t index, uint8_t * data, size_t len, bool final, uint32_t totalLen);

typedef std::function<void (DynamicJsonDocument& json)> DeserializationHandler;
typedef std::function<void (JsonDocument& json)> DeserializationHandler;

typedef enum
{
Expand Down
21 changes: 8 additions & 13 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static EFUpdate efupdate; /// EFU Update Handler
static AsyncWebServer webServer (HTTP_PORT); // Web Server

//-----------------------------------------------------------------------------
void PrettyPrint(DynamicJsonDocument &jsonStuff, String Name)
void PrettyPrint(JsonDocument &jsonStuff, String Name)
{
// DEBUG_V ("---------------------------------------------");
LOG_PORT.println (String (F ("---- Pretty Print: '")) + Name + "'");
Expand Down Expand Up @@ -557,14 +557,9 @@ void c_WebMgr::GetDeviceOptions ()
// set up a framework to get the option data
WebJsonDoc->clear ();

if (0 == WebJsonDoc->capacity ())
{
logcon (F ("ERROR: Failed to allocate memory for the GetDeviceOptions web request response."));
}

// DEBUG_V ("");
JsonObject WebOptions = WebJsonDoc->createNestedObject (F ("options"));
JsonObject JsonDeviceOptions = WebOptions.createNestedObject (CN_device);
JsonObject WebOptions = (*WebJsonDoc)[F ("options")].to<JsonObject>();
JsonObject JsonDeviceOptions = WebOptions[CN_device].to<JsonObject> ();
// DEBUG_V("");

// PrettyPrint (WebOptions);
Expand All @@ -585,8 +580,8 @@ void c_WebMgr::CreateAdminInfoFile ()
{
// DEBUG_START;

DynamicJsonDocument AdminJsonDoc(1024);
JsonObject jsonAdmin = AdminJsonDoc.createNestedObject (F ("admin"));
JsonDocument AdminJsonDoc;
JsonObject jsonAdmin = AdminJsonDoc[F ("admin")].to<JsonObject> ();

jsonAdmin[CN_version] = VERSION;
jsonAdmin["built"] = BUILD_DATE;
Expand Down Expand Up @@ -722,10 +717,10 @@ void c_WebMgr::ProcessXJRequest (AsyncWebServerRequest* client)
{
// DEBUG_START;

DynamicJsonDocument WebJsonDoc(STATUS_DOC_SIZE);
JsonDocument WebJsonDoc;
WebJsonDoc.clear ();
JsonObject status = WebJsonDoc.createNestedObject (CN_status);
JsonObject system = status.createNestedObject (CN_system);
JsonObject status = WebJsonDoc[CN_status].to<JsonObject> ();
JsonObject system = status[CN_system].to<JsonObject> ();

system[F ("freeheap")] = ESP.getFreeHeap ();
system[F ("uptime")] = millis ();
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/WebMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class c_WebMgr

using WebJsonDocument = BasicJsonDocument<SpiRamAllocator>;
#else
using WebJsonDocument = DynamicJsonDocument;
using WebJsonDocument = JsonDocument;
#endif // def BOARD_HAS_PSRAM

WebJsonDocument *WebJsonDoc = nullptr;
Expand Down
8 changes: 2 additions & 6 deletions ESPixelStick/src/input/InputAlexa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ void c_InputAlexa::GetConfig (JsonObject & jsonConfig)
void c_InputAlexa::GetStatus (JsonObject& /* jsonStatus */)
{
// DEBUG_START;

// JsonObject mqttStatus = jsonStatus.createNestedObject (F ("mqtt"));
// mqttStatus["unifirst"] = startUniverse;

// DEBUG_END;

} // GetStatus
Expand Down Expand Up @@ -170,8 +166,8 @@ void c_InputAlexa::onMessage(EspalexaDevice * pDevice)
// DEBUG_V (String ("pDevice->getG: ") + String (pDevice->getG ()));
// DEBUG_V (String ("pDevice->getB: ") + String (pDevice->getB ()));

DynamicJsonDocument JsonConfigDoc (1024);
JsonObject JsonConfig = JsonConfigDoc.createNestedObject (CN_config);
JsonDocument JsonConfigDoc;
JsonObject JsonConfig = JsonConfigDoc[CN_config].to<JsonObject> ();

JsonConfig[CN_EffectSpeed] = 1;
JsonConfig[CN_EffectReverse] = false;
Expand Down
6 changes: 3 additions & 3 deletions ESPixelStick/src/input/InputArtnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void c_InputArtnet::GetStatus (JsonObject & jsonStatus)
{
// DEBUG_START;

JsonObject ArtnetStatus = jsonStatus.createNestedObject (F ("Artnet"));
JsonObject ArtnetStatus = jsonStatus[F ("Artnet")].to<JsonObject> ();
ArtnetStatus[CN_unifirst] = startUniverse;
ArtnetStatus[CN_unilast] = LastUniverse;
ArtnetStatus[CN_unichanlim] = ChannelsPerUniverse;
Expand All @@ -97,11 +97,11 @@ void c_InputArtnet::GetStatus (JsonObject & jsonStatus)
ArtnetStatus[CN_last_clientIP] = pArtnet->getRemoteIP().toString ();
ArtnetStatus[CN_PollCounter] = PollCounter;

JsonArray ArtnetUniverseStatus = ArtnetStatus.createNestedArray (CN_channels);
JsonArray ArtnetUniverseStatus = ArtnetStatus[CN_channels].to<JsonArray> ();

for (auto & CurrentUniverse : UniverseArray)
{
JsonObject ArtnetCurrentUniverseStatus = ArtnetUniverseStatus.createNestedObject ();
JsonObject ArtnetCurrentUniverseStatus = ArtnetUniverseStatus.add<JsonObject> ();

ArtnetCurrentUniverseStatus[CN_errors] = CurrentUniverse.SequenceErrorCounter;
ArtnetCurrentUniverseStatus[CN_num_packets] = CurrentUniverse.num_packets;
Expand Down
6 changes: 3 additions & 3 deletions ESPixelStick/src/input/InputDDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void c_InputDDP::GetStatus (JsonObject& jsonStatus)
{
// DEBUG_START;

JsonObject ddpStatus = jsonStatus.createNestedObject (F ("ddp"));
JsonObject ddpStatus = jsonStatus[F ("ddp")].to<JsonObject> ();
// DEBUG_V ("");

ddpStatus["packetsreceived"] = stats.packetsReceived;
Expand Down Expand Up @@ -317,8 +317,8 @@ void c_InputDDP::ProcessReceivedQuery ()
{
// DEBUG_V ("DDP_ID_CONFIG query");

DynamicJsonDocument JsonConfigDoc (2048);
JsonObject JsonConfig = JsonConfigDoc.createNestedObject (CN_config);
JsonDocument JsonConfigDoc;
JsonObject JsonConfig = JsonConfigDoc[CN_config].to<JsonObject> ();
String hostname;
NetworkMgr.GetHostname (hostname);
JsonConfig[CN_hostname] = hostname;
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputDisabled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void c_InputDisabled::GetStatus (JsonObject & jsonStatus)
{
// DEBUG_START;

JsonObject Status = jsonStatus.createNestedObject (F ("disabled"));
JsonObject Status = jsonStatus[F ("disabled")].to<JsonObject> ();
Status[CN_id] = InputChannelId;

// DEBUG_END;
Expand Down
6 changes: 3 additions & 3 deletions ESPixelStick/src/input/InputE131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void c_InputE131::GetStatus (JsonObject & jsonStatus)
{
// DEBUG_START;

JsonObject e131Status = jsonStatus.createNestedObject (F ("e131"));
JsonObject e131Status = jsonStatus[F ("e131")].to<JsonObject> ();
e131Status[CN_id] = InputChannelId;
e131Status[CN_unifirst] = startUniverse;
e131Status[CN_unilast ] = LastUniverse;
Expand All @@ -102,11 +102,11 @@ void c_InputE131::GetStatus (JsonObject & jsonStatus)
e131Status[CN_last_clientIP] = uint32_t(e131->stats.last_clientIP);
// DEBUG_V ("");

JsonArray e131UniverseStatus = e131Status.createNestedArray (CN_channels);
JsonArray e131UniverseStatus = e131Status[CN_channels].to<JsonArray> ();
uint32_t TotalErrors = e131->stats.packet_errors;
for (auto & CurrentUniverse : UniverseArray)
{
JsonObject e131CurrentUniverseStatus = e131UniverseStatus.createNestedObject ();
JsonObject e131CurrentUniverseStatus = e131UniverseStatus.add<JsonObject> ();

e131CurrentUniverseStatus[CN_errors] = CurrentUniverse.SequenceErrorCounter;
TotalErrors += CurrentUniverse.SequenceErrorCounter;
Expand Down
18 changes: 9 additions & 9 deletions ESPixelStick/src/input/InputEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,31 @@ void c_InputEffectEngine::GetConfig (JsonObject& jsonConfig)

// DEBUG_V ("");

JsonArray EffectsArray = jsonConfig.createNestedArray (CN_effects);
JsonArray EffectsArray = jsonConfig[CN_effects].to<JsonArray> ();
// DEBUG_V ("");

for (EffectDescriptor_t currentEffect : ListOfEffects)
{
// DEBUG_V ("");
JsonObject currentJsonEntry = EffectsArray.createNestedObject ();
JsonObject currentJsonEntry = EffectsArray.add<JsonObject> ();
currentJsonEntry[CN_name] = currentEffect.name;
}

JsonArray TransitionsArray = jsonConfig.createNestedArray (CN_transitions);
JsonArray TransitionsArray = jsonConfig[CN_transitions].to<JsonArray> ();
for (auto currentTransition : TransitionColorTable)
{
// DEBUG_V ("");
JsonObject currentJsonEntry = TransitionsArray.createNestedObject ();
JsonObject currentJsonEntry = TransitionsArray.add<JsonObject> ();
currentJsonEntry["r"] = currentTransition.r;
currentJsonEntry["g"] = currentTransition.g;
currentJsonEntry["b"] = currentTransition.b;
}

JsonArray MarqueeGroupArray = jsonConfig.createNestedArray (CN_MarqueeGroups);
JsonArray MarqueeGroupArray = jsonConfig[CN_MarqueeGroups].to<JsonArray> ();
for(auto CurrentMarqueeGroup : MarqueueGroupTable)
{
JsonObject currentJsonEntry = MarqueeGroupArray.createNestedObject ();
JsonObject currentJsonEntryColor = currentJsonEntry.createNestedObject (CN_color);
JsonObject currentJsonEntry = MarqueeGroupArray.add<JsonObject> ();
JsonObject currentJsonEntryColor = currentJsonEntry[CN_color].to<JsonObject> ();
currentJsonEntryColor["r"] = CurrentMarqueeGroup.Color.r;
currentJsonEntryColor["g"] = CurrentMarqueeGroup.Color.g;
currentJsonEntryColor["b"] = CurrentMarqueeGroup.Color.b;
Expand All @@ -203,7 +203,7 @@ void c_InputEffectEngine::GetConfig (JsonObject& jsonConfig)
void c_InputEffectEngine::GetMqttEffectList (JsonObject& jsonConfig)
{
// DEBUG_START;
JsonArray EffectsArray = jsonConfig.createNestedArray (CN_effect_list);
JsonArray EffectsArray = jsonConfig[CN_effect_list].to<JsonArray> ();

for (EffectDescriptor_t currentEffect : ListOfEffects)
{
Expand Down Expand Up @@ -236,7 +236,7 @@ void c_InputEffectEngine::GetStatus (JsonObject& jsonStatus)
{
// DEBUG_START;

JsonObject Status = jsonStatus.createNestedObject (F ("effects"));
JsonObject Status = jsonStatus[F ("effects")].to<JsonObject> ();
Status[CN_currenteffect] = ActiveEffect->name;
Status[CN_id] = InputChannelId;

Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void c_InputFPPRemote::GetStatus (JsonObject& jsonStatus)
{
// DEBUG_START;

JsonObject LocalPlayerStatus = jsonStatus.createNestedObject (F ("Player"));
JsonObject LocalPlayerStatus = jsonStatus[F ("Player")].to<JsonObject> ();
LocalPlayerStatus[CN_id] = InputChannelId;
LocalPlayerStatus[CN_active] = PlayingFile ();

Expand All @@ -98,7 +98,7 @@ void c_InputFPPRemote::GetStatus (JsonObject& jsonStatus)

else if (PlayingFile ())
{
JsonObject PlayerObjectStatus = LocalPlayerStatus.createNestedObject (StatusType);
JsonObject PlayerObjectStatus = LocalPlayerStatus[StatusType].to<JsonObject> ();
pInputFPPRemotePlayItem->GetStatus (PlayerObjectStatus);
}

Expand Down
4 changes: 2 additions & 2 deletions ESPixelStick/src/input/InputFPPRemotePlayEffectFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void fsm_PlayEffect_state_Idle::Start (String & ConfigString, float )

// DEBUG_V (String ("ConfigString: '") + ConfigString + "'");
p_InputFPPRemotePlayEffect->PlayEffectTimer.StartTimer(1000 * p_InputFPPRemotePlayEffect->PlayDurationSec);

// tell the effect engine what it is supposed to be doing
DynamicJsonDocument EffectConfig (512);
JsonDocument EffectConfig;
DeserializationError error = deserializeJson ((EffectConfig), (const String)ConfigString);

// DEBUG_V ("Error Check");
Expand Down
2 changes: 1 addition & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool c_InputFPPRemotePlayList::ProcessPlayListEntry ()
// DEBUG_START;
bool response = false;

DynamicJsonDocument JsonPlayListDoc (2048);
JsonDocument JsonPlayListDoc;

extern void PrettyPrint (JsonArray & jsonStuff, String Name);
extern void PrettyPrint (JsonObject & jsonStuff, String Name);
Expand Down
Loading