Arduino get request

Arduino get request DEFAULT

In this example we learn how to send get request to a web page using NodeMCU or ESP8266? As we know all webpages are HTTP protocols, GET and POST are methods of communicating between web browser and the server. Also we look towards server side php coding. If you are looking for POST method read here.

What is HTTP?

The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.

HTTP works as a request-response protocol between a client and server. Each Hypertext Transfer Protocol (HTTP) message is either a request or a response. A server listens on a connection for a request, parses each message received, interprets the message semantics in relation to the identified request target, and responds to that request with one or more response messages. A client constructs request messages to communicate specific intentions, examines received responses to see if the intentions were carried out, and determines how to interpret the results.

A web browser may be the client, and an application on a computer that hosts a web site may be the server.

Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.

Two HTTP Request Methods: GET and POST

Two commonly used methods for a request-response between a client and server are: GET and POST.

  • GET – Requests data from a specified resource
  • POST – Submits data to be processed to a specified resource

GET

The GET method requests transfer of a current selected representation for the target resource. GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations.  Hence, when people speak of retrieving some identifiable information via HTTP, they are generally referring to making a GET request.

The GET Method

Note that the query string (name/value pairs) is sent in the URL of a GET request:

/test/demo_form.php?name1=value1&name2=value2

Some other notes on GET requests:

  • GET requests can be cached
  • GET requests remain in the browser history
  • GET requests can be bookmarked
  • GET requests should never be used when dealing with sensitive data
  • GET requests have length restrictions
  • GET requests should be used only to retrieve data

ESP8266 GET Example Code

Make changes in wifi settings, SSID and password of your wifi network and change server ip. Also change GET request data as per your server requirements.

/* * HTTP Client GET Request * Copyright (c) 2018, circuits4you.com * All rights reserved. * https://circuits4you.com * Connects to WiFi HotSpot. */ #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266HTTPClient.h> /* Set these to your desired credentials. */ const char *ssid = "circuits4you.com"; //ENTER YOUR WIFI SETTINGS const char *password = "yourPassword"; //Web/Server address to read/write from const char *host = "192.168.43.128"; //https://circuits4you.com website or IP address of server //======================================================================= // Power on setup //======================================================================= void setup() { delay(1000); Serial.begin(115200); WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect) delay(1000); WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot WiFi.begin(ssid, password); //Connect to your WiFi router Serial.println(""); Serial.print("Connecting"); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } //If connection successful show IP address in serial monitor Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP } //======================================================================= // Main Program Loop //======================================================================= void loop() { HTTPClient http; //Declare object of class HTTPClient String ADCData, station, getData, Link; int adcvalue=analogRead(A0); //Read Analog value of LDR ADCData = String(adcvalue); //String to interger conversion station = "B"; //GET Data getData = "?status=" + ADCData + "&station=" + station ; //Note "?" added at front Link = "http://192.168.43.128/c4yforum/getdemo.php" + getData; http.begin(Link); //Specify request destination int httpCode = http.GET(); //Send the request String payload = http.getString(); //Get the response payload Serial.println(httpCode); //Print HTTP return code Serial.println(payload); //Print request response payload http.end(); //Close connection delay(5000); //GET Data at every 5 seconds } //=======================================================================

Upload the code and open serial monitor, in case of any problem it will show errors.

Server side programs

Server side program consists of three parts 1. Database creation 2. Data logging and 3. Display logged data. To run this codes you need WAMP or LAMP installed (apache2, mySql and PHP)

Database creation PHP Code i.e. install.php

Enter your mySQL usename and password in code.

install.php

This program will create database and tables required for our demo application. This is run once code.

<?php //Create Data base if not exists $servername = "localhost"; $username = "root"; $password = "root"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Create database $sql = "CREATE DATABASE espdemo"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); echo "<br>"; //Connect to database and create table $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "espdemo"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //Sr No, Station, Status(OK, NM, WM, ACK) Date, Time //1 A NM 12-5-18 12:15:00 am // sql to create table $sql = "CREATE TABLE logs ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, station VARCHAR(30), status VARCHAR(30), remark VARCHAR(50), `Date` DATE NULL, `Time` TIME NULL, `TimeStamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )"; if ($conn->query($sql) === TRUE) { echo "Table logs created successfully"; } else { echo "Error creating table: " . $conn->error; } $conn->close(); ?>

Data logging PHP Code which handles GET request

getdemo.php

This is responsible for storing data into database. it will give only OK or Errors.

<?php //Creates new record as per request //Connect to database $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "espdemo"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Database Connection failed: " . $conn->connect_error); } //Get current date and time date_default_timezone_set('Asia/Kolkata'); $d = date("Y-m-d"); //echo " Date:".$d."<BR>"; $t = date("H:i:s"); if(!empty($_GET['status']) && !empty($_GET['station'])) { $status = $_GET['status']; $station = $_GET['station']; $sql = "INSERT INTO logs (station, status, Date, Time) VALUES ('".$station."', '".$status."', '".$d."', '".$t."')"; if ($conn->query($sql) === TRUE) { echo "OK"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } $conn->close(); ?>

Display logged data

view.php File

This will show logged data in web browser

