In this guide, you’ll learn how to make HTTP GET requests using the ESP32 board with Arduino IDE. We’ll demonstrate how to decode JSON data from OpenWeatherMap.org and plot values in charts using ThingSpeak.

Recommended: ESP32 HTTP POST with Arduino IDE (ThingSpeak and IFTTT.com)
The Hypertext Transfer Protocol (HTTP) works as a request-response protocol between a client and server. Here’s an example:
GET is used to request data from a specified resource. It is often used to get values from APIs.
For example, you can use a simple request to return a value or JSON object:
GET /weather?countryCode=PT
Additionally, you can also make a GET request to update a value (like with ThingSpeak). For example, you can use:
GET /update?field1=value1
Note that the query string (name = field1 and value = value1) is sent in the URL of the HTTP GET request.
(With HTTP GET, data is visible to everyone in the URL request.)
Before proceeding with this tutorial, make sure you complete the following prerequisites.
We’ll program the ESP32 using Arduino IDE, so make sure you have the ESP32 add-on installed.
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:

In this guide, you’ll learn how to setup your ESP32 board to perform HTTP requests to OpenWeatherMap.org and ThingSpeak. If you prefer to learn with a local solution you can use HTTP with Node-RED. All examples presented in this guide 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.
In this example you’ll learn how to make API requests to access data. As an example, we’ll use the OpenWeatherMap API. This API has a free plan and provides lots of useful information about the weather in almost any location in the world.

An application programming interface (API) is a set of functions written by software developers to enable anyone to use their data or services. The OpenWeatherMap project has an API that enables users to request weather data.

In this project, you’ll use that API to request the day’s weather forecast for your chosen location. Learning to use APIs is a great skill because it allows you access to a wide variety of constantly changing information, such as current stock prices, currency exchange rates, the latest news, traffic updates, tweets, and much more.
Note: API keys are unique to the user and shouldn’t be shared with anyone.
OpenWeatherMap’s free plan provides everything you need to complete this project. To use the API you need an API key, known as the APIID. To get the APIID:

