User Tools

Site Tools


espwebclient_webclient_httpclient

This is an old revision of the document!


Synchronous Mode:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
String serverName = "http://192.168.1.106/update-sensor";

void setup(){
   // ** wifi connection here ** //
   if(WiFi.status()== WL_CONNECTED){
      WiFiClient client;
      HTTPClient http;
      
      String serverPath = serverName + "?temperature=24.37";
      http.begin(client, serverPath.c_str());
      
      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();
   }
}   
espwebclient_webclient_httpclient.1719129013.txt.gz · Last modified: (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki