#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST"; // Simulated SSID in Wokwi
const char* password = ""; // No password for simulated WiFi
const char* serverName = "http://soufiane-arduino.000webhostapp.com/insert_data.php";
void setup() {
Serial.begin(115200);
// Simulate connecting to WiFi
Serial.print("Connecting to WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected to WiFi");
// Now you can make an HTTP request
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "data=" + String("java the best");
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("WiFi not connected");
}
}
void loop() {
// Main code loop
delay(10000); // Send data every 10 seconds
}