<!DOCTYPE html> <html> <head> <meta http-equiv="refresh" content="5"> </head> <body> <style> #c4ytable { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; border-collapse: collapse; width: 100%; } #c4ytable td, #c4ytable th { border: 1px solid #ddd; padding: 8px; } #c4ytable tr:nth-child(even){background-color: #f2f2f2;} #c4ytable tr:hover {background-color: #ddd;} #c4ytable th { padding-top: 12px; padding-bottom: 12px; text-align: left; background-color: #00A8A9; color: white; } </style> <?php //Connect to database and create table $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "espdemo"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Database Connection failed: " . $conn->connect_error); echo "<a href='install.php'>If first time running click here to install database</a>"; } ?> <div id="cards" class="cards"> <?php $sql = "SELECT * FROM logs ORDER BY id DESC"; if ($result=mysqli_query($conn,$sql)) { // Fetch one and one row echo "<TABLE id='c4ytable'>"; echo "<TR><TH>Sr.No.</TH><TH>Station</TH><TH>ADC Value</TH><TH>Date</TH><TH>Time</TH></TR>"; while ($row=mysqli_fetch_row($result)) { echo "<TR>"; echo "<TD>".$row[0]."</TD>"; echo "<TD>".$row[1]."</TD>"; echo "<TD>".$row[2]."</TD>"; //echo "<TD>".$row[3]."</TD>"; echo "<TD>".$row[4]."</TD>"; echo "<TD>".$row[5]."</TD>"; echo "</TR>"; } echo "</TABLE>"; // Free result set mysqli_free_result($result); } mysqli_close($conn); ?> </body> </html>

Display of logged data

This way you can make your own cloud server for data logging and displaying it.

How to make POST request ? explained here

Related

Sours: https://circuits4you.com/2018/03/10/esp8266-http-get-request-example/

HTTP Client

This example for a Yún device shows how create a basic HTTP client that connects to the internet and downloads content. In this case, you'll connect to the Arduino website and download a version of the logo as ASCII text.

Open the Serial Monitor in the IDE once you've programmed the board.

Hardware Required

  • Yún board or shield

  • a wireless network connection to the internet

Circuit

There is no circuit for this example.

Yun Fritzing

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code

Include both the Bridge and HttpClient libraries

In start Bridge, and wait for a serial connection before going into .

In , create a named instance of HttpClient, and call a URL with .

As long as there are bytes from the server in the client buffer, read the bytes and print them to the serial monitor. Repeat every 5 seconds.

The complete sketch is below :

See Also

  • Bridge Library - Your reference to the Bridge Library

  • Bridge - Simple REST style calls to access analog and digital pins

  • Console Ascii Table - A complete ASCII table printed to the Console

  • Console Pixel - Turn an LED on and off through the Console

  • Console Read - Read data coming from bridge using the Console.read() function

  • Data Logger - Log data from three analog sensors to an SD card.

  • File Write - How to write file into the Yún filesystem.

  • Http Client Console - HTTP client that connects, downloads content and shows it using WiFi and Console.

  • Mailbox Read Message - How to read the messages queue, called Mailbox, using the Bridge library.

  • Process - How to run linux processes using an Yún.

  • Remote Due Blink - How to upload remotely a sketch on DUE boards.

  • Shell Commands - How to run linux shell commands using a Yún.

  • Temperature Web Panel - How to serve data from an analog input via the Yún's built-in webserver.

  • Time check - Gets the time from Linux via Bridge then parses out hours, minutes and seconds.

  • WiFi Status - Prints information about the status of your wifi connection.

  • Yún First Configuration - Easily configure your Yún device using Serial Monitor and USB port.

  • Serial Terminal - Use the Yún's 32U4 processor as a serial terminal for the Linux side on the Yún.

Last revision 2016/05/25 by SM

Last revision February 05, 2018, at 08:43 PM

Sours: https://www.arduino.cc/en/Tutorial/LibraryExamples/HttpClient/
  1. Green bible verses
  2. Destroyed baby jeans
  3. Kody brown meri
  4. Frog hooded blanket

In this guide, you’ll learn how to make HTTP GET and HTTP POST requests with the ESP32 board with Arduino IDE. We’ll cover examples on how to get values, post JSON objects, URL encoded requests, and more.

ESP32 HTTP GET and HTTP POST with Arduino IDE (JSON, URL Encoded, Text)

Recommended:ESP8266 NodeMCU HTTP GET and HTTP POST with Arduino IDE (JSON, URL Encoded, Text)

HTTP Request Methods: GET vs POST

The Hypertext Transfer Protocol (HTTP) works as a request-response protocol between a client and server. Here’s an example:

  • The ESP32 (client) submits an HTTP request to a Raspberry Pi running Node-RED (server);
  • The server returns a response to the ESP32 (client);
  • Finally, the response contains status information about the request and may also contain the requested content.

HTTP GET

GET is used to request data from a specified resource. It is often used to get values from APIs.

For example, you can have:

Note that the query string (name = temperature and value = value1) is sent in the URL of the HTTP GET request.

Or you can use a simple request to return a value or JSON object, for example:

(With HTTP GET, data is visible to everyone in the URL request.)

HTTP POST

POST is used to send data to a server to create/update a resource. For example, publish sensor readings to a server.

The data sent to the server with POST is stored in the request body of the HTTP request:

In the body request, you can also send a JSON object:

(With HTTP POST, data is not visible in the URL request. However, if it’s not encrypted, it’s still visible in the request body.)

HTTP GET/POST with ESP32

In this guide, we’ll explore the following scenarios:

  1. ESP32 HTTP GET: Value or Query in URL
  2. ESP32 HTTP GET: JSON Data Object or Plain Text
  3. ESP32 HTTP POST: URL Encoded, JSON Data Object, Plain Text

Prerequisites

Before proceeding with this tutorial, make sure you complete the following prerequisites.

Arduino IDE

We’ll program the ESP32 using Arduino IDE, so make sure you have the ESP32 add-on installed.

Arduino_JSON Library

You also need to install the Arduino_JSON library. You can install this library in the Arduino IDE Library Manager. Just go to Sketch Include Library > Manage Libraries and search for the library name as follows:

Install Arduino JSON library Arduino IDE

Parts Required

For this tutorial you need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Preparing Node-RED (optional)

