From a0eb3ebaeb5985d16fd2505e5740b9936d3317da Mon Sep 17 00:00:00 2001 From: Nagoydede Date: Tue, 25 Mar 2025 22:06:22 +0100 Subject: [PATCH] comments and code cleaning --- linky_tic.ino | 36 +++++++++++++++++++++++++----------- tic.h | 3 +++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/linky_tic.ino b/linky_tic.ino index 76b4caf..31f7e18 100644 --- a/linky_tic.ino +++ b/linky_tic.ino @@ -7,16 +7,18 @@ #include #include +// Activer le Wi-Fi +#define WIFI_ENABLE -#define WIFI_ENABLE //enable wifi -#define SERVER_NAME "ticweb" +// Initialiser le serveur web si le Wi-Fi est activé #ifdef WIFI_ENABLE -ESP8266WebServer server(80); +ESP8266WebServer server(HTTP_PORT); #endif +// Fonction pour configurer et connecter au réseau Wi-Fi void setup_wifi() { delay(10); - // We start by connecting to a WiFi network + // Connexion au réseau Wi-Fi DebugPort.println(); DebugPort.print("Connecting to "); DebugPort.println(ssid); @@ -25,6 +27,7 @@ void setup_wifi() { WiFi.begin(ssid, passPhrase); int c = 0; + // Attendre la connexion Wi-Fi while (WiFi.status() != WL_CONNECTED) { delay(500); DebugPort.print("."); @@ -35,42 +38,50 @@ void setup_wifi() { DebugPort.println(WiFi.localIP()); } +// Fonction pour obtenir les paramètres réseau et matériels void getSettings() { String response = "{"; + // Ajouter les informations réseau à la réponse JSON response += "\"ip\": \"" + WiFi.localIP().toString() + "\""; response += ",\"gw\": \"" + WiFi.gatewayIP().toString() + "\""; response += ",\"nm\": \"" + WiFi.subnetMask().toString() + "\""; + // Ajouter l'intensité du signal Wi-Fi si demandé if (server.arg("signalStrength") == "true") { response += ",\"signalStrengh\": \"" + String(WiFi.RSSI()) + "\""; } + // Ajouter les informations matérielles si demandé if (server.arg("chipInfo") == "true") { response += ",\"chipId\": \"" + String(ESP.getChipId()) + "\""; response += ",\"flashChipId\": \"" + String(ESP.getFlashChipId()) + "\""; response += ",\"flashChipSize\": \"" + String(ESP.getFlashChipSize()) + "\""; response += ",\"flashChipRealSize\": \"" + String(ESP.getFlashChipRealSize()) + "\""; } + // Ajouter la mémoire libre disponible si demandé if (server.arg("freeHeap") == "true") { response += ",\"freeHeap\": \"" + String(ESP.getFreeHeap()) + "\""; } response += "}"; + // Envoyer la réponse JSON au client server.send(200, "text/json", response); } +// Fonction pour obtenir les données TIC complètes void getTicData() { String response = ticValuesAsJson(); server.send(200, "text/json", response.c_str()); } +// Fonction pour obtenir les données TIC de base void getTicBasicData() { String response = ticBasicValuesAsJson(); server.send(200, "text/json", response.c_str()); } -// Define routing +// Définir les routes du serveur REST void restServerRouting() { server.on("/", HTTP_GET, []() { server.send(200, F("text/html"), @@ -81,6 +92,7 @@ void restServerRouting() { server.on(F("/ticbasic"), HTTP_GET, getTicBasicData); } +// Fonction pour configurer la communication série void setup_serial() { //debug interface //there is only RX on Serial 0 interface @@ -88,33 +100,35 @@ void setup_serial() { //thanks to swap. //The speed is not appropriate for debug. //Debug serial port is on Serial 1, TX only - DebugPort.begin(9600, SERIAL_7E1); + DebugPort.begin(TIC_SPEED, SERIAL_7E1); -//data acquisition interface + // Interface d'acquisition des données #ifdef TIC - TicPort.begin(9600, SERIAL_7E1); + TicPort.begin(TIC_SPEED, SERIAL_7E1); Serial.swap(); #else - TicPort.begin(115200); + TicPort.begin(DEBUG_SPEED); #endif } +// Fonction d'initialisation principale void setup() { setup_serial(); #ifdef WIFI_ENABLE setup_wifi(); - // Set server routing + // Configurer les routes du serveur restServerRouting(); - // Start server + // Démarrer le serveur HTTP DebugPort.println("Start HTTP server"); server.begin(); DebugPort.println("HTTP server started"); #endif } +// Boucle principale void loop() { server.handleClient(); readTicPort(); diff --git a/tic.h b/tic.h index f78482c..c6450c0 100644 --- a/tic.h +++ b/tic.h @@ -7,6 +7,9 @@ #define TIC +#define TIC_SPEED 9600 //9600 bps en mode standard ou 1500 bps pour le mode historique +#define DEBUG_SPEED 115200 //vitesse port débug +#define HTTP_PORT 80 //port // Définition des constantes pour les délimiteurs de trame TIC //CF document ENEDIS