#include <WiFi.h>
#include "ThingSpeak.h"
const char* ssid = "Wokwi-GUEST";  // WiFi de test fourni par Wokwi
const char* password = "";
WiFiClient client;
unsigned long channelID = 3111931; // <-- Remplace par ton Channel ID
const char* writeAPIKey = "3IINXQH8UO87BHUE"; // <-- Remplace par ta clé API
void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.print("Connexion WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\n✅ Connecté au WiFi !");
  ThingSpeak.begin(client);
}
void loop() {
  // Simulation de donnée : température aléatoire
  float temperature = random(200, 300) / 10.0; // entre 20.0 et 30.0 °C
  Serial.print("Envoi à ThingSpeak : ");
  Serial.println(temperature);
  int response = ThingSpeak.writeField(channelID, 1, temperature, writeAPIKey);
  if (response == 200) {
    Serial.println("✅ Donnée envoyée avec succès !");
  } else {
    Serial.println("⚠️ Erreur lors de l'envoi (" + String(response) + ")");
  }
  delay(20000); // ThingSpeak accepte 1 envoi toutes les 15 s min
}