Guest User

Untitled

a guest
Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2.  
  3. const char* ssid = "***********";
  4. const char* password = "*********";
  5.  
  6. const char* host = "iot.com";
  7. String led = "/test.txt";
  8.  
  9. String Tempdata = "";
  10.  
  11. void setup() {
  12. delay(100);
  13. Serial.begin(9600);
  14. delay(10);
  15. WiFi.begin(ssid, password);
  16. int wifi_ctr = 0;
  17. while (WiFi.status() != WL_CONNECTED) {
  18. delay(500);
  19. }
  20. }
  21.  
  22. void loop() {
  23. String data;
  24. WiFiClient client;
  25. const int httpPort = 80;
  26. if (!client.connect(host, httpPort)) {
  27. return;
  28. }
  29.  
  30. client.print(String("GET /") + led + " HTTP/1.1rn" +
  31. "Host: " + host + "rn" +
  32. "Connection: closernrn");
  33.  
  34. delay(500);
  35.  
  36. // int dir = 0;
  37.  
  38. // char section[] = "header";
  39. while (client.available()) {
  40. data = "";
  41. data = client.readStringUntil('r');
  42. }
  43. data.remove(0, 1);
  44. if (Tempdata != data)
  45. {
  46. Tempdata = data;
  47. Serial.print(data);
  48. }
  49. }
Add Comment
Please, Sign In to add comment