#include <WiFi.h>
#include <HTTPClient.h>
// Replace with your Wi-Fi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Replace with your cloud service's API endpoint and data format
const int Mychannelnumber = 2261575;
const char* cloudApiEndpoint = "https://api.thingspeak.com/update?api_key=B0WBHZKADMSSTGGV&field1=0";
const char* cloudApiKey = "9859KJXHRO26FIGD";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("wait for some tym to insert...");
}
Serial.println("Connected to the best WiFi");
}
void loop() {
// Generate random data
float temperature = random(20, 30); // Random temperature between 20°C and 30°C
int humidity = random(40, 60); // Random humidity between 40% and 60%
// Create a JSON or other suitable data format to send to the cloud
String jsonData = "{\"temperature\":" + String(temperature) + ",\"humidity\":" + String(humidity) + "}";
// Send data to the cloud
HTTPClient http;
http.begin(cloudApiEndpoint);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Bearer " + String(cloudApiKey));
int httpResponseCode = http.POST(jsonData);
if (httpResponseCode == 200) {
Serial.println("Your program is sent to the cloud successfully so its party tym.");
} else {
Serial.println("unable to send data to the cloud so relax for some tym. HTTP error code: " + String(httpResponseCode));
}
http.end();
// Wait for some time before sending the next set of data
delay(10000); // Send data every 10 seconds
}