CODE NEW

 


#include <ESP8266WiFi.h>
#include  <WiFiClient.h>
#include  <ThingSpeak.h>

const char* ssid = "LTCE";
const char* password = "690391";
const char* host = "file:///C:/Users/Harsh%20Vatre/Desktop/Untitled-1.html
";
const String apiKey = "QLTJTC9CSVSALKJY";

WiFiClient client;

void setup() {
  Serial.begin(115200);
  delay(10);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  if (client.connect(host, 80)) {
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(random(100));
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);

    Serial.println("Posted data to ThingSpeak");
  }

  client.stop();
  delay(20000); // Wait 20 seconds to update again
}

Comments

Popular posts from this blog

arduino to esp

HEART BEAT NOT WORKING (1-201)