Guest User

ESP_Client

a guest
Oct 3rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266HTTPClient.h>
  3.  
  4. const char *ssid = "DataJugling";
  5. const char *password = "jugle123";
  6. const char *url = "http://dataserver.local/";
  7.  
  8. void setup() {
  9.   Serial.begin(115200);
  10.  
  11.   pinMode(LED_BUILTIN, OUTPUT);
  12.   digitalWrite(LED_BUILTIN, LOW);
  13.  
  14.   WiFi.mode(WIFI_STA);
  15.   WiFi.begin(ssid, password);
  16.   while (WiFi.status() != WL_CONNECTED) delay(500);
  17.   digitalWrite(LED_BUILTIN, HIGH);
  18. }
  19.  
  20. void loop() {
  21.   HTTPClient http;
  22.  
  23.   http.begin(url);
  24.   int httpCode = http.GET();
  25.  
  26.   if (httpCode > 0) {
  27.     String data = http.getString();
  28.     Serial.println(data);
  29.   } else {
  30.     Serial.printf("[HTTP] Error: %s\n", http.errorToString(httpCode).c_str());
  31.   }
  32.   http.end();
  33.  
  34.   delay(1000);
  35. }
Add Comment
Please, Sign In to add comment