#include <WiFi.h>
#include <ThingSpeak.h>
#include <WiFiClient.h>
#include <Servo.h>
const char *ssid = "Wokwi-GUEST";
const char *password = "";
WiFiClient client;
unsigned long myChannelNumber = 2805605; // Replace with your channel number
const char * myWriteAPIKey = "9K67ZCTFLIQMPAED"; // Replace with your API key
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi!");
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
// Prepare data to send
int parkingStatus = 1; // For example, 1 indicates space is available
ThingSpeak.setField(1, parkingStatus); // Send data to Field 1 of your channel
// Write data to ThingSpeak
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200) {
Serial.println("Data sent successfully to ThingSpeak");
} else {
Serial.println("Error sending data");
}
delay(20000); // Update data every 20 seconds
}