#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "xxxxxxxxx";
const char* password = "xxxxxxxxxxx";
WebServer server(80);
String htmlPage() {
long rssi = WiFi.RSSI();
// Convertir RSSI en pourcentage
int percent = map(rssi, -90, -30, 0, 100);
percent = constrain(percent, 0, 100);
// Déterminer la couleur
String color = "red";
if (percent > 70) color = "green";
else if (percent > 40) color = "orange";
// Construction HTML
String page = "<!DOCTYPE html><html><head><meta charset='UTF-8'>";
page += "<meta http-equiv='refresh' content='1'>";
page += "<style>";
page += "body { font-family: Arial; text-align: center; margin-top: 30px; }";
page += ".bar-container { width: 60px; height: 300px; border: 2px solid #333; margin: auto; display: flex; align-items: flex-end; }";
page += ".bar { width: 100%; background: " + color + "; height: " + String(percent) + "%; transition: height 0.3s; }";
page += "h1 { font-size: 2em; }";
page += "p { font-size: 1.4em; }";
page += "</style></head><body>";
page += "<h1>Force du signal WiFi</h1>";
page += "<div class='bar-container'><div class='bar'></div></div>";
page += "<p><b>" + String(rssi) + " dBm</b></p>";
page += "<p>Qualité : " + String(percent) + "%</p>";
page += "</body></html>";
return page;
}
void handleRoot() {
server.send(200, "text/html", htmlPage());
}
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é !");
Serial.print("Adresse IP : ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}