Refactor controller and updater classes, update platformio configuration, and improve WiFi connection handling
This commit is contained in:
+4
-1
@@ -13,6 +13,9 @@ platform = espressif32
|
||||
board = arduino_nano_esp32
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_port = /dev/ttyACM0
|
||||
monitor_port = /dev/ttyACM0
|
||||
|
||||
; Équivalent de "Partition Scheme → Default with OTA"
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = min_spiffs.csv
|
||||
build_flags = -std=c++17
|
||||
@@ -9,17 +9,14 @@ Controller::Controller() {
|
||||
}
|
||||
|
||||
void Controller::initController() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (unsigned short i = 0; i < 5; i++) {
|
||||
// créer le volet
|
||||
unsigned short pinDown = 9 - (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);
|
||||
|
||||
// stock le volet
|
||||
shutters[i] = &shutter;
|
||||
}
|
||||
|
||||
// Permet de correctement initaliser tout les volets
|
||||
@@ -33,12 +30,12 @@ void Controller::openExactePercentSpecificShutter(unsigned short shutter, float
|
||||
else if (percent > 100)
|
||||
percent = 100;
|
||||
|
||||
if (shutter < 0 && shutter >= 5)
|
||||
if (shutter < 0 || shutter >= 5)
|
||||
return;
|
||||
|
||||
float percentOpen = shutters[shutter]->percentOpen;
|
||||
// si le volet est deja ouvert a son pourcentage, ne rien faire
|
||||
if (percent = percentOpen)
|
||||
if (percent == percentOpen)
|
||||
return;
|
||||
|
||||
float deltaPercent = percentOpen - percent;
|
||||
|
||||
+13
-13
@@ -1,6 +1,19 @@
|
||||
#ifndef 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 {
|
||||
public:
|
||||
Shutter* shutters[5];
|
||||
@@ -15,17 +28,4 @@ class Controller {
|
||||
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
|
||||
+15
-7
@@ -13,15 +13,23 @@ Updater updater;
|
||||
Controller controller;
|
||||
|
||||
void setup() {
|
||||
updater.update(); // vérifie les updates
|
||||
controller.initController();
|
||||
Serial.begin(115200);
|
||||
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() {
|
||||
if (millis() > timeWaitRestart) // redemarrage tout les 6mois
|
||||
ESP.restart();
|
||||
else if (lastTimeCheckUpdate - millis() > timeWaitCheckUpdate)
|
||||
updater.update();
|
||||
// if (millis() > timeWaitRestart) // redemarrage tout les 6mois
|
||||
// ESP.restart();
|
||||
// else if (lastTimeCheckUpdate - millis() > timeWaitCheckUpdate)
|
||||
// updater.update();
|
||||
|
||||
controller.manualOpen();
|
||||
// controller.manualOpen();
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#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() {
|
||||
}
|
||||
|
||||
@@ -9,6 +13,7 @@ bool Updater::checkUpdate() {
|
||||
HTTPClient http;
|
||||
|
||||
// 1. Vérifie si une nouvelle version est disponible
|
||||
Serial.println("recherche de version");
|
||||
http.begin(VERSIONURL); // ton-serveur.com/version.txt");
|
||||
int httpCode = http.GET();
|
||||
|
||||
@@ -24,6 +29,8 @@ bool Updater::checkUpdate() {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Updater::update() {
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#ifndef UPDATER
|
||||
#define UPDATER
|
||||
|
||||
const int THISVERSION = 1;
|
||||
const char* FIRMWAREURL = "http://89.168.57.22:6543/";
|
||||
const char* VERSIONURL = "http://89.168.57.22/6543/LastVersion.txt";
|
||||
extern const int THISVERSION;
|
||||
extern const char* FIRMWAREURL;
|
||||
extern const char* VERSIONURL;
|
||||
|
||||
// Permet la mise a jour a distance
|
||||
class Updater {
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
|
||||
#include "wifiManager.h"
|
||||
|
||||
const char* SSID = "Livebox-51A0";
|
||||
const char* PASSWORD = "mGmMjFh5NPL5PNLJRb";
|
||||
|
||||
WifiManager::WifiManager() {
|
||||
Serial.begin(115200);
|
||||
WiFi.begin(SSID, PASSWORD);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) delay(500);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print('.');
|
||||
}
|
||||
Serial.println("WiFi connecté");
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef WIFIMANAGER
|
||||
#define WIFIMANAGER
|
||||
|
||||
const char* SSID = "ton_wifi";
|
||||
const char* PASSWORD = "ton_mdp";
|
||||
extern const char* SSID;
|
||||
extern const char* PASSWORD;
|
||||
|
||||
class WifiManager {
|
||||
public:
|
||||
WifiManager();
|
||||
|
||||
void start();
|
||||
// void start();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user