Revert back to using FirebaseJson instead of ArduinoJson

There is no convenient way to access arrays of Json objects and nested keys such as testarray/[2]/myvalue using ArduinoJson. It would at the very least to split the path into a number of individual strings and then access the value like json[testarray][2][myvalue] More details in https://arduinojson.org/v6/doc/deserialization/ . Conclusion: too complicated.
This commit is contained in:
Fribur 2024-01-16 19:32:02 -05:00
parent 8392c7cd8c
commit 75e3d03ea4
2 changed files with 7 additions and 6 deletions

View File

@ -47,6 +47,7 @@ lib_deps =
https://github.com/coryjfowler/MCP_CAN_lib
plerup/EspSoftwareSerial @ ^8.0.1
https://github.com/dok-net/ghostl @ ^1.0.1
mobizt/FirebaseJson @ ^3.0.6
rweather/Crypto@^0.4.0
extra_scripts =

View File

@ -3,7 +3,7 @@
#include "HttpPowerMeter.h"
#include "MessageOutput.h"
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <FirebaseJson.h>
#include <Crypto.h>
#include <SHA256.h>
#include <base64.h>
@ -204,13 +204,13 @@ bool HttpPowerMeterClass::tryGetFloatValueForPhase(int phase, int httpCode, cons
bool success = false;
if (httpCode == HTTP_CODE_OK) {
httpResponse = httpClient.getString(); //very unfortunate that we cannot parse WifiClient stream directly
StaticJsonDocument<2048> json; //however creating these allocations on stack should be fine to avoid heap fragmentation
deserializeJson(json, httpResponse);
if(!json.containsKey(jsonPath))
{
FirebaseJson json;
json.setJsonData(httpResponse);
FirebaseJsonData value;
if (!json.get(value, jsonPath)) {
snprintf_P(httpPowerMeterError, sizeof(httpPowerMeterError), PSTR("[HttpPowerMeter] Couldn't find a value for phase %i with Json query \"%s\""), phase, jsonPath);
}else {
power[phase] = json[jsonPath].as<float>();
power[phase] = value.to<float>();
//MessageOutput.printf("Power for Phase %i: %5.2fW\r\n", phase, power[phase]);
success = true;
}