summaryrefslogtreecommitdiff
path: root/.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient
diff options
context:
space:
mode:
authorkrolyxon <me@krolyxon.com>2026-06-08 23:10:46 +0530
committerkrolyxon <me@krolyxon.com>2026-06-08 23:10:46 +0530
commit3120783000d0025b183b0397acaa8b769499eb38 (patch)
tree1c4f93be213f1b1d48f59e554562d847b4e7c25e /.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient
Initial gh-pages firmware hosting
Diffstat (limited to '.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient')
-rw-r--r--.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino125
1 files changed, 125 insertions, 0 deletions
diff --git a/.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino b/.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino
new file mode 100644
index 0000000..34d65f1
--- /dev/null
+++ b/.pio/libdeps/esp32-s3-n16r8/ArduinoJson/examples/JsonHttpClient/JsonHttpClient.ino
@@ -0,0 +1,125 @@
+// ArduinoJson - https://arduinojson.org
+// Copyright © 2014-2026, Benoit BLANCHON
+// MIT License
+//
+// This example shows how to parse a JSON document in an HTTP response.
+// It uses the Ethernet library, but can be easily adapted for Wifi.
+//
+// It performs a GET resquest on https://arduinojson.org/example.json
+// Here is the expected response:
+// {
+// "sensor": "gps",
+// "time": 1351824120,
+// "data": [
+// 48.756080,
+// 2.302038
+// ]
+// }
+//
+// https://arduinojson.org/v7/example/http-client/
+
+#include <ArduinoJson.h>
+#include <Ethernet.h>
+#include <SPI.h>
+
+void setup() {
+ // Initialize Serial port
+ Serial.begin(9600);
+ while (!Serial)
+ continue;
+
+ // Initialize Ethernet library
+ byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
+ if (!Ethernet.begin(mac)) {
+ Serial.println(F("Failed to configure Ethernet"));
+ return;
+ }
+ delay(1000);
+
+ Serial.println(F("Connecting..."));
+
+ // Connect to HTTP server
+ EthernetClient client;
+ client.setTimeout(10000);
+ if (!client.connect("arduinojson.org", 80)) {
+ Serial.println(F("Connection failed"));
+ return;
+ }
+
+ Serial.println(F("Connected!"));
+
+ // Send HTTP request
+ client.println(F("GET /example.json HTTP/1.0"));
+ client.println(F("Host: arduinojson.org"));
+ client.println(F("Connection: close"));
+ if (client.println() == 0) {
+ Serial.println(F("Failed to send request"));
+ client.stop();
+ return;
+ }
+
+ // Check HTTP status
+ char status[32] = {0};
+ client.readBytesUntil('\r', status, sizeof(status));
+ // It should be "HTTP/1.0 200 OK" or "HTTP/1.1 200 OK"
+ if (strcmp(status + 9, "200 OK") != 0) {
+ Serial.print(F("Unexpected response: "));
+ Serial.println(status);
+ client.stop();
+ return;
+ }
+
+ // Skip HTTP headers
+ char endOfHeaders[] = "\r\n\r\n";
+ if (!client.find(endOfHeaders)) {
+ Serial.println(F("Invalid response"));
+ client.stop();
+ return;
+ }
+
+ // Allocate the JSON document
+ JsonDocument doc;
+
+ // Parse JSON object
+ DeserializationError error = deserializeJson(doc, client);
+ if (error) {
+ Serial.print(F("deserializeJson() failed: "));
+ Serial.println(error.f_str());
+ client.stop();
+ return;
+ }
+
+ // Extract values
+ Serial.println(F("Response:"));
+ Serial.println(doc["sensor"].as<const char*>());
+ Serial.println(doc["time"].as<long>());
+ Serial.println(doc["data"][0].as<float>(), 6);
+ Serial.println(doc["data"][1].as<float>(), 6);
+
+ // Disconnect
+ client.stop();
+}
+
+void loop() {
+ // not used in this example
+}
+
+// Performance issue?
+// ------------------
+//
+// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
+// See: https://arduinojson.org/v7/how-to/improve-speed/
+
+// See also
+// --------
+//
+// https://arduinojson.org/ contains the documentation for all the functions
+// used above. It also includes an FAQ that will help you solve any
+// serialization problem.
+//
+// The book "Mastering ArduinoJson" contains a tutorial on deserialization
+// showing how to parse the response from GitHub's API. In the last chapter,
+// it shows how to parse the huge documents from OpenWeatherMap
+// and Reddit.
+// Learn more at https://arduinojson.org/book/
+// Use the coupon code TWENTY for a 20% discount ❤❤❤❤❤