diff --git a/Hard/platformio.ini b/Hard/platformio.ini index afece18..b62f6a6 100644 --- a/Hard/platformio.ini +++ b/Hard/platformio.ini @@ -12,3 +12,7 @@ platform = espressif32 board = arduino_nano_esp32 framework = arduino +monitor_speed = 115200 + +; Équivalent de "Partition Scheme → Default with OTA" +board_build.partitions = min_spiffs.csv \ No newline at end of file diff --git a/Hard/src/main.cpp b/Hard/src/main.cpp index cb9fbba..2a28309 100644 --- a/Hard/src/main.cpp +++ b/Hard/src/main.cpp @@ -1,18 +1,10 @@ #include -// put function declarations here: -int myFunction(int, int); +#include "updater.h" +#include "wifiManager.h" void setup() { - // put your setup code here, to run once: - int result = myFunction(2, 3); } void loop() { - // put your main code here, to run repeatedly: -} - -// put function definitions here: -int myFunction(int x, int y) { - return x + y; } \ No newline at end of file diff --git a/Hard/src/updater.cpp b/Hard/src/updater.cpp new file mode 100644 index 0000000..09dc50b --- /dev/null +++ b/Hard/src/updater.cpp @@ -0,0 +1,49 @@ +#include + +#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; + } + } +} \ No newline at end of file diff --git a/Hard/src/updater.h b/Hard/src/updater.h new file mode 100644 index 0000000..0432d54 --- /dev/null +++ b/Hard/src/updater.h @@ -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 \ No newline at end of file diff --git a/Hard/src/wifiManager.cpp b/Hard/src/wifiManager.cpp new file mode 100644 index 0000000..32cfcc4 --- /dev/null +++ b/Hard/src/wifiManager.cpp @@ -0,0 +1,12 @@ +#include +#include + +#include "wifiManager.h" + +WifiManager::WifiManager() { + Serial.begin(115200); + WiFi.begin(SSID, PASSWORD); + + while (WiFi.status() != WL_CONNECTED) delay(500); + Serial.println("WiFi connecté"); +} \ No newline at end of file diff --git a/Hard/src/wifiManager.h b/Hard/src/wifiManager.h new file mode 100644 index 0000000..584beba --- /dev/null +++ b/Hard/src/wifiManager.h @@ -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 \ No newline at end of file