http and get in esp8266

Solutions on MaxInterview for http and get in esp8266 by the best coders in the world

showing results for - "http and get in esp8266"
Sofia
13 Aug 2020
1#include <ESP8266HTTPClient.h>
2#include <ESP8266WiFi.h>
3 
4void setup() {
5 
6  Serial.begin(115200);                 //Serial connection
7  WiFi.begin("yourSSID", "yourPASS");   //WiFi connection
8 
9  while (WiFi.status() != WL_CONNECTED) {  //Wait for the WiFI connection completion
10 
11    delay(500);
12    Serial.println("Waiting for connection");
13 
14  }
15 
16}
17 
18void loop() {
19 
20  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
21 
22    HTTPClient http;    //Declare object of class HTTPClient
23 
24    http.begin("http://192.168.1.88:8085/hello");      //Specify request destination
25    http.addHeader("Content-Type", "text/plain");  //Specify content-type header
26 
27    int httpCode = http.POST("Message from ESP8266");   //Send the request
28    String payload = http.getString();                  //Get the response payload
29 
30    Serial.println(httpCode);   //Print HTTP return code
31    Serial.println(payload);    //Print request response payload
32 
33    http.end();  //Close connection
34 
35  } else {
36 
37    Serial.println("Error in WiFi connection");
38 
39  }
40 
41  delay(30000);  //Send a request every 30 seconds
42 
43}
44