Guest User

esp8266

a guest
Apr 11th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. /*
  2. * Simple HTTP get webclient test
  3. */
  4.  
  5. #include <ESP8266WiFi.h>
  6.  
  7. const char* ssid = "lehigh-guest";
  8. const char* password = "";
  9.  
  10. const char* host = "api.thingspeak.com";
  11. String field1;
  12. void setup() {
  13. Serial.begin(115200);
  14. delay(100);
  15.  
  16. // We start by connecting to a WiFi network
  17.  
  18.  
  19.  
  20. WiFi.begin(ssid, password);
  21.  
  22. while (WiFi.status() != WL_CONNECTED) {
  23. delay(500);
  24. }
  25. }
  26.  
  27. int value = 0;
  28.  
  29. void loop() {
  30. delay(5000);
  31. ++value;
  32.  
  33.  
  34. // Use WiFiClient class to create TCP connections
  35. WiFiClient client;
  36. const int httpPort = 80;
  37. if (!client.connect(host, httpPort)) {
  38. return;
  39. }
  40.  
  41. // We now create a URI for the request
  42. String url = "/channels/103752/feeds/last";
  43.  
  44.  
  45. // This will send the request to the server
  46. client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  47. "Host: " + host + "\r\n" +
  48. "Connection: close\r\n\r\n");
  49. delay(500);
  50.  
  51. // Read all the lines of the reply from server and print them to Serial
  52. while(client.available()){
  53. String line = client.readStringUntil('\r');
  54. Serial.print(line);
  55. }
  56.  
  57.  
  58. Serial.println();
  59.  
  60. }
Add Comment
Please, Sign In to add comment