Refactor controller and updater classes, update platformio configuration, and improve WiFi connection handling

This commit is contained in:
2026-06-10 19:20:13 +02:00
parent b9602ca614
commit 9a6f9954da
8 changed files with 56 additions and 36 deletions
+3
View File
@@ -13,6 +13,9 @@ platform = espressif32
board = arduino_nano_esp32 board = arduino_nano_esp32
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
upload_port = /dev/ttyACM0
monitor_port = /dev/ttyACM0
; Équivalent de "Partition Scheme → Default with OTA" ; Équivalent de "Partition Scheme → Default with OTA"
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
build_flags = -std=c++17
+4 -7
View File
@@ -9,17 +9,14 @@ Controller::Controller() {
} }
void Controller::initController() { void Controller::initController() {
for (int i = 0; i < 5; i++) { for (unsigned short i = 0; i < 5; i++) {
// créer le volet // créer le volet
unsigned short pinDown = 9 - (2 * i); unsigned short pinDown = 9 - (2 * i);
unsigned short pinUp = 8 - (2 * i); unsigned short pinUp = 8 - (2 * i);
Shutter shutter{pinUp, pinDown, i}; // i est le nom shutters[i] = new Shutter(pinUp, pinDown, i);
pinMode(i, OUTPUT); pinMode(i, OUTPUT);
// stock le volet
shutters[i] = &shutter;
} }
// Permet de correctement initaliser tout les volets // Permet de correctement initaliser tout les volets
@@ -33,12 +30,12 @@ void Controller::openExactePercentSpecificShutter(unsigned short shutter, float
else if (percent > 100) else if (percent > 100)
percent = 100; percent = 100;
if (shutter < 0 && shutter >= 5) if (shutter < 0 || shutter >= 5)
return; return;
float percentOpen = shutters[shutter]->percentOpen; float percentOpen = shutters[shutter]->percentOpen;
// si le volet est deja ouvert a son pourcentage, ne rien faire // si le volet est deja ouvert a son pourcentage, ne rien faire
if (percent = percentOpen) if (percent == percentOpen)
return; return;
float deltaPercent = percentOpen - percent; float deltaPercent = percentOpen - percent;
+13 -13
View File
@@ -1,6 +1,19 @@
#ifndef CONTROLER #ifndef CONTROLER
#define CONTROLER #define CONTROLER
struct Shutter {
public:
const unsigned short pinUp;
const unsigned short pinDown;
const unsigned short name;
const unsigned short TIMETOOPEN = 10; // en secondes
float percentOpen = 0.0f; // pourcentage d'ouverture du volet, 0: fermer | 100: ouvert
// Constructeur
Shutter(unsigned short up, unsigned short down, unsigned short n) : pinUp(up), pinDown(down), name(n) {}
};
class Controller { class Controller {
public: public:
Shutter* shutters[5]; Shutter* shutters[5];
@@ -15,17 +28,4 @@ class Controller {
void manualOpen(); void manualOpen();
}; };
struct Shutter {
public:
const unsigned short pinUp;
const unsigned short pinDown;
const unsigned short name;
const unsigned short TIMETOOPEN = 10; // en secondes
float percentOpen = 0.0f; // pourcentage d'ouverture du volet, 0: fermer | 100: ouvert
// Constructeur
Shutter(unsigned short up, unsigned short down, unsigned short n) : pinUp(up), pinDown(down), name(n) {}
};
#endif #endif
+15 -7
View File
@@ -13,15 +13,23 @@ Updater updater;
Controller controller; Controller controller;
void setup() { void setup() {
updater.update(); // vérifie les updates Serial.begin(115200);
controller.initController(); delay(2000); // Attendez que le moniteur se connecte
Serial.println("\n\n=== DÉMARRAGE ===");
Serial.println("Serial connecté!");
updater.update();
Serial.println("Updater terminé");
// controller.initController();
// Serial.println("Contrôleur initialisé");
} }
void loop() { void loop() {
if (millis() > timeWaitRestart) // redemarrage tout les 6mois // if (millis() > timeWaitRestart) // redemarrage tout les 6mois
ESP.restart(); // ESP.restart();
else if (lastTimeCheckUpdate - millis() > timeWaitCheckUpdate) // else if (lastTimeCheckUpdate - millis() > timeWaitCheckUpdate)
updater.update(); // updater.update();
controller.manualOpen(); // controller.manualOpen();
} }
+7
View File
@@ -2,6 +2,10 @@
#include "updater.h" #include "updater.h"
const int THISVERSION = 1;
const char* FIRMWAREURL = "http://89.168.57.22:6543/";
const char* VERSIONURL = "http://89.168.57.22/6543/LastVersion.txt";
Updater::Updater() { Updater::Updater() {
} }
@@ -9,6 +13,7 @@ bool Updater::checkUpdate() {
HTTPClient http; HTTPClient http;
// 1. Vérifie si une nouvelle version est disponible // 1. Vérifie si une nouvelle version est disponible
Serial.println("recherche de version");
http.begin(VERSIONURL); // ton-serveur.com/version.txt"); http.begin(VERSIONURL); // ton-serveur.com/version.txt");
int httpCode = http.GET(); int httpCode = http.GET();
@@ -24,6 +29,8 @@ bool Updater::checkUpdate() {
return false; return false;
} }
return false;
} }
void Updater::update() { void Updater::update() {
+3 -3
View File
@@ -1,9 +1,9 @@
#ifndef UPDATER #ifndef UPDATER
#define UPDATER #define UPDATER
const int THISVERSION = 1; extern const int THISVERSION;
const char* FIRMWAREURL = "http://89.168.57.22:6543/"; extern const char* FIRMWAREURL;
const char* VERSIONURL = "http://89.168.57.22/6543/LastVersion.txt"; extern const char* VERSIONURL;
// Permet la mise a jour a distance // Permet la mise a jour a distance
class Updater { class Updater {
+7 -2
View File
@@ -3,10 +3,15 @@
#include "wifiManager.h" #include "wifiManager.h"
const char* SSID = "Livebox-51A0";
const char* PASSWORD = "mGmMjFh5NPL5PNLJRb";
WifiManager::WifiManager() { WifiManager::WifiManager() {
Serial.begin(115200);
WiFi.begin(SSID, PASSWORD); WiFi.begin(SSID, PASSWORD);
while (WiFi.status() != WL_CONNECTED) delay(500); while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.println("WiFi connecté"); Serial.println("WiFi connecté");
} }
+3 -3
View File
@@ -1,14 +1,14 @@
#ifndef WIFIMANAGER #ifndef WIFIMANAGER
#define WIFIMANAGER #define WIFIMANAGER
const char* SSID = "ton_wifi"; extern const char* SSID;
const char* PASSWORD = "ton_mdp"; extern const char* PASSWORD;
class WifiManager { class WifiManager {
public: public:
WifiManager(); WifiManager();
void start(); // void start();
}; };
#endif #endif