Comments (4)
Hi @jgroszko,
After making the following changes, I could successfully run your program on my ESP32.
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "...";
const char* password = "...";
bool filteredJsonGet(String &url, JsonDocument &result, JsonDocument &filter) {
HTTPClient http;
http.useHTTP10(true);
http.begin(url);
Serial.println("About to get");
int httpCode = http.GET();
Serial.println("Got");
if(httpCode != 200) {
Serial.print("GET failed ");
Serial.print(httpCode);
Serial.print(" - ");
Serial.println(url);
http.end();
return false;
} else {
Serial.println("HTTP Success");
DeserializationError error = deserializeJson(result, http.getStream(), DeserializationOption::Filter(filter));
Serial.println("Deserialized json");
http.end();
if (error) {
Serial.print("GET failed ");
Serial.print(url);
Serial.print(" - deserializeJson() failed: ");
Serial.println(error.c_str());
return false;
}
if (result.overflowed()) {
Serial.print("GET failed ");
Serial.print(url);
Serial.println(" - Ran out of memory for JsonDocument");
return false;
}
Serial.println("No json errors");
}
+ return true;
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
String url = "http://worldtimeapi.org/api/timezone/America/Chicago";
JsonDocument filter;
filter["unixtime"] = true;
JsonDocument result;
if(filteredJsonGet(url, result, filter)) {
Serial.print("Success ");
- Serial.println(result["unixtime"].as<const char*>());
+ Serial.println(result["unixtime"].as<unsigned long>());
} else {
Serial.println("Fail");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
I tested with versions 2.0.14 and 2.0.16 of the Arduino Core for ESP32.
I first thought that the crash was due to calling Serial.println()
with a null string, but after checking with the implementation, I confirmed that it is safe to pass a null char pointer. Besides, the original code was not crashing my device; it just didn't write anything after Success
.
Best regards,
Benoit
from arduinojson.
PS: I just saw in your crash dump that you are using the Inkplate core. I looked at the source code and found the same protection against null pointers passed to println()
.
from arduinojson.
Hey Benoit,
Thanks for the quick response! It was definitely the missing return statement, glad it was something simple. I was afraid it'd be some pointer nonsense that I was missing.
from arduinojson.
You're welcome, @jgroszko.
Thank you for using ArduinoJson!
Don't forget to cast a star to support the project š
from arduinojson.
Related Issues (20)
- `doc[var]` doesn't work when `var` contains a string
- JsonArray.add(JsonObject) adds partial JsonObject when the JsonDocument is full HOT 6
- ArduinoJson.h: No such file or directory HOT 3
- JsonVariant tests false for both a value that doesn't exist and for a value that is zero HOT 7
- How do i create JSON array of objects using ArduinoJson library. HOT 1
- Identifying JsonVariant type of a deserialized document HOT 4
- Example code results in compiler error: no match for 'operator+=' HOT 3
- In Memory Deserialization HOT 4
- v7 equivalent of validateJson HOT 2
- conversion from āArduinoJson::V704HB42::detail::enable_if<true, ArduinoJson::V704HB42::JsonVariantConst>::typeā {aka āArduinoJson::V704HB42::JsonVariantConstā} to āArduinoJson::V704HB42::JsonDocumentā is ambiguous HOT 1
- Assertion `poolIndex < count_' failed HOT 1
- Maximum string length of 13 characters HOT 2
- V6 Documentation ArduinoJson PubSubClient with StreamUtils HOT 1
- deserialize file from LittleFS crash HOT 6
- Trying to compile a 2021 program HOT 2
- Bring back zero-copy mode in v7 HOT 6
- MQTT Publish destroying Json HOT 2
- Error compiling example code SimpleParser on Arduino Web Editor NodeMCU 0.9
- JSON output is truncated. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.