setup projet
ajout de l'updater et du wifimanager
This commit is contained in:
@@ -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
|
||||
+2
-10
@@ -1,18 +1,10 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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é");
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user