Add OTA through ElegantOTA lite. OTA is accessible via IP_ADRESS/update
This commit is contained in:
parent
1180e340fb
commit
f2ddf22a5a
8
.theia/launch.json
Normal file
8
.theia/launch.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
@ -2,21 +2,45 @@
|
|||||||
#include "secret.h"
|
#include "secret.h"
|
||||||
#include "tic.h"
|
#include "tic.h"
|
||||||
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
#include <ElegantOTA.h>
|
||||||
|
|
||||||
// Activer le Wi-Fi
|
// Activer le Wi-Fi
|
||||||
#define WIFI_ENABLE
|
#define WIFI_ENABLE
|
||||||
|
|
||||||
// Initialiser le serveur web si le Wi-Fi est activé
|
// Initialiser le serveur web si le Wi-Fi est activé
|
||||||
#ifdef WIFI_ENABLE
|
|
||||||
ESP8266WebServer server(HTTP_PORT);
|
ESP8266WebServer server(HTTP_PORT);
|
||||||
#endif
|
|
||||||
|
|
||||||
// Durée de sommeil en microsecondes (par exemple, 5 secondes)
|
unsigned long ota_progress_millis = 0;
|
||||||
const int sleepDuration = 1 * 1000000;
|
|
||||||
|
void onOTAStart() {
|
||||||
|
// Log when OTA has started
|
||||||
|
Serial.println("OTA update started!");
|
||||||
|
// <Add your own code here>
|
||||||
|
}
|
||||||
|
|
||||||
|
void onOTAProgress(size_t current, size_t final) {
|
||||||
|
// Log every 1 second
|
||||||
|
if (millis() - ota_progress_millis > 1000) {
|
||||||
|
ota_progress_millis = millis();
|
||||||
|
Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onOTAEnd(bool success) {
|
||||||
|
// Log when OTA has finished
|
||||||
|
if (success) {
|
||||||
|
Serial.println("OTA update finished successfully!");
|
||||||
|
} else {
|
||||||
|
Serial.println("There was an error during OTA update!");
|
||||||
|
}
|
||||||
|
// <Add your own code here>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Fonction pour configurer et connecter au réseau Wi-Fi
|
// Fonction pour configurer et connecter au réseau Wi-Fi
|
||||||
void setup_wifi() {
|
void setup_wifi() {
|
||||||
@ -114,25 +138,6 @@ void setup_serial() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fonction pour mettre l'ESP8266 en mode deep sleep
|
|
||||||
void goToDeepSleep() {
|
|
||||||
DebugPort.println("Going to deep sleep...");
|
|
||||||
ESP.deepSleep(sleepDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
void goToLightSleep() {
|
|
||||||
DebugPort.println("Going to light sleep...");
|
|
||||||
wifi_set_opmode(NULL_MODE); // Turn off Wi-Fi
|
|
||||||
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // Set light sleep mode
|
|
||||||
wifi_fpm_open();
|
|
||||||
//gpio_pin_wakeup_enable(GPIO_ID_PIN(D1), GPIO_PIN_INTR_LOLEVEL); // Enable wakeup on GPIO
|
|
||||||
//wifi_fpm_do_wakeup_gpio(true);
|
|
||||||
//wifi_fpm_set_wakeup_gpio_mode(WAKEUP_GPIO_MODE_KEEP_HIGH);
|
|
||||||
wifi_fpm_set_wakeup_cb(loop);
|
|
||||||
wifi_fpm_do_sleep(sleepDuration); // Sleep
|
|
||||||
delay(20); // Short delay to allow the ESP8266 to enter sleep mode
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fonction d'initialisation principale
|
// Fonction d'initialisation principale
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
@ -143,6 +148,12 @@ void setup() {
|
|||||||
// Configurer les routes du serveur
|
// Configurer les routes du serveur
|
||||||
restServerRouting();
|
restServerRouting();
|
||||||
|
|
||||||
|
ElegantOTA.begin(&server);
|
||||||
|
// ElegantOTA callbacks
|
||||||
|
ElegantOTA.onStart(onOTAStart);
|
||||||
|
ElegantOTA.onProgress(onOTAProgress);
|
||||||
|
ElegantOTA.onEnd(onOTAEnd);
|
||||||
|
|
||||||
// Démarrer le serveur HTTP
|
// Démarrer le serveur HTTP
|
||||||
DebugPort.println("Start HTTP server");
|
DebugPort.println("Start HTTP server");
|
||||||
server.begin();
|
server.begin();
|
||||||
@ -152,14 +163,13 @@ void setup() {
|
|||||||
|
|
||||||
// Boucle principale
|
// Boucle principale
|
||||||
void loop() {
|
void loop() {
|
||||||
|
ElegantOTA.loop();
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
readTicPort();
|
readTicPort();
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
// Si aucune requête n'est en cours, mettre l'ESP8266 en mode deep sleep
|
|
||||||
/*
|
/*
|
||||||
|
// Si aucune requête n'est en cours, mettre l'ESP8266 en mode deep sleep
|
||||||
if (server.client().available() == 0) {
|
if (server.client().available() == 0) {
|
||||||
goToLightSleep();
|
goToDeepSleep();
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
@ -16,3 +16,11 @@
|
|||||||
|
|
||||||
const char *ssid = STASSID;
|
const char *ssid = STASSID;
|
||||||
const char *passPhrase = STAPSK;
|
const char *passPhrase = STAPSK;
|
||||||
|
|
||||||
|
// MQTT Broker settings
|
||||||
|
const char *mqtt_broker = "broker.emqx.io"; // EMQX broker endpoint
|
||||||
|
const char *mqtt_topic = "emqx/esp8266/led"; // MQTT topic
|
||||||
|
const char *mqtt_username = "emqx"; // MQTT username for authentication
|
||||||
|
const char *mqtt_password = "public"; // MQTT password for authentication
|
||||||
|
const int mqtt_port = 1883; // MQTT port (TCP)
|
||||||
|
const char *mqtt_clientId = "tic_client-"
|
Loading…
Reference in New Issue
Block a user