setup projet

ajout de l'updater et du wifimanager
This commit is contained in:
2026-06-08 12:37:30 +02:00
parent 22a0eec84d
commit 204cdef7d7
6 changed files with 97 additions and 10 deletions
+4
View File
@@ -12,3 +12,7 @@
platform = espressif32 platform = espressif32
board = arduino_nano_esp32 board = arduino_nano_esp32
framework = arduino framework = arduino
monitor_speed = 115200
; Équivalent de "Partition Scheme → Default with OTA"
board_build.partitions = min_spiffs.csv
+2 -10
View File
@@ -1,18 +1,10 @@
#include <Arduino.h> #include <Arduino.h>
// put function declarations here: #include "updater.h"
int myFunction(int, int); #include "wifiManager.h"
void setup() { void setup() {
// put your setup code here, to run once:
int result = myFunction(2, 3);
} }
void loop() { void loop() {
// put your main code here, to run repeatedly:
}
// put function definitions here:
int myFunction(int x, int y) {
return x + y;
} }
+49
View File
@@ -0,0 +1,49 @@
#include <HTTPUpdate.h>
#include "updater.h"
Updater::Updater() {
}
bool Updater::checkUpdate() {
HTTPClient http;
// 1. Vérifie si une nouvelle version est disponible
http.begin(VERSIONURL); // ton-serveur.com/version.txt");
int httpCode = http.GET();
if (httpCode == 200) {
int nouvelleVersion = http.getString().toInt();
http.end();
if (nouvelleVersion > THISVERSION) {
Serial.println("Nouvelle version trouvée ! ");
return true;
}
return false;
}
}
void Updater::update() {
if (checkUpdate()) {
// 2. Télécharge et flashe le nouveau firmware
WiFiClient client;
httpUpdate.setLedPin(LED_BUILTIN, LOW);
t_httpUpdate_return ret = httpUpdate.update(client, FIRMWAREURL);
switch (ret) {
case HTTP_UPDATE_OK:
Serial.println("Succès ! Redémarrage...");
break;
case HTTP_UPDATE_FAILED:
Serial.printf("Échec : %s\n", httpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("Pas de mise à jour.");
break;
}
}
}
+16
View File
@@ -0,0 +1,16 @@
#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";
class Updater {
public:
Updater();
bool checkUpdate();
void update();
};
#endif
+12
View File
@@ -0,0 +1,12 @@
#include <WiFi.h>
#include <HTTPClient.h>
#include "wifiManager.h"
WifiManager::WifiManager() {
Serial.begin(115200);
WiFi.begin(SSID, PASSWORD);
while (WiFi.status() != WL_CONNECTED) delay(500);
Serial.println("WiFi connecté");
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef WIFIMANAGER
#define WIFIMANAGER
const char* SSID = "ton_wifi";
const char* PASSWORD = "ton_mdp";
class WifiManager {
public:
WifiManager();
void start();
};
#endif