#include <WiFi.h>
#include<ThingSpeak.h>
#include<PubSubClient.h>
const char* ssid = "Wokwi-GUEST";//Replace with your Wifi Name
const char* password = "";// Replace with your wifi Password
const long channel =2425259;//Replace with your own ThingSpeak Account Channle ID
const char *WRITE_API="X42II4GPF3TB15UN";
WiFiClient client;
int interval = 15*1000;
long now=0;
void connect_wifi()
{
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid,password);
while (WiFi.status()!=WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.print("Connection Successful");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void setup()
{
Serial.begin(115200);
connect_wifi();
ThingSpeak.begin(client);
}
void loop()
{
int h=0;
if (millis() - now >interval)
{
h=hallRead();
ThingSpeak.setField(1,h);
int status1 = ThingSpeak.writeFields(channel,WRITE_API);
if (status1 == 200)
{
Serial.println("Updated Values Successfully");
}
else
{
Serial.println("Error Occured. HTTP error code"+status1);
}
now=millis();
}
}