1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

feat: add OTA functionality for ESP32

This commit is contained in:
Sen Morgan 2024-01-28 19:54:31 +01:00
parent 3b162996ad
commit 7294535321
3 changed files with 70 additions and 26 deletions

View File

@ -52,6 +52,10 @@
#include "DCCEX.h" #include "DCCEX.h"
#include "Display_Implementation.h" #include "Display_Implementation.h"
#ifdef OTA_ENABLED
#include <ArduinoOTA.h>
#endif // OTA_ENABLED
#ifdef CPU_TYPE_ERROR #ifdef CPU_TYPE_ERROR
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h #error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h
#endif #endif
@ -101,6 +105,16 @@ void setup()
#else #else
// ESP32 needs wifi on always // ESP32 needs wifi on always
WifiESP::setup(WIFI_SSID, WIFI_PASSWORD, WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP); WifiESP::setup(WIFI_SSID, WIFI_PASSWORD, WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP);
// Start OTA if enabled
#ifdef OTA_ENABLED
ArduinoOTA.setHostname(WIFI_HOSTNAME);
#ifdef OTA_AUTH
ArduinoOTA.setPassword(OTA_AUTH);
#endif // OTA_AUTH
ArduinoOTA.begin();
#endif // OTA_ENABLED
#endif // ARDUINO_ARCH_ESP32 #endif // ARDUINO_ARCH_ESP32
#if ETHERNET_ON #if ETHERNET_ON
@ -150,6 +164,9 @@ void loop()
#ifndef WIFI_TASK_ON_CORE0 #ifndef WIFI_TASK_ON_CORE0
WifiESP::loop(); WifiESP::loop();
#endif #endif
#ifdef OTA_ENABLED
ArduinoOTA.handle();
#endif // OTA_ENABLED
#endif //ARDUINO_ARCH_ESP32 #endif //ARDUINO_ARCH_ESP32
#if ETHERNET_ON #if ETHERNET_ON
EthernetInterface::loop(); EthernetInterface::loop();

View File

@ -117,6 +117,9 @@ The configuration file for DCC-EX Command Station
#define WIFI_PASSWORD "Your network passwd" #define WIFI_PASSWORD "Your network passwd"
// //
// WIFI_HOSTNAME: You probably don't need to change this // WIFI_HOSTNAME: You probably don't need to change this
// Note: If you're using OTA updates (OTA_ENABLED == true), and decide
// to modify this name, remember to concurrently update the "upload_port"
// in the corresponding environment within the platformio.ini file.
#define WIFI_HOSTNAME "dccex" #define WIFI_HOSTNAME "dccex"
// //
// WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented, // WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented,
@ -129,6 +132,17 @@ The configuration file for DCC-EX Command Station
// true. Otherwise it is assumed that you'd like to connect to an existing network // true. Otherwise it is assumed that you'd like to connect to an existing network
// with that SSID. // with that SSID.
#define WIFI_FORCE_AP false #define WIFI_FORCE_AP false
//
// OTA_ENABLED: If you'd like to enable OTA updates, set this to true. Otherwise,
// OTA updates will not be available.
#define OTA_ENABLED true
//
// OTA_AUTH: If you'd like to change the OTA password, set this to the password
// you'd like to use. Otherwise, the default password will be "dccex-ota".
// Note: After changing the OTA password, you must update the "upload_flags → --auth"
// in the corresponding environment within the platformio.ini file.
#define OTA_AUTH "dccex-ota"
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
// //

View File

@ -176,6 +176,19 @@ build_flags = -std=c++17
monitor_speed = 115200 monitor_speed = 115200
monitor_echo = yes monitor_echo = yes
[env:ESP32-OTA]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = ${env.lib_deps}
build_flags = -std=c++17
monitor_speed = 115200
monitor_echo = yes
upload_protocol = espota
upload_port = dccex
upload_flags =
--auth=dccex-ota
[env:Nucleo-F411RE] [env:Nucleo-F411RE]
platform = ststm32 platform = ststm32
board = nucleo_f411re board = nucleo_f411re