As an example, we’ll create a web service with a Raspberry Pi and Node-RED to act as a web service (like an API). Basically, you’ll make HTTP GET and HTTP POST requests to your Raspberry Pi to get values or update them. You can use any other web service.

If you don’t have Node-RED installed, follow the next tutorials:

Having Node-RED running on your Raspberry Pi, go to your Raspberry Pi IP address followed by :1880.

The Node-RED interface should open. You can simply import the final flow:

Node-RED-Flow-HTTP-GET-POST-Request-Methods-ESP32-ESP8266-Arduino

Go to Menu > Import and copy the following to your Clipboard to create your Node-RED flow.

View raw code

Other Web Services or APIs

In this guide, the ESP32 performs HTTP requests to Node-RED, but you can use these examples with other services like ThingSpeak, IFTTT.com (Web Hooks service), OpenWeatherMap.org, PHP server, etc… All examples presented in this guide will also work with other APIs.

In summary, to make this guide compatible with any service, you need to search for the service API documentation. Then, you need the server name (URL or IP address), and parameters to send in the request (URL path or request body). Finally, modify our examples to integrate with any API you want to use.

1. ESP32 HTTP GET: Value or Query in URL

In the first example, the ESP32 will make an HTTP GET request to update a reading in a service. This type of request could also be used to filter a value, request a value or return a JSON object.

HTTP GET ESP32 Get Sensor Value Plain Text Status 200 OK

Code ESP32 HTTP GET with Arduino IDE

After installing the necessary board add-ons and libraries, copy the following code to your Arduino IDE, but don’t upload it yet. You need to make some changes to make it work for you.

View raw code

Setting your network credentials

Modify the next lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.

Setting your serverName

You also need to type your domain name or Node-RED IP address, so the ESP publishes the readings to your own server.

Now, upload the code to your board and it should work straight away.

Read the next section, if you want to learn how to make the HTTP GET request.

HTTP GET Request

In the loop() is where you actually make the HTTP GET request every 5 seconds with sample data:

The ESP32 makes a new request in the following URL to update the sensor field with a new temperature.

Then, the following lines of code save the HTTP response from the server.

Demonstration

With your board running the new sketch, open the Node-RED debug window. You’ll see that the sample values are being printed successfully (24.37).

2. ESP32 HTTP GET: JSON Data Object or Plain Text

This next example shows how to make an HTTP GET request to get a JSON object and decode it with the ESP32. Many APIs return data in JSON format.

HTTP GET ESP32 Get Sensor JSON Data

Copy the next sketch to your Arduino IDE (type your SSID and password):

View raw code

Setting your serverName

Enter your domain name or Node-RED IP address, so the ESP requests the sensor readings that will be retrieved in a JSON object.

Now, upload the code to your board.

HTTP GET Request (JSON Object)

In the loop(), call the httpGETRequest() function to make the HTTP GET request:

The httpGETRequest() function makes a request to Node-RED address http://192.168.1.106:1880/get-sensor and it retrieves a string with a JSON object.

Decoding JSON Object

To get access to the values, decode the JSON object and store all values in the sensorReadingsArr array.

HTTP GET Demonstration

After uploading the code, open the Arduino IDE and you’ll see that it’s receiving the following JSON data:

Then, you print the decoded JSON object in the Arduino IDE Serial Monitor.

For debugging purposes, the requested information is also printed in the Node-RED debug window.

3. ESP32 HTTP POST: URL Encoded, JSON Data Object, Plain Text

Finally, you’ll learn how to make an HTTP POST request with an ESP32.

With this example, your ESP32 can make HTTP POST requests using three different types of body requests: URL encoded, JSON object or plain text. These are the most common methods and should integrate with most APIs or web services.

HTTP POST ESP32 URL Encoded JSON Object Data Plain Text

Copy the next sketch to your Arduino IDE (type your SSID and password):

View raw code

Setting your serverName

Enter your domain name or Node-RED IP address, so the ESP posts sample sensor readings.

Now, upload the code to your board.

HTTP POST URL Encoded

To make an HTTP POST request of type URL encoded, like this

You need to run the following in your Arduino code:

HTTP POST JSON Object

Or if you prefer to make an HTTP POST request with a JSON object:

Use the next snippet:

HTTP Plain Text

If you want to send plain text or a value, use the following:

Note: the Node-RED flow we’re using (web service) is not setup to receive plain text, but if the API that you plan to integrate only accepts plain text or a value, you can use the previous snippet.

HTTP POST Demonstration

In the Node-RED debug window, you can view that your ESP is making an HTTP POST request every 5 seconds.

And in this example, those values are also sent to 3 Gauges and are displayed in Node-RED Dashboard:

Wrapping Up

In this tutorial you’ve learned how to integrate your ESP32 with online services using HTTP GET and HTTP POST requests.

HTTP GET and HTTP POST are commonly used in most web services and APIs. These can be useful in your projects to: publish your sensor readings to a web service like IFTTT, ThingSpeak; to an ESP32 or Raspberry Pi web server or to your own server; to request data from the internet or from your database, and much more.

If you’re using an ESP8266 board, read: Guide for ESP8266 NodeMCU HTTP GET and HTTP Post Requests.

You might also like reading:

I hope you liked this project. If you have any questions, post a comment below and we’ll try to get back to you.

If you like ESP32, you might consider enrolling in our course “Learn ESP32 with Arduino IDE“. You can also access our free ESP32 resources here.

Thank you for reading.




Sours: https://randomnerdtutorials.com/esp32-http-get-post-arduino/
A simple https request with Arduino ESP8266 to Matomo Analytics

Arduino - HTTP Request

The blow is the complete arduino code for making HTTP GET/POST request

