#include #include // Replace with your WiFi credentials const char* ssid = "FABLAB"; const char* password = "12345678"; // Replace with your ThingSpeak Write API Key const char* apiKey = "15DBNHTNHL25YMYN"; // ThingSpeak API URL const char* server = "http://api.thingspeak.com/update"; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.print("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(1000); } Serial.println("\nConnected to WiFi!"); } void loop() { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; // Generate random values int value1 = random(20, 40); // Example: Temperature int value2 = random(30, 60); // Example: Humidity int value3 = random(100, 500); // Example: Light Intensity // Construct the request URL String url = String(server) + "?api_key=" + apiKey + "&field1=" + String(value1) + "&field2=" + String(value2) + "&field3=" + String(value3); Serial.println("Sending data to ThingSpeak..."); Serial.println(url); // Send data to ThingSpeak http.begin(url); int httpCode = http.GET(); if (httpCode > 0) { Serial.println("Data sent successfully!"); } else { Serial.println("Failed to send data."); } http.end(); } else { Serial.println("WiFi Disconnected!"); } delay(15000); // ThingSpeak allows updates every 15 seconds }