Experiment 10
Experiment 10
1. ESP8266
2. Connecting Cables
3. DC 5V, 1A Power Adaptor
THEORY:
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 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
HARDWARE CONNECTION:
OpenWeather platform is a set of elegant and widely recognisable APIs. Powered by
convolutional machine learning solutions, it is capable of delivering all the weather information
necessary for decision-making for any location on the globe to start using our APIs, please sign
up here https://home.openweathermap.org/users/sign_in
CODE/PROGRAM:-
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <Arduino_JSON.h>
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());
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);
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;
}
PRECAUTIONS
1. Use insulation tools while you connect the Circuit.
2. Wear Good Insulating Shoes.
3. Avoid contacting circuits with wet hands or wet materials.
4. Maintain a work space clear of extraneous material such as books, papers, and clothes.
5. Be careful while connecting any actuators in 230V AC Mains.
Results
The NodeMCU was programmed using the Arduino IDE to establish communication with
weather APIs through HTTP GET requests. The station effectively retrieved weather data such
as temperature, humidity, and atmospheric pressure from external sources.
OUTPUT :