#include <SPI.h>#include <Ethernet.h>byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };EthernetClient client;int HTTP_PORT = 80;String HTTP_METHOD = "GET"; char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger";voidsetup() {Serial.begin(9600);if (Ethernet.begin(mac) == 0) {Serial.println("Failed to obtaining an IP address using DHCP");while(true); }if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

#include <Phpoc.h>PhpocClient client;int HTTP_PORT = 80;String HTTP_METHOD = "GET"; char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger/button-press/with/key/xxxxx";voidsetup() {Serial.begin(9600);Phpoc.begin();if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

#include <SPI.h>#include <Ethernet.h>byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };EthernetClient client;int HTTP_PORT = 80;String HTTP_METHOD = "GET";char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger";String queryString = "?value1=26&value2=70";;voidsetup() {Serial.begin(9600);if (Ethernet.begin(mac) == 0) {Serial.println("Failed to obtaining an IP address using DHCP");while(true); }if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + queryString + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

#include <Phpoc.h>PhpocClient client;int HTTP_PORT = 80;String HTTP_METHOD = "GET";char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger/button-press/with/key/xxxxx";String queryString = "?value1=26&value2=70";;voidsetup() {Serial.begin(9600);Phpoc.begin();if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + queryString + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

#include <SPI.h>#include <Ethernet.h>byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };EthernetClient client;int HTTP_PORT = 80;String HTTP_METHOD = "POST";char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger";String queryString = "?value1=26&value2=70";;voidsetup() {Serial.begin(9600);if (Ethernet.begin(mac) == 0) {Serial.println("Failed to obtaining an IP address using DHCP");while(true); }if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); client.println(queryString);while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

#include <Phpoc.h>PhpocClient client;int HTTP_PORT = 80;String HTTP_METHOD = "POST";char HOST_NAME[] = "maker.ifttt.com";String PATH_NAME = "/trigger/button-press/with/key/xxxxx";String queryString = "?value1=26&value2=70";;voidsetup() {Serial.begin(9600);Phpoc.begin();if(client.connect(HOST_NAME, HTTP_PORT)) {Serial.println("Connected to server"); client.println(HTTP_METHOD + " " + PATH_NAME + " HTTP/1.1"); client.println("Host: " + String(HOST_NAME)); client.println("Connection: close"); client.println(); client.println(queryString);while(client.connected()) {if(client.available()){char c = client.read();Serial.print(c); } } client.stop();Serial.println();Serial.println("disconnected"); } else {Serial.println("connection failed"); }}voidloop() {}

※ NOTE THAT:

This tutorial used the dynamic IP address (via DHCP). If you want to use the static IP address:

※ NOTE THAT:

Note that this tutorial is incomplete. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.

※ OUR MESSAGES

Follow Us

Share with your friends to help us spread the tutorial!

Sours: https://arduinogetstarted.com/tutorials/arduino-http-request

Get request arduino

In this tutorial, we will learn how to make HTTP GET requests in ESP32 to commonly used APIs such as ThingSpeak and OpenWeatherMap.org.

This tutorial is adaptable with any web service/API other than the ones which we will follow here. You just have to change the server’s name and parameters accordingly to the service API documentation.

ESP32 HTTP GET request with Arduino IDE (ThingSpeak and IFTTT.com)

In this tutorial, we will learn the followings:

HTTP GET Request

The Hypertext Transfer Protocol (HTTP) works as a request-response protocol between a server and a client. It enables smooth communication between them. The two most widely used HTTP methods are GET and POST. Through GET, data is requested from a specified resource whereas POST sends data to create a resource.

Recommended Reading:ESP32 HTTP POST using Arduino IDE (ThingSpeak and IFTTT)

In this user guide, we will focus on the GET request in HTTP. GET is commonly used to request data and retrieves it. We will use GET requests to obtain values (JSON object) from OpenWeatherMap.org. Moreover, we will also show you how to use GET requests to update values to ThingSpeak API. These requests are highly favorable to use when the data in question does not have any security concerns(passwords) or does not consist of images.

An example of an HTTP GET request is as follows:

GET/UpdatingSensorReadings?sensor_reading1=value1&sensor_reading2=value2

GET Requests Features

Data is visible in the browser URL and not sent in the message body

  • The length of the browser URL is limited to approximately 255 characters
  • Only the string data type is allowed
  • Data remains in the browser history hence it is not secure
  • Extremely easy to bookmark the data
  • Only used to retrieve data from the address bar
  • Data is easily stored and cacheable
  • Performance is significantly greater than POST due to the simplified nature of the request

HTTP GET Request Examples

We will learn how to request JSON data with HTTP GET request performs with ESP32 development board to OpenWeatherMap.org to access the weather parameters of our city. Additionally, we will also update readings by making an HTTP GET request performs with ESP32 to ThingSpeak

Working Process

  1. Firstly, the client (ESP32) will submit an HTTP request to the server (ThingSpeak/OpenWeatherMap.org).
  2. Secondly, the server will return a response to the client.
  3. Lastly, the response will be received which will contain the status information and the requested content of the request.
ESP32 HTTP  project overview

Prerequisites

We will program our ESP32 board in Arduino IDE. Thus, you should have the latest version of Arduino IDE. Additionally, you also need to install the ESP32 plugin. If your IDE does not have the plugins installed you can visit the link below:

• Installing ESP32 library in Arduino IDE and upload code.

Installing Arduino_JSON Library

You will also have to install the Arduino_JSON library as we will be dealing with JSON script. Open your Arduino Library Manager by clicking Sketch > Include Library > Manage Libraries. Type ‘Arduino_JSON’ in the search tab and press enter. Install the library which is highlighted below.

HTTP GET in Arduino_JSON library

ESP32 HTTP GET in OpenWeatherMap.org (Acquiring JSON Object)

First, we will look at how to use the OpenWeatherMap.org API to request data regarding the weather parameters of a city. OpenWeatherMap is an online webpage that gives the user information about the weather parameters for any set location. These include temperature, precipitation, humidity, pressure, wind and even forecasts to name a few. It has accurate and fast APIs which performs this functionality. In our project, we will be requesting the weather forecast for our set location through this API.

Our ESP32 (client) will make an HTTP GET request to the server which is OpenWeatherMap API in this case. As a response, we will receive a string consisting of the JSON object with details regarding the weather for our set location.

HTTP GET OpenWeatherMap working process

Setting up OpenWeatherMap API

Before we proceed further, first we have to set up an account in the OpenWeatherMap.

Go to the following webpage: https://openweathermap.org/appid/ to open the API. You will see the following window when the web page loads. Click ‘here’ as shown in the red box to sign up.

OpenWeatherMap signup page

You will be shown a page where you will have to add your username, password and some other details to create your account. Complete all the details, tick the relevant fields and then click on the ‘Create Account’ button.

OpenWeatherMap Create account

The webpage will send a confirmation link to the email address you provided. After confirmation, the following appears:

OpenWeatherMap get API key

Now, go to the ‘API keys’ tab and the following window will appear, carrying your unique API key. Likewise, you can go to https://home.openweathermap.org/api_keys to access your unique API key.

HTTP GET OpenWeatherMap API key

The key in the grey box is your unique key which we will be using later. Save this key and for security reasons do not share it with anyone.

Obtaining the Weather Update

Now as we have set up our account with OpenWeatherMap and have also obtained our key let see look into how to get weather update for a location of our choice. You will have to type the following URL in a new tab:

http://api.openweathermap.org/data/2.5/weather?q=city_code,
country_code&APPID=your_API_key

There are three parameters which we are specifying in the URL. First ‘q=city_code’ is the name of the city whose weather update you are acquiring. Second, ‘country_code’ specifies the two-digit country code of the city you specified before. Third, you will enter your unique API key which we just saved before.
Let us take a simple example. For example, if we want to know the weather update of the city Lahore in Pakistan, we will enter the following URL:

http://api.openweathermap.org/data/2.5/weather?q=Lahore,
PK&APPID=68de4b6c1e6fe13a39b55bf36b42****

Copy the following URL in a new window and the following parameters pop up. This is the current weather update of Lahore, Pakistan (same time report).

{“coord”:{“lon”:74.3436,”lat”:31.5497},”weather”:[{“id”:800,”main”:”Clear”,”description”:”clear sky”,”icon”:”01d”}],”base”:”stations”,”main”:{“temp”:307.14,”feels_like”:308.07,”temp_min”:306.21,”temp_max”:307.14,”pressure”:1003,”humidity”:38},”visibility”:6000,”wind”:{“speed”:6.17,”deg”:70},”clouds”:{“all”:5},”dt”:1622811705,”sys”:{“type”:1,”id”:7585,”country”:”PK”,”sunrise”:1622764679,”sunset”:1622815452},”timezone”:18000,”id”:1172451,”name”:”Lahore”,”cod”:200}

As you see above, the information is given in JSON script. Now we will decipher this data in an easily readable format through our Arduino Sketch.

Arduino Sketch

Open your Arduino IDE and go to File > New to open a new file. Copy the code given below in that file. For this code to work with your ESP32 board you will have to replace the following with your parameters in the program code:

  • Network credentials
  • API key
  • City and Country code
  • The server (domain name) for the URL path

How the Code Works?

Now, let us understand how each part of the code works.

Importing Libraries

Firstly, we will import the relevant libraries which are necessary for this project. We are using three libraries: WiFi.h, HTTPClient.h and Arduino_JSON.h
WiFi.h library is used to connect our ESP32 module with the local WIFI network. Also, the HTTPClient.h will help us to make the HTTP GET requests easily and the Arduino_JSON.h will be used for the JSON script.

Setting Network Credentials

Next, we will create two global variables to save the SSID and the password values. You have to replace both of them with your network credentials to successfully connect with your router.

Configuring your API key

Now, we will create a string variable to hold our unique API key. This is the key that we saved previously.

Setting City and Country Code

Next, we will create two string variables. The first variable will hold the name of the city whose weather update we want. The second variable will hold the two-digit country code for that particular city. In our case, we will access the current weather parameters for the city Lahore located in Pakistan (PK).

Setup() function

Inside the setup() function, we will open a serial connection at a baud rate of 115200.

Next, we will connect our ESP32 board with the local network whose network credentials we already specified above using the WiFi.begin() function. After the connection will be established, the IP address of the ESP32 board will get printed on the serial monitor.

loop() function

Inside the infinite loop() function we will make the HTTP POST request.
We will create another variable named ‘server’ which will hold the URL path of the HTTP GET request which we will use.

After every 10 seconds, the ESP32 module will make a request to the API by calling the GET_Request() function.

The following section of code defines the Get_Request() function. This function takes in the server URL as the parameter. We then create an instance of HTTPClient library called ‘http’ and request the API for a weather update. This information (‘payload’) is saved in string data type with a JSON object. The JSON object contains the complete information regarding the weather parameters for your set location.

The following section of code will help us to transform the JSON script into a readable format and displays it on our serial monitor. This data will get stored in the string variable ‘json_array’. We will then create an object ‘my_obj’ of JSONVAR and use it to access individual temperature, pressure, humidity and wind speed.

Demonstration

After you have uploaded your code to the ESP32 development board press its ENABLE button.

ESP32 enable reset button