http://api.openweathermap.org/data/2.5/weather?q=yourCityName,yourCountryCode&APPID=yourUniqueAPIkey
Replace yourCityName with the city you want data for, yourCountryCode with the country code for that city, and yourUniqueAPIkey with the unique API key from step 4. For example, the updated API URL for the city of Porto, Portugal, would be:
http://api.openweathermap.org/data/2.5/weather?q=Porto, PT&APPID=801d2603e9f2e1c70e042e4f5f6e0---
{"coord":{"lon":-8.611,"lat":41.1496},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"stations","main":{"temp":294.58,"feels_like":294.95,"temp_min":293.82,"temp_max":295.65,"pressure":1016,"humidity":83},"visibility":10000,"wind":{"speed":8.94,"deg":180,"gust":8.94},"clouds":{"all":75},"dt":1666877635,"sys":{"type":2,"id":2009460,"country":"PT","sunrise":1666853957,"sunset":1666892227},"timezone":3600,"id":2735943,"name":"Porto","cod":200}This is how it looks with indentation for better readability.
{ "coord": { "lon": -8.611, "lat": 41.1496 }, "weather": [ { "id": 803, "main": "Clouds", "description": "broken clouds", "icon": "04d" } ], "base": "stations", "main": { "temp": 294.58, "feels_like": 294.95, "temp_min": 293.82, "temp_max": 295.65, "pressure": 1016, "humidity": 83 }, "visibility": 10000, "wind": { "speed": 8.94, "deg": 180, "gust": 8.94 }, "clouds": { "all": 75 }, "dt": 1666877635, "sys": { "type": 2, "id": 2009460, "country": "PT", "sunrise": 1666853957, "sunset": 1666892227 }, "timezone": 3600, "id": 2735943, "name": "Porto", "cod": 200 }
Next, you’ll see how to use this information to get specific data like temperature, humidity, pressure, wind speed, etc.
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.
/* Rui Santos Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-open-weather-map-thingspeak-arduino/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #include <WiFi.h> #include <HTTPClient.h> #include <Arduino_JSON.h> const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Your Domain name with URL path or IP address with path String openWeatherMapApiKey = "REPLACE_WITH_YOUR_OPEN_WEATHER_MAP_API_KEY"; // Example: //String openWeatherMapApiKey = "bd939aa3d23ff33d3c8f5dd1dd435"; // Replace with your country code and city String city = "Porto"; String countryCode = "PT"; // THE DEFAULT TIMER IS SET TO 10 SECONDS FOR TESTING PURPOSES // For a final application, check the API call limits per hour/minute to avoid getting blocked/banned unsigned long lastTime = 0; // Timer set to 10 minutes (600000) //unsigned long timerDelay = 600000; // Set timer to 10 seconds (10000) unsigned long timerDelay = 10000; String jsonBuffer; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.println("Connecting"); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading."); } void loop() { // Send an HTTP GET request if ((millis() - lastTime) > timerDelay) { // Check WiFi connection status if(WiFi.status()== WL_CONNECTED){ String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&APPID=" + openWeatherMapApiKey; jsonBuffer = httpGETRequest(serverPath.c_str()); Serial.println(jsonBuffer); JSONVar myObject = JSON.parse(jsonBuffer); // JSON.typeof(jsonVar) can be used to get the type of the var if (JSON.typeof(myObject) == "undefined") { Serial.println("Parsing input failed!"); return; } Serial.print("JSON object = "); Serial.println(myObject); Serial.print("Temperature: "); Serial.println(myObject["main"]["temp"]); Serial.print("Pressure: "); Serial.println(myObject["main"]["pressure"]); Serial.print("Humidity: "); Serial.println(myObject["main"]["humidity"]); Serial.print("Wind Speed: "); Serial.println(myObject["wind"]["speed"]); } else { Serial.println("WiFi Disconnected"); } lastTime = millis(); } } String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; // Your Domain name with URL path or IP address with path http.begin(client, serverName); // Send HTTP POST request int httpResponseCode = http.GET(); String payload = "{}"; if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); return payload; }
Modify the next lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.
// Replace with your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD";
Insert your API key in the following like:
String openWeatherMapApiKey = "REPLACE_WITH_YOUR_OPEN_WEATHER_MAP_API_KEY";
Enter the city you want to get data for, as well as the country code in the following variables:
// Replace with your country code and city String city = "Porto"; String countryCode = "PT";
After making these changes, you can upload the code to your board. Continue reading to learn how the code works.
In the loop(), call the httpGETRequest() function to make the HTTP GET request:
String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&APPID=" + openWeatherMapApiKey; jsonBuffer = httpGETRequest(serverPath.c_str());
The httpGETRequest() function makes a request to OpenWeatherMap and it retrieves a string with a JSON object that contains all the information about the weather for your city.
String httpGETRequest(const char* serverName) { HTTPClient http; // Your IP address with path or Domain name with URL path http.begin(serverName); // Send HTTP POST request int httpResponseCode = http.GET(); String payload = "{}"; if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); return payload; }
To get access to the values, decode the JSON object and store all values in the jsonBuffer array.
JSONVar myObject = JSON.parse(jsonBuffer); // JSON.typeof(jsonVar) can be used to get the type of the var if (JSON.typeof(myObject) == "undefined") { Serial.println("Parsing input failed!"); return; } Serial.print("JSON object = "); Serial.println(myObject); Serial.print("Temperature: "); Serial.println(myObject["main"]["temp"]); Serial.print("Pressure: "); Serial.println(myObject["main"]["pressure"]); Serial.print("Humidity: "); Serial.println(myObject["main"]["humidity"]); Serial.print("Wind Speed: "); Serial.println(myObject["wind"]["speed"]);
After uploading the code, open the Serial Monitor and you’ll see that it’s receiving the following JSON data:
{"coord":{"lon":-8.61,"lat":41.15},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":294.44,"feels_like":292.82,"temp_min":292.15,"temp_max":297.04,"pressure":1008,"humidity":63},"visibility":10000,"wind":{"speed":4.1,"deg":240},"clouds":{"all":20},"dt":1589288330,"sys":{"type":1,"id":6900,"country":"PT","sunrise":1589260737,"sunset":1589312564},"timezone":3600,"id":2735943,"name":"Porto","cod":200}Then, it prints the decoded JSON object in the Arduino IDE Serial Monitor to get the temperature (in Kelvin), pressure, humidity and wind speed values.

For demonstration purposes, we’re requesting new data every 10 seconds. However, for a long term project you should increase the timer or check the API call limits per hour/minute to avoid getting blocked/banned.
In this example, the ESP32 makes an HTTP GET request to update a reading in ThingSpeak.

ThingSpeak has a free API that allows you to store and retrieve data using HTTP. In this tutorial, you’ll use the ThingSpeak API to publish and visualize data in charts from anywhere. As an example, we’ll publish random values, but in a real application you would use real sensor readings.
To use ThingSpeak with your ESP, you need an API key. Follow the next steps:


Copy the next sketch to your Arduino IDE (type your SSID, password, and API Key):
/* Rui Santos Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-open-weather-map-thingspeak-arduino/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #include <WiFi.h> #include <HTTPClient.h> const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // REPLACE WITH THINGSPEAK.COM API KEY String serverName = "http://api.thingspeak.com/update?api_key=REPLACE_WITH_YOUR_API_KEY"; // EXAMPLE: //String serverName = "http://api.thingspeak.com/update?api_key=7HQJM49R8JAPR"; // THE DEFAULT TIMER IS SET TO 10 SECONDS FOR TESTING PURPOSES // For a final application, check the API call limits per hour/minute to avoid getting blocked/banned unsigned long lastTime = 0; // Timer set to 10 minutes (600000) //unsigned long timerDelay = 600000; // Set timer to 10 seconds (10000) unsigned long timerDelay = 10000; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.println("Connecting"); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading."); // Random seed is a number used to initialize a pseudorandom number generator randomSeed(analogRead(33)); } void loop() { // Send an HTTP GET request if ((millis() - lastTime) > timerDelay) { // Check WiFi connection status if(WiFi.status()== WL_CONNECTED){ WiFiClient client; HTTPClient http; String serverPath = serverName + "&field1=" + String(random(40)); // Your Domain name with URL path or IP address with path http.begin(client, serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET(); if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } // Free resources http.end(); } else { Serial.println("WiFi Disconnected"); } lastTime = millis(); } }
Modify the next lines with your network credentials: SSID and password. The code is well commented on where you should make the changes.
// Replace with your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD";
Modify the serverName variable to include your API key.
String serverName = "http://api.thingspeak.com/update?api_key=REPLACE_WITH_YOUR_API_KEY";
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.
In the loop() is where you make the HTTP GET request every 10 seconds with random values:
String serverPath = serverName + "&field1=" + String(random(40)); // Your Domain name with URL path or IP address with path http.begin(serverPath.c_str()); // Send HTTP GET request int httpResponseCode = http.GET();
The ESP32 makes a new request in the following URL to update the sensor field1 with a new value (30).
http://api.thingspeak.com/update?api_key=REPLACE_WITH_YOUR_API_KEY&field1=30
Then, the following lines of code save the HTTP response from the server.
if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); String payload = http.getString(); Serial.println(payload); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); }
In the Arduino IDE serial monitor, you should see an HTTP response code of 200 (this means that the request has succeeded).

Your ThingSpeak Dashboard (under the Private View tab) should be receiving new readings every 10 seconds.

For a final application, you might need to increase the timer or check the API call limits per hour/minute to avoid getting blocked/banned.
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION