ESPSomfy-RTS/SomfyController.ino
Anthony Marchand 0e0a482afb feat: ajout du support Ethernet W5500 SPI
- Intégration du contrôleur Ethernet W5500 via SPI pour les cartes
  comme Waveshare ESP32-S3 POE
- Configuration des pins SPI (MOSI, MISO, SCLK, CS, INT, RST) via
  l'interface web
- Utilisation directe des APIs ESP-IDF pour le W5500 car la classe
  Arduino ETH ne supporte pas nativement ce contrôleur
- Gestion manuelle du DHCP et DNS pour le W5500
- Protection des appels ETH Arduino quand W5500 est utilisé
- Désactivation temporaire de la vérification OTA GitHub pour W5500
  (problème de compatibilité HTTPClient)
- Ajout des presets de cartes dans l'interface (Waveshare, etc.)
2026-01-18 22:40:06 +01:00

94 lines
2.4 KiB
C++

#include <WiFi.h>
#include <LittleFS.h>
#include <esp_task_wdt.h>
#include "ConfigSettings.h"
#include "Network.h"
#include "Web.h"
#include "Sockets.h"
#include "Utils.h"
#include "Somfy.h"
#include "MQTT.h"
#include "GitOTA.h"
ConfigSettings settings;
Web webServer;
SocketEmitter sockEmit;
Network net;
rebootDelay_t rebootDelay;
SomfyShadeController somfy;
MQTTClass mqtt;
GitUpdater git;
uint32_t oldheap = 0;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Startup/Boot....");
Serial.println("Mounting File System...");
if(LittleFS.begin()) Serial.println("File system mounted successfully");
else Serial.println("Error mounting file system");
settings.begin();
if(WiFi.status() == WL_CONNECTED) WiFi.disconnect(true);
delay(10);
Serial.println();
webServer.startup();
webServer.begin();
delay(1000);
net.setup();
somfy.begin();
//git.checkForUpdate();
esp_task_wdt_init(15, true); //enable panic so ESP32 restarts (increased from 7 to 15 seconds)
esp_task_wdt_add(NULL); //add current thread to WDT watch
}
void loop() {
esp_task_wdt_reset();
// put your main code here, to run repeatedly:
//uint32_t heap = ESP.getFreeHeap();
if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) {
Serial.print("Rebooting after ");
Serial.print(rebootDelay.rebootTime);
Serial.println("ms");
net.end();
ESP.restart();
return;
}
uint32_t timing = millis();
net.loop();
if(millis() - timing > 100) Serial.printf("Timing Net: %ldms\n", millis() - timing);
esp_task_wdt_reset();
timing = millis();
somfy.loop();
if(millis() - timing > 100) Serial.printf("Timing Somfy: %ldms\n", millis() - timing);
esp_task_wdt_reset();
timing = millis();
if(net.connected() || net.softAPOpened) {
if(!rebootDelay.reboot && net.connected() && !net.softAPOpened) {
git.loop();
esp_task_wdt_reset();
}
webServer.loop();
if(millis() - timing > 100) Serial.printf("Timing WebServer: %ldms\n", millis() - timing);
esp_task_wdt_reset();
timing = millis();
sockEmit.loop();
if(millis() - timing > 100) Serial.printf("Timing Socket: %ldms\n", millis() - timing);
esp_task_wdt_reset();
}
if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) {
net.end();
ESP.restart();
}
// Final watchdog reset before end of loop
esp_task_wdt_reset();
// Small delay to prevent tight loop from consuming too much CPU
delay(1);
}