In your Arduino IDE, open up the serial monitor and you will be able to see the IP address of your ESP module. Additionally, the time delay message will also be displayed.
Now, if a successful client-server communication took place, then the server would send the response code 200. This code corresponds to ‘OK’ which means successful. This will get printed on your Serial Monitor.
Then you will receive the weather update for your city in the form of JSON data as shown below:

HTTP GET OpenWeatherMap Serial Monitor demo1

This data also gets decoded into individual temperature, pressure, humidity and wind speed values as seen in the red rectangle. After every 10 seconds, you will receive a new set of readings for all the parameters.

HTTP GET OpenWeatherMap Serial Monitor demo2

ESP32 HTTP GET in ThingSpeak (Updating Values)

Now, we will look at how to make a request through our ESP32 board to ThingSpeak to update some random values. ThingSpeak is an open-source API that is used to store or retrieve data using HTTP or MQTT protocol. This takes place over the Internet or through the LAN. We will use this API to publish random values for simplicity purposes. For practicality, the same procedure can be used to publish sensor values e.g., data readings from the BME280 temperature sensor integrated with the ESP32 board.

Our ESP32 (client) will make an HTTP GET request to send different random values to the server which is ThingSpeak in this case. We will be able to view the different values in the ThingSpeak dashboard in the form of a graph that will keep updating.

HTTP GET ThingSpeak working process

Using ThingSpeak API

ThingSpeak API is free to use but we will have to create a MathWorks Account.

First go to the following website: https://thingspeak.com/
The following window will appear. Click on the ‘Get Started for Free’ button.

ESP32 HTTP  ThingSpeak get started

Now you will be redirected to the account window. If you already have an existing MathWorks account you can use that to log in. Otherwise, you will have to create a new one. Click ‘Create One!’ to make a new MathWorks account. When you have successfully signed in you will receive the following notification:

ESP32 HTTP ThingSpeak account

Click ‘OK’.

ESP32 HTTP ThingSpeak account successful

Now go to ‘New Channel’.

ESP32 HTTP ThingSpeak new channel

After creating your channel go to the API key tab and click it. You will now be able to access your unique API key. Save it and keep it secure as you will need it later in the program code.

HTTP GET ThingSpeak API key

ThingSpeak Arduino Sketch

Open your Arduino IDE and go to File > New to open a new file. Copy the code given below in that file. This code will work with your ESP32 board. You just have to replace the network credentials and your API key.

How the Code Works?

Now, let us understand how each part of the code works.

Importing Libraries

Firstly, we will import the relevant libraries which are necessary for this project. We are using two libraries: WiFi.h and HTTPClient.h
WiFi.h library is used to connect our ESP32 module with the local WIFI network. Also, the HTTPClient.h will help us to make the HTTP GET requests easily.

Setting Network Credentials

Next, we will create two global variables to save the SSID and the password values. You have to replace both of them with your network credentials to successfully connect with your router.

Setting server

After importing all the necessary libraries and configuring your network credentials you will have to give your server’s name. We will create a string variable and call it ‘server’. We will include the API key that we saved before in our server as shown below.

Make sure to replace your API key in the place specified. For example, our key is S7JL1OFE7U******

Hence, we will specify the server as:

Setup() function

Inside the setup() function, we will open a serial connection at a baud rate of 115200.

Moreover, we will connect our ESP32 board with the local network whose network credentials we already specified above using the WiFi.begin() function. After the connection will be established, the IP address of the ESP32 board will get printed on the serial monitor.

We will use the randomSeed() function to initiate a random number from a given starting point which is known as the seed. This will be set to analogRead(23) which we are using as an argument inside the function. The GPIO23 is unconnected thus through analogRead(23) it will read the value of the unconnected analog input and then use it as a starting point.

loop() function

Inside the infinite loop() function we will make the HTTP GET request. After every 10 seconds, a random number will be sent from the client to the server (ESP32 to ThingSpeak) through the GET request. Inside the ‘server_path’ we will send our server which we configured above with an API key and a random number between 0-49. The server path will hold the domain name for the GET request.

As an example, we will show you how to make a GET request where we will be updating a value. The ESP32 will make an HTTP GET request in a URL shown below:

http://api.thingspeak.com/update?api_key=Your_API_Key&field1=12

In the above GET request, we are updating the field1 with a new value which is 12.

The following section of the code will print the response code and the random number in the serial monitor.

Demonstration

After you have uploaded your code to the ESP32 development board press its ENABLE button.

ESP32 enable reset button

In your Arduino IDE, open up the serial monitor and you will be able to see the IP address of your ESP module. Additionally, the time delay message will also be displayed. Now, if a successful client-server communication took place, then the server would send the response code 200. This code corresponds to ‘OK’ which means successful. This will get printed on your Serial Monitor. You can also view the random number being displayed after the response code.

HTTP GET ThingSpeak serial monitor demo

Next, open the ThingSpeak API and you will be able to see different random values updating after 10 seconds in your dashboard.

HTTP GET ThingSpeak dashboard demo

Conclusion

To conclude it all, we learnt how to make HTTP GET requests from our ESP32 module to ThingSpeak (updating values) and OpenWeatherMap.org (weather review).

Categories ESP32Sours: https://microcontrollerslab.com/http-get-esp32-arduino-openweathermap-thingspeak-examples/
Arduino + GSM (HTTP GET requests)

How to Send HTTP Post and Get Requests Using Arduino ENC28J60 Ethernet Shield

 

ENC28J60 Ethernet Shield for Arduino

In this IoT age, there are several ways of sending and getting data to/from a microcontroller to a remote server. This article will be the first part of a series about such ways through the Arduino ENC28J60 shield or module. Here I will be showing the classic way of communicating via the Internet: HTTP requests.

Introduction

An HTTP request is how most web browsers request a web page from a server. For example, when you visit this website, your browser will send this request:

GET / HTTP/1.1 Host: circuitxcode.com

