#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* serverName = "https://scam-self-roulette.ngrok-free.dev/data.php";
const int potPin = 34;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connexion au WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnecté au réseau");
}
void loop() {
int sensorValue = analogRead(potPin);
int gazLevel = map(sensorValue, 0, 4095, 0, 500);
Serial.print("Niveau de gaz détecté : ");
Serial.println(gazLevel);
if(WiFi.status() == WL_CONNECTED){
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type", "text/plain");
http.addHeader("ngrok-skip-browser-warning", "true");
int httpResponseCode = http.POST(String(gazLevel));
if (httpResponseCode > 0) {
Serial.print("Code réponse HTTP : ");
Serial.println(httpResponseCode);
} else {
Serial.print("Erreur HTTP : ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(5000);
}