Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple HTTP get webclient test
- */
- #include <ESP8266WiFi.h>
- const char* ssid = "lehigh-guest";
- const char* password = "";
- const char* host = "api.thingspeak.com";
- String field1;
- void setup() {
- Serial.begin(115200);
- delay(100);
- // We start by connecting to a WiFi network
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- }
- }
- int value = 0;
- void loop() {
- delay(5000);
- ++value;
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
- const int httpPort = 80;
- if (!client.connect(host, httpPort)) {
- return;
- }
- // We now create a URI for the request
- String url = "/channels/103752/feeds/last";
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(500);
- // Read all the lines of the reply from server and print them to Serial
- while(client.available()){
- String line = client.readStringUntil('\r');
- Serial.print(line);
- }
- Serial.println();
- }
Add Comment
Please, Sign In to add comment