The server handling this website hears the request and then returns a response and all the code for viewing the website on the browser (HTML, CSS, JS, etc.).

A microcontroller with Internet capabilities can also do such requests. In this tutorial, I will feature the Arduino ENC28J60 shield or module. However, the codes here might also be usable for other shields like W5100, etc. 

Sending a GET Request

A GET request gets data from a remote server. When done using a web browser, GET requests can be cached, bookmarked, or saved in the browser’s history. As such, GET requests are less secure compared to POST requests. 

Let’s say we have a fake website, example-server.com. This website’s homepage displays a simple Hello World!

example-server.com homepage

The code below uses GET to acquire the homepage above.

#include <UIPEthernet.h> EthernetClient client; uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; void setup() {   Serial.begin(9600);   char server[] = "www.example-server.com";   if(Ethernet.begin(mac) == 0){     Serial.println("Failed to configure Ethernet using DHCP");     while(1); //do nothing if ethernet failed to start   }   if (client.connect(server,80)){       Serial.println("Connected to server");       client.println("GET / HTTP/1.1");       client.println("Host: example-server.com");       client.println();   }else{       Serial.println("Connection to server failed");   } } void loop() {     while(client.connected()){     if(client.available()){       char c = client.read();       Serial.print(c);       }   } }

If you run this code on an Arduino, the serial monitor will show this:

GET request example - serial monitor output
This is an example of a response from a server. At the bottom is the HTML source of the page. Above it is HTTP headers and the status code.

Let’s just run through the code. The first lines contain this:

#include <UIPEthernet.h> EthernetClient client; uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};

Here the UIPEthernet library is included as the built-in Ethernet library doesn’t support the EN28J60 shield/module. 

We then initialize the EthernetClient object and then create a MAC address. The MAC address could be anything as long as it isn’t the same as any other devices on your LAN. Some ethernet shields have their MAC address printed on the board so you may use that.

Here’s the setup() function:

