#include <WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
const char* ssid = "Wokwi-GUEST"; // simulated network SSID for Wokwi
const char* password = ""; // no password needed for the Wokwi simulated network
unsigned long channelID = 2592583;
const char* writeAPIKey = "mwa0000034384896";
const int ledPin = 2; // GPIO2 is usually the built-in LED on ESP32
WiFiClient client;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected");
ThingSpeak.begin(client);
pinMode(ledPin, OUTPUT);
}
void loop() {
int status = ThingSpeak.writeField(channelID, 1, random(0, 100), writeAPIKey);
if (status == 200) {
Serial.println("Channel update successful");
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
} else {
Serial.print("Problem updating channel. HTTP error code: ");
Serial.println(status);
}
delay(20000); // Wait 20 seconds before sending the next update
}