include <ThingSpeak.h>
// Replace with your Wi-Fi credentials
const char* ssid = "your-ssid";
const char* password = "your-password";
// Replace with your ThingSpeak channel details
const char* server = "api.thingspeak.com";
const char* apiKey = "your-api-key";
const unsigned long channelId = your-channel-id;
WiFiClient client;
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");
}
void loop() {
// Your sensor readings go here
float sensorValue = 123.45;
ThingSpeak.begin(client);
ThingSpeak.writeField(channelId, 1, sensorValue, apiKey);
int httpCode = ThingSpeak.writeFields(channelId, apiKey);
ThingSpeak.stop();
if (httpCode == 200) {
Serial.println("Data sent to ThingSpeak successfully");
} else {
Serial.println("Error sending data to ThingSpeak");
}
delay(60000); // Send data every 1 minute
}