void setup() {   Serial.begin(9600);   char server[] = "www.example-server.com";   if(Ethernet.begin(mac) == 0){     Serial.println("Failed to configure Ethernet using DHCP");     while(1); //do nothing if ethernet failed to start   }   if (client.connect(server,80)){       Serial.println("Connected to server");       client.println("GET / HTTP/1.1");       client.println("Host: example-server.com");       client.println();   }else{       Serial.println("Connection to server failed");   } }

I created a server char array where the server name is assigned to. Then, we check if the ethernet device is able to initiate a connection through DHCP. If this initialization is unsuccessful, there’s no point in continuing so the program ends with an infinite loop.

If the DHCP initialization is successful, we connect to the server using 

client.connect(server,80)

This function returns true if successful and false if not. The second parameter in the function is the port number. Port 80 is the port for HTTP requests while 443 is for HTTPS. We will be using more port numbers as we go along with this series.

If we are able to connect to the server, we now send the request:

client.println("GET / HTTP/1.1"); client.println("Host: example-server.com"); client.println();

Note the extra client.println() is necessary.

The simplest GET request follows this format:

GET <page> HTTP/1.1 Host: <website URL>

In the Arduino sketch, we are requesting for the home page so there’s only a “/”. If we want to request another page, like contact.php for example, then this is the request:

GET /contact.php HTTP/1.1 Host: <website URL>

Browsers typically send more headers than what I used here.

The loop() function waits for any response from the server and prints it to the serial monitor.

void loop() {     while(client.connected()){     if(client.available()){       char c = client.read();       Serial.print(c);       }   } }

The GET request, again, is for receiving data from the server. If we want to send data, we use POST request.

Sending a POST Request

Unlike the GET request, a POST request will not be cached, bookmarked, or remain in the browser’s history. This makes POST requests more secure than GET requests. Moreover, you can use POST requests to send data to the server.

Here’s an Arduino sketch for sending a POST request:

#include <UIPEthernet.h> EthernetClient client; uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; void setup() {   Serial.begin(9600);   char server[] = "www.example-server.com";   String data = "sensor1=";   data += analogRead(A0);   data += "sensor2=";   data += analogRead(A1);   if(Ethernet.begin(mac) == 0){     Serial.println("Failed to configure Ethernet using DHCP");     while(1);   }   if (client.connect(server,80)){       Serial.println("Connected to server");       client.println("POST / HTTP/1.1");       client.println("Host: example-server.com");       client.println("Content-Type: application/x-www-form-urlencoded");       client.print("Content-Length: ");       client.println(data.length());       client.println();       client.println(data);       client.println();   }else{       Serial.println("Connection to server failed");   } } void loop() {     while(client.connected()){     if(client.available()){       char c = client.read();       Serial.print(c);       }   } }

The first difference in this sketch from the first one is we need to define the data we will be sending:

String data = "sensor1="; data += analogRead(A0); data += "&sensor2="; data += analogRead(A1);

Here, I created a string and embedded the readings from analog ports A0 and A1. This is assuming I have some sensor connected in these ports. The data string would look like this:

sensor1=100&sensor2=200

The second difference is this part:

if(client.connect(server,80)){       Serial.println("Connected to server");       client.println("POST / HTTP/1.1");       client.println("Host: example-server.com");       client.println("Content-Type: application/x-www-form-urlencoded");       client.print("Content-Length: ");       client.println(data.length());       client.println();       client.println(data);       client.println(); }

Besides changing GET to POST, notice that I added these:

client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(data.length()); client.println(); client.println(data); client.println();

The first line tells the server what type of data we are sending. The next lines tell the length of the data to be sent (which is the data string). Then the last part of the request is the data string itself.

The format for a simple POST request is like this:

POST <page> HTTP/1.1 Host: <website URL> Content-Type: <content-type> Content-Length: <length of data> <data>

When you upload the sketch, expect the same reply as the previous sketch. 

Typically, POST requests will not provide the HTML code of the page unless the page you are requesting is explicitly sending the HTML code. 

So what happens to the data we just sent? If the page to where it was sent is using PHP, two variables will now have been created: $_POST[‘sensor1’] and $_POST[‘sensor2’]. Now it is up to the web developer what he will do with the contents of these variables.

Example With PHP Code

For example, we have a page that captures our POST data and stores it inside a text file. When a browser user visits the same page, the data is displayed. That sensor.php page will have a code like this:

<html><body><?php            $filename ="post-data.txt";if($_SERVER['REQUEST_METHOD']==='POST'){$s1 ='Sensor 1: '.$_POST['sensor1']."\r\n";                $s2 ='Sensor 2: '.$_POST['sensor2']."\r\n";                $handle = fopen($filename,"w")ordie("Unable to open file!");                fwrite($handle, $s1);                fwrite($handle, $s2);                fclose($handle);}elseif($_SERVER['REQUEST_METHOD']==='GET'){                $handle = fopen($filename,"r");                $contents = fread($handle, filesize($filename));                echo $contents;                fclose($handle);}else{;}?></body></html>

Here, we separate the POST requesters from the GET requesters. The latter sends data while the former reads the data. If a POST request is sent, this part of the code runs:

if($_SERVER['REQUEST_METHOD']==='POST'){$s1 ='Sensor1: '.$_POST['sensor1']."\r\n";   $s2 ='Sensor2: '.$_POST['sensor2']."\r\n";   $handle = fopen($filename,"w")ordie("Unable to open file!");   fwrite($handle, $s1);   fwrite($handle, $s2);   fclose($handle);}

Data sent via POST are stored in $_POST[name] variables. Here the POST data have names sensor1 and sensor2 which are defined in the Arduino sketch. Both values are put into a string and then written to a text file.

If a user uses a browser to visit the same page, he initiates a GET request. Hence, this part of the PHP code executes:

elseif($_SERVER['REQUEST_METHOD']==='GET'){   $handle = fopen($filename,"r");   $contents = fread($handle, filesize($filename));   echo $contents;   fclose($handle);}

The full Arduino sketch is below:

#include <UIPEthernet.h> EthernetClient client; uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05}; void setup() {   Serial.begin(9600);   char server[] = "www.example-server.com";   String data = "sensor1=";   data += analogRead(A0);   data += "sensor2=";   data += analogRead(A1);   if(Ethernet.begin(mac) == 0){     Serial.println("Failed to configure Ethernet using DHCP");     while(1);   }  if (client.connect(server,80)){       Serial.println("Connected to server");       client.println("POST /sensor.php HTTP/1.1");       client.println("Host: example-server.com");       client.println("Content-Type: application/x-www-form-urlencoded");       client.print("Content-Length: ");       client.println(data.length());       client.println();       client.println(data);       client.println();   }else{       Serial.println("Connection to server failed");   } } void loop() {     while(client.connected()){     if(client.available()){       char c = client.read();       Serial.print(c);       }   } }

Now when I upload the sketch, and the data is successfully sent to the remote server, the sensor.php page will display the sensor values on a web browser.

POST request - browser output

That’s it! For the next part of this series, I will show you another way of sending and receiving data from a remote server still using the ENC28J60 ethernet shield.

Sours: https://www.circuitxcode.com/send-http-post-get-requests-using-arduino-enc28j60-ethernet-shield/

Now discussing:

What is ?

is a class that performs HTTP requests on ESP8266 and ESP32.

Assuming that the board is connected to the WiFi network, you can send an HTTP request like so:

While you can perform HTTP request without (cf “See also” below), this class greatly simplifies your code.

On ESP8266, this class is provided by the ESP8266HTTPClient library, which is bundled with the ESP8266 core for Arduino.

On ESP32, it’s provided by the HTTPClient library, which is bundled with the Arduino core for the ESP32.

How to parse a JSON document from an HTTP response?

Unfortunately, doesn’t implement the interface, so you cannot pass it directly to like so:

We could pass the result of directly to , but it would be quite inefficient because it would copy the complete response in RAM before parsing.

We can do much better by letting ArduinoJson pull the bytes from the HTTP response. To do that, we must get ’s underlying by calling instead of .

Unfortunately, by using the underlying , we bypass the code that handles chunked transfer encoding, so we must switch to HTTP version 1.0.

Remember to call when you use , or will return .

Notice that I used a here because the document is quite large. Feel free to use a if your document is smaller. As always, use the ArduinoJson Assistant to compute the right capacity for your project.

How to send a JSON document in an HTTP request?

Unfortunately, there is no way to use the same trick as above, so we have to use a temporary buffer. Here is how we can do so with a :

If you run this program, you’ll see that it prints information on the HTTP requests. That’s the response returned by httpbin.org; it’s very handy to debug your programs.

You can significantly improve this code’s performance by calling before .
Here are some other tips for using the class efficiently.

Why is the empty? 🆕

The most likely explanation is that the server returned a redirection code, like 301 Moved Permanently or 302 Found.

This feature was added quite recently on ESP32, so make sure you are up-to-date.

BONUS: How to see the document when I use a ?

As we saw, it’s more efficient to pass the to because it saves a large amount of memory. However, we cannot directly print the content of the to see what was sent to ArduinoJson.

To see the content that is received from the HTTP response, we can use the from the StreamUtils library.

Replace:

with:

will forward everything to and will print the content to the serial port.

StreamUtils is a powerful library that deserves more attention. Please give it a star to spread the word.

See also

Sours: https://arduinojson.org/v6/how-to/use-arduinojson-with-httpclient/


1040 1041 1042 1043 1044