mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-04-21 04:21:20 +02:00
Merge 9a6cd8dd76856a3e8e44f1cf60e7c06c0f0fdc4d into 8ac61b88d444ff1e8d48e17b590ba383ed591560
This commit is contained in:
commit
53320dd9f4
@ -52,6 +52,10 @@
|
|||||||
#include "DCCEX.h"
|
#include "DCCEX.h"
|
||||||
#include "Display_Implementation.h"
|
#include "Display_Implementation.h"
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
#endif // ARDUINO_ARCH_ESP32
|
||||||
|
|
||||||
#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
|
||||||
@ -112,6 +116,9 @@ void setup()
|
|||||||
// ESP32 needs wifi on always
|
// ESP32 needs wifi on always
|
||||||
PASSWDCHECK(WIFI_PASSWORD); // compile time check
|
PASSWDCHECK(WIFI_PASSWORD); // compile time check
|
||||||
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);
|
||||||
|
#if OTA_AUTO_INIT
|
||||||
|
Diag::OTA = true;
|
||||||
|
#endif // OTA_AUTO_INIT
|
||||||
#endif // ARDUINO_ARCH_ESP32
|
#endif // ARDUINO_ARCH_ESP32
|
||||||
|
|
||||||
#if ETHERNET_ON
|
#if ETHERNET_ON
|
||||||
@ -179,6 +186,50 @@ void loop()
|
|||||||
#ifndef WIFI_TASK_ON_CORE0
|
#ifndef WIFI_TASK_ON_CORE0
|
||||||
WifiESP::loop();
|
WifiESP::loop();
|
||||||
#endif
|
#endif
|
||||||
|
// Responsibility 4: Optionally handle Arduino OTA updates
|
||||||
|
if (Diag::OTA) {
|
||||||
|
static bool otaInitialised = false;
|
||||||
|
// Initialise OTA if not already done
|
||||||
|
if (!otaInitialised) {
|
||||||
|
ArduinoOTA.setHostname(WIFI_HOSTNAME);
|
||||||
|
// Prevent locos from moving during OTA
|
||||||
|
ArduinoOTA.onStart([]() {
|
||||||
|
// Emergency stop all locos
|
||||||
|
DCC::setThrottle(0,1,1);
|
||||||
|
// Disable tracks power
|
||||||
|
TrackManager::setMainPower(POWERMODE::OFF);
|
||||||
|
TrackManager::setProgPower(POWERMODE::OFF);
|
||||||
|
// Broadcast power status
|
||||||
|
CommandDistributor::broadcastPower();
|
||||||
|
DISPLAY_START (
|
||||||
|
LCD(0,F("OTA update"));
|
||||||
|
LCD(1,F("In progress..."));
|
||||||
|
);
|
||||||
|
});
|
||||||
|
ArduinoOTA.onEnd([]() {
|
||||||
|
DISPLAY_START (
|
||||||
|
LCD(0,F("OTA update"));
|
||||||
|
LCD(1,F("Complete"));
|
||||||
|
);
|
||||||
|
});
|
||||||
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
|
DISPLAY_START (
|
||||||
|
LCD(0,F("OTA update"));
|
||||||
|
LCD(1,F("Error: %d"), error);
|
||||||
|
);
|
||||||
|
});
|
||||||
|
// Set OTA password if defined
|
||||||
|
#ifdef OTA_AUTH
|
||||||
|
ArduinoOTA.setPassword(OTA_AUTH);
|
||||||
|
#endif // OTA_AUTH
|
||||||
|
ArduinoOTA.begin();
|
||||||
|
otaInitialised = true;
|
||||||
|
}
|
||||||
|
// Handle OTA if initialised
|
||||||
|
else {
|
||||||
|
ArduinoOTA.handle();
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif //ARDUINO_ARCH_ESP32
|
#endif //ARDUINO_ARCH_ESP32
|
||||||
#if ETHERNET_ON
|
#if ETHERNET_ON
|
||||||
EthernetInterface::loop();
|
EthernetInterface::loop();
|
||||||
|
@ -1264,6 +1264,11 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
|
|||||||
IODevice::writeAnalogue(p[1], p[2], params>3 ? p[3] : 0);
|
IODevice::writeAnalogue(p[1], p[2], params>3 ? p[3] : 0);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case "OTA"_hk: // <D OTA ON/OFF>
|
||||||
|
Diag::OTA = onOff;
|
||||||
|
DIAG(F("OTA=%S"), onOff ? F("ON") : F("OFF"));
|
||||||
|
return true;
|
||||||
|
|
||||||
default: // invalid/unknown
|
default: // invalid/unknown
|
||||||
return parseC(stream, params, p);
|
return parseC(stream, params, p);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ bool Diag::WIFI=false;
|
|||||||
bool Diag::WITHROTTLE=false;
|
bool Diag::WITHROTTLE=false;
|
||||||
bool Diag::ETHERNET=false;
|
bool Diag::ETHERNET=false;
|
||||||
bool Diag::LCN=false;
|
bool Diag::LCN=false;
|
||||||
|
bool Diag::OTA=false;
|
||||||
|
|
||||||
|
|
||||||
void StringFormatter::diag( const FSH* input...) {
|
void StringFormatter::diag( const FSH* input...) {
|
||||||
|
@ -30,7 +30,7 @@ class Diag {
|
|||||||
static bool WITHROTTLE;
|
static bool WITHROTTLE;
|
||||||
static bool ETHERNET;
|
static bool ETHERNET;
|
||||||
static bool LCN;
|
static bool LCN;
|
||||||
|
static bool OTA;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringFormatter
|
class StringFormatter
|
||||||
|
@ -128,6 +128,21 @@ 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_AUTO_INIT: Set this to true if you want OTA updates to be initialized
|
||||||
|
// automatically upon startup. If set to false, OTA updates will remain
|
||||||
|
// unavailable until the "<C OTA 1>" command is executed.
|
||||||
|
// Please note that this feature requires the use of ARDUINO_ARCH_ESP32 as your board.
|
||||||
|
#define OTA_AUTO_INIT false
|
||||||
|
//
|
||||||
|
// OTA_AUTH: Set this to your desired password if you wish to secure OTA updates.
|
||||||
|
// If not set, OTA updates will be password-free.
|
||||||
|
// Note: Upon modifying the OTA password, ensure to update the "upload_flags → --auth"
|
||||||
|
// in the relevant environment within the platformio.ini file.
|
||||||
|
// To deactivate OTA authorization, comment out the line below and comment out
|
||||||
|
// the "upload_flags" line in the platformio.ini file.
|
||||||
|
// #define OTA_AUTH "dccex-ota"
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -193,6 +193,20 @@ 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 =
|
||||||
|
--timeout=10
|
||||||
|
--auth=dccex-ota
|
||||||
|
|
||||||
[env:Nucleo-F411RE]
|
[env:Nucleo-F411RE]
|
||||||
platform = ststm32 @ 17.6.0
|
platform = ststm32 @ 17.6.0
|
||||||
board = nucleo_f411re
|
board = nucleo_f411re
|
||||||
|
Loading…
x
Reference in New Issue
Block a user