#include <ThingSpeak.h>
#include "WiFi.h"
WiFiClient client;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define LED_Pin 12
unsigned long Channel_ID= 2352111;
const char* API_Key = "AKWNIUJ8CSNCVYGH";
const int Field_num = 3;
void setup()
{
Serial.begin(9600);
WiFi.disconnect();
WiFi.begin(ssid,pass);
while ((!(WiFi.status() == WL_CONNECTED))) {
delay(300);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
pinMode(LED_Pin, OUTPUT);
ThingSpeak.begin(client);
}
void loop()
{
int A = ThingSpeak.readLongField(Channel_ID, Field_num, API_Key);
Serial.println(A);
digitalWrite(LED_Pin, A);
// ON https://api.thingspeak.com/update?key=KD1ECLHY4X123MMI&field3=1
// OFF https://api.thingspeak.com/update?key=KD1ECLHY4X123MMI&field3=0
}