WeMOS: WiFi Thingspeak analogRead2

From OnnoWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
/////////////////////////////////
// Generated with a lot of love//
// with TUNIOT FOR ESP8266     //
// Website: Easycoding.tn      //
/////////////////////////////////
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

WiFiClient client;

String thingSpeakAddress= "http://api.thingspeak.com/update?";
String request_string;

HTTPClient http;

void setup()
{
  Serial.begin(115200);
  if (WiFi.status() != WL_CONNECTED) {
     WiFi.begin("HUAWEI-1A73","52408495");
  }
  Serial.println("WiFi Connected");  
}

void loop()
{
  Serial.println(analogRead(A0));
  if (client.connect("api.thingspeak.com",80)) {
    request_string = thingSpeakAddress;
    request_string += "key=";
    request_string += "0C2X0PGNFHOEGYZA";
    request_string += "&";
    request_string += "field3";
    request_string += "=";
    request_string += String(analogRead(A0));
    http.begin(request_string);
    http.GET();
    http.end();
  }
  Serial.println("Waiting...");    
  // thingspeak needs minimum 15 sec delay between updates
  delay(15000);
}


Pranala Menarik