tidy up sequence of services, start log and serial console first, catch any board profile errors first

This commit is contained in:
proddy
2022-02-06 15:48:57 +01:00
parent ddee63b718
commit 81d54ca69f
11 changed files with 136 additions and 216 deletions

View File

@@ -54,10 +54,6 @@ void EMSESPShell::stopped() {
logger().log(LogLevel::DEBUG, LogFacility::AUTH, F("su session closed on console %s"), console_name().c_str());
}
logger().log(LogLevel::DEBUG, LogFacility::CONSOLE, F("User session closed on console %s"), console_name().c_str());
// remove all custom contexts
// commands->remove_all_commands();
// console_commands_loaded_ = false; // make sure they get reloaded next time a console is opened
}
// show welcome banner
@@ -77,8 +73,6 @@ void EMSESPShell::display_banner() {
if (console_hostname_.empty()) {
console_hostname_ = "ems-esp";
// console_hostname_.resize(16, '\0');
// snprintf(&console_hostname_[0], console_hostname_.capacity() + 1, "ems-esp");
}
// load the list of commands
@@ -465,31 +459,6 @@ std::string EMSESPShell::hostname_text() {
return console_hostname_;
}
/*
// remove commands from the current context to save memory before exiting
bool EMSESPShell::exit_context() {
unsigned int current_context = context();
if (current_context == ShellContext::MAIN) {
Shell::stop();
return true;
}
// commands->remove_context_commands(current_context);
// return Shell::exit_context();
return false;
}
// enter a custom context (sub-menu)
void Console::enter_custom_context(Shell & shell, unsigned int context) {
// load_standard_commands(context);
// don't go into the new context if it's already the root (to prevent double loading)
if (context != ShellContext::MAIN) {
shell.enter_context(context);
}
}
*/
// each custom context has the common commands like log, help, exit, su etc
void Console::load_standard_commands(unsigned int context) {
#if defined(EMSESP_DEBUG)
@@ -771,22 +740,6 @@ void Console::load_system_commands(unsigned int context) {
});
}
/*
// prompt, change per context
std::string EMSESPShell::context_text() {
switch (static_cast<ShellContext>(context())) {
case ShellContext::MAIN:
return std::string{'/'};
case ShellContext::SYSTEM:
return std::string{"/system"};
default:
return std::string{};
}
}
*/
// when in su (admin) show # as the prompt suffix
std::string EMSESPShell::prompt_suffix() {
if (has_flags(CommandFlags::ADMIN)) {
@@ -848,12 +801,11 @@ std::string EMSESPStreamConsole::console_name() {
return name_;
}
// Start up telnet and logging
// Log order is off, err, warning, notice, info, debug, trace, all
void Console::start(bool telnet_enabled) {
telnet_enabled_ = telnet_enabled;
// Start serial console
void Console::start_serial() {
Serial.begin(115200);
// Serial Console
// Serial Console - is always active
shell = std::make_shared<EMSESPStreamConsole>(Serial, true);
shell->maximum_log_messages(100);
shell->start();
@@ -865,20 +817,20 @@ void Console::start(bool telnet_enabled) {
#if defined(EMSESP_STANDALONE)
shell->add_flags(CommandFlags::ADMIN); // always start in su/admin mode when running tests
#endif
}
// Start up telnet
void Console::start_telnet() {
telnet_enabled_ = true; // telnet is enabled when calling this function
// start the telnet service
// default idle is 10 minutes, default write timeout is 0 (automatic)
// note, this must be started after the network/wifi for ESP32 otherwise it'll crash
#ifndef EMSESP_STANDALONE
if (telnet_enabled) {
telnet_.start();
telnet_.initial_idle_timeout(3600); // in sec, one hour idle timeout
telnet_.default_write_timeout(1000); // in ms, socket timeout 1 second
}
telnet_.start();
telnet_.initial_idle_timeout(3600); // in sec, one hour idle timeout
telnet_.default_write_timeout(1000); // in ms, socket timeout 1 second
#endif
// turn watch off in case it was still set in the last session
// EMSESP::watch(EMSESP::WATCH_OFF);
}
// handles telnet sync and logging to console

View File

@@ -99,8 +99,6 @@ class EMSESPShell : virtual public uuid::console::Shell {
std::string prompt_suffix() override;
void end_of_transmission() override;
// std::string context_text() override;
// bool exit_context() override;
private:
void add_console_commands();
@@ -128,16 +126,16 @@ class EMSESPStreamConsole : public uuid::console::StreamConsole, public EMSESPSh
class Console {
public:
void loop();
void start(bool telnet_enabled = true);
void start_serial();
void start_telnet();
uuid::log::Level log_level();
// static void enter_custom_context(Shell & shell, unsigned int context);
static void load_standard_commands(unsigned int context);
static void load_system_commands(unsigned int context);
private:
bool telnet_enabled_;
bool telnet_enabled_ = false; // telnet is default off
};
} // namespace emsesp

View File

@@ -93,7 +93,7 @@
#endif
#ifndef EMSESP_DEFAULT_BOARD_PROFILE
#define EMSESP_DEFAULT_BOARD_PROFILE "S32" // Gateway S32
#define EMSESP_DEFAULT_BOARD_PROFILE "default"
#endif
// Default GPIO PIN definitions

View File

@@ -20,12 +20,6 @@
namespace emsesp {
#if defined(EMSESP_STANDALONE)
uint32_t heap_start = 0;
#else
uint32_t heap_start = ESP.getFreeHeap(); // get initial available heap memory
#endif
AsyncWebServer webServer(80);
#if defined(EMSESP_STANDALONE)
@@ -233,7 +227,7 @@ void EMSESP::watch_id(uint16_t watch_id) {
// resets all counters and bumps the UART
// this is called when the tx_mode is persisted in the FS either via Web UI or the console
void EMSESP::init_uart() {
void EMSESP::uart_init() {
uint8_t tx_mode;
uint8_t rx_gpio;
uint8_t tx_gpio;
@@ -1369,7 +1363,7 @@ void EMSESP::send_raw_telegram(const char * data) {
// start all the core services
// the services must be loaded in the correct order
void EMSESP::start() {
Serial.begin(115200);
console_.start_serial();
// start the file system
#ifndef EMSESP_STANDALONE
@@ -1379,38 +1373,41 @@ void EMSESP::start() {
}
#endif
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
system_.check_upgrade(); // do any system upgrades
webSettingsService.begin(); // load EMS-ESP Application settings...
system_.get_settings(); // ...and store some of the settings locally for future reference
console_.start(system_.telnet_enabled()); // telnet and serial console, from here we can start logging events
webLogService.start(); // start web log service
webCustomizationService.begin(); // load the customizations
// welcome message
LOG_INFO(F("Starting EMS-ESP version %s (hostname: %s)"), EMSESP_APP_VERSION, system_.hostname().c_str());
LOG_INFO(F("Configuring for interface board profile %s"), system_.board_profile().c_str());
// start all the EMS-ESP services
mqtt_.start(); // mqtt init
system_.start(heap_start); // starts commands, led, adc, button, network, syslog & uart
shower_.start(); // initialize shower timer and shower alert
dallassensor_.start(); // Dallas external sensors
analogsensor_.start(); // Analog external sensors
webServer.begin(); // start the web server
// emsdevices.reserve(5); // reserve space for initially 5 devices to avoid mem frag issues
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
LOG_INFO(F("Starting EMS-ESP version %s (hostname: %s)"), EMSESP_APP_VERSION, system_.hostname().c_str()); // welcome message
LOG_INFO(F("Last system reset reason Core0: %s, Core1: %s"), system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
// Load our library of known devices into stack mem. Names are stored in Flash memory (takes up about 1kb)
webSettingsService.begin(); // load EMS-ESP Application settings...
system_.reload_settings(); // ... and store some of the settings locally
webCustomizationService.begin(); // load the customizations
// start telnet service if it's enabled
if (system_.telnet_enabled()) {
console_.start_telnet();
}
system_.check_upgrade(); // do any system upgrades
// start all the EMS-ESP services
mqtt_.start(); // mqtt init
system_.start(); // starts commands, led, adc, button, network, syslog & uart
shower_.start(); // initialize shower timer and shower alert
dallassensor_.start(); // Dallas external sensors
analogsensor_.start(); // Analog external sensors
webLogService.start(); // apply settings to weblog service
// Load our library of known devices into stack mem. Names are stored in Flash memory
device_library_ = {
#include "device_library.h"
};
LOG_INFO(F("EMS device library loaded with %d records"), device_library_.size());
LOG_INFO(F("Loaded EMS device library (%d records)"), device_library_.size());
#if defined(EMSESP_STANDALONE)
Mqtt::on_connect(); // simulate an MQTT connection
#endif
webServer.begin(); // start the web server
}
// main loop calling all services

View File

@@ -145,7 +145,7 @@ class EMSESP {
static void show_devices(uuid::console::Shell & shell);
static void show_ems(uuid::console::Shell & shell);
static void init_uart();
static void uart_init();
static void incoming_telegram(uint8_t * data, const uint8_t length);

View File

@@ -48,9 +48,8 @@ uuid::syslog::SyslogService System::syslog_;
#endif
// init statics
uint32_t System::heap_start_ = 1; // avoid using 0 to divide-by-zero later
PButton System::myPButton_;
bool System::restart_requested_ = false;
PButton System::myPButton_;
bool System::restart_requested_ = false;
// send on/off to a gpio pin
// value: true = HIGH, false = LOW
@@ -169,7 +168,7 @@ bool System::command_syslog_level(const char * value, const int8_t id) {
return StateUpdateResult::CHANGED;
},
"local");
EMSESP::system_.syslog_start();
EMSESP::system_.syslog_init();
return true;
}
return false;
@@ -240,7 +239,7 @@ void System::format(uuid::console::Shell & shell) {
System::system_restart();
}
void System::syslog_start() {
void System::syslog_init() {
bool was_enabled = syslog_enabled_;
EMSESP::webSettingsService.read([&](WebSettings & settings) {
syslog_enabled_ = settings.syslog_enabled;
@@ -287,7 +286,7 @@ void System::syslog_start() {
}
// read some specific system settings to store locally for faster access
void System::get_settings() {
void System::reload_settings() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
pbutton_gpio_ = settings.pbutton_gpio;
analog_enabled_ = settings.analog_enabled;
@@ -360,20 +359,8 @@ bool System::is_valid_gpio(uint8_t pin) {
return true;
}
// first call. Sets memory and starts up the UART Serial bridge
void System::start(uint32_t heap_start) {
#if defined(EMSESP_DEBUG)
show_mem("Startup");
#endif
// set the inital free mem, only on first boot
if (heap_start_ < 2) {
heap_start_ = heap_start;
}
// load in all the settings first
get_settings();
// Starts up the UART Serial bridge
void System::start() {
#ifndef EMSESP_STANDALONE
// disable bluetooth module
// periph_module_disable(PERIPH_BT_MODULE);
@@ -390,9 +377,9 @@ void System::start(uint32_t heap_start) {
led_init(false); // init LED
button_init(false); // the special button
network_init(false); // network
syslog_start(); // start Syslog
syslog_init(); // start Syslog
EMSESP::init_uart(); // start UART
EMSESP::uart_init(); // start UART
}
// button single click
@@ -429,7 +416,7 @@ void System::button_OnVLongPress(PButton & b) {
// push button
void System::button_init(bool refresh) {
if (refresh) {
get_settings();
reload_settings();
}
if (is_valid_gpio(pbutton_gpio_)) {
@@ -451,7 +438,7 @@ void System::button_init(bool refresh) {
// set the LED to on or off when in normal operating mode
void System::led_init(bool refresh) {
if (refresh) {
get_settings();
reload_settings();
}
if ((led_gpio_ != 0) && is_valid_gpio(led_gpio_)) {
@@ -517,15 +504,6 @@ void System::loop() {
#endif
}
void System::show_mem(const char * note) {
#ifndef EMSESP_STANDALONE
static uint32_t old_free_heap = 0;
uint32_t free_heap = ESP.getFreeHeap();
LOG_INFO(F("(%s) Free heap: %lu (~%lu)"), note, free_heap, (uint32_t)Helpers::abs(free_heap - old_free_heap));
old_free_heap = free_heap;
#endif
}
// create the json for heartbeat
bool System::heartbeat_json(JsonObject & output) {
uint8_t bus_status = EMSESP::bus_status();
@@ -590,7 +568,7 @@ void System::send_heartbeat() {
// initializes network
void System::network_init(bool refresh) {
if (refresh) {
get_settings();
reload_settings();
}
last_system_check_ = 0; // force the LED to go from fast flash to pulse
@@ -785,80 +763,82 @@ void System::show_users(uuid::console::Shell & shell) {
}
void System::show_system(uuid::console::Shell & shell) {
shell.printfln(F("Uptime: %s"), uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str());
shell.println("System:");
shell.printfln(F(" Board profile: %s"), board_profile().c_str());
shell.printfln(F(" Uptime: %s"), uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3).c_str());
#ifndef EMSESP_STANDALONE
shell.printfln(F("SDK version: %s"), ESP.getSdkVersion());
shell.printfln(F("CPU frequency: %lu MHz"), ESP.getCpuFreqMHz());
shell.printfln(F("Free heap: %lu bytes"), (uint32_t)ESP.getFreeHeap());
shell.printfln(F(" SDK version: %s"), ESP.getSdkVersion());
shell.printfln(F(" CPU frequency: %lu MHz"), ESP.getCpuFreqMHz());
shell.printfln(F(" Free heap: %lu bytes"), (uint32_t)ESP.getFreeHeap());
shell.println();
shell.println("Network:");
switch (WiFi.status()) {
case WL_IDLE_STATUS:
shell.printfln(F("Network: Idle"));
shell.printfln(F(" Network: Idle"));
break;
case WL_NO_SSID_AVAIL:
shell.printfln(F("Network: Network not found"));
shell.printfln(F(" Network: Network not found"));
break;
case WL_SCAN_COMPLETED:
shell.printfln(F("Network: Network scan complete"));
shell.printfln(F(" Network: Network scan complete"));
break;
case WL_CONNECTED:
shell.printfln(F("Network: connected"));
shell.printfln(F("SSID: %s"), WiFi.SSID().c_str());
shell.printfln(F("BSSID: %s"), WiFi.BSSIDstr().c_str());
shell.printfln(F("RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality(WiFi.RSSI()));
shell.printfln(F("MAC address: %s"), WiFi.macAddress().c_str());
shell.printfln(F("Hostname: %s"), WiFi.getHostname());
shell.printfln(F("IPv4 address: %s/%s"), uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
shell.printfln(F("IPv4 gateway: %s"), uuid::printable_to_string(WiFi.gatewayIP()).c_str());
shell.printfln(F("IPv4 nameserver: %s"), uuid::printable_to_string(WiFi.dnsIP()).c_str());
shell.printfln(F(" Network: connected"));
shell.printfln(F(" SSID: %s"), WiFi.SSID().c_str());
shell.printfln(F(" BSSID: %s"), WiFi.BSSIDstr().c_str());
shell.printfln(F(" RSSI: %d dBm (%d %%)"), WiFi.RSSI(), wifi_quality(WiFi.RSSI()));
shell.printfln(F(" MAC address: %s"), WiFi.macAddress().c_str());
shell.printfln(F(" Hostname: %s"), WiFi.getHostname());
shell.printfln(F(" IPv4 address: %s/%s"), uuid::printable_to_string(WiFi.localIP()).c_str(), uuid::printable_to_string(WiFi.subnetMask()).c_str());
shell.printfln(F(" IPv4 gateway: %s"), uuid::printable_to_string(WiFi.gatewayIP()).c_str());
shell.printfln(F(" IPv4 nameserver: %s"), uuid::printable_to_string(WiFi.dnsIP()).c_str());
if (WiFi.localIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000") {
shell.printfln(F("IPv6 address: %s"), uuid::printable_to_string(WiFi.localIPv6()).c_str());
shell.printfln(F(" IPv6 address: %s"), uuid::printable_to_string(WiFi.localIPv6()).c_str());
}
break;
case WL_CONNECT_FAILED:
shell.printfln(F("WiFi Network: Connection failed"));
shell.printfln(F(" WiFi Network: Connection failed"));
break;
case WL_CONNECTION_LOST:
shell.printfln(F("WiFi Network: Connection lost"));
shell.printfln(F(" WiFi Network: Connection lost"));
break;
case WL_DISCONNECTED:
shell.printfln(F("WiFi Network: Disconnected"));
shell.printfln(F(" WiFi Network: Disconnected"));
break;
case WL_NO_SHIELD:
default:
shell.printfln(F("WiFi Network: Unknown"));
shell.printfln(F(" WiFi Network: Unknown"));
break;
}
shell.println();
// show Ethernet if connected
if (ethernet_connected_) {
shell.printfln(F("Wired Network: connected"));
shell.printfln(F("MAC address: %s"), ETH.macAddress().c_str());
shell.printfln(F("Hostname: %s"), ETH.getHostname());
shell.printfln(F("IPv4 address: %s/%s"), uuid::printable_to_string(ETH.localIP()).c_str(), uuid::printable_to_string(ETH.subnetMask()).c_str());
shell.printfln(F("IPv4 gateway: %s"), uuid::printable_to_string(ETH.gatewayIP()).c_str());
shell.printfln(F("IPv4 nameserver: %s"), uuid::printable_to_string(ETH.dnsIP()).c_str());
shell.println();
shell.printfln(F(" Wired Network: connected"));
shell.printfln(F(" MAC address: %s"), ETH.macAddress().c_str());
shell.printfln(F(" Hostname: %s"), ETH.getHostname());
shell.printfln(F(" IPv4 address: %s/%s"), uuid::printable_to_string(ETH.localIP()).c_str(), uuid::printable_to_string(ETH.subnetMask()).c_str());
shell.printfln(F(" IPv4 gateway: %s"), uuid::printable_to_string(ETH.gatewayIP()).c_str());
shell.printfln(F(" IPv4 nameserver: %s"), uuid::printable_to_string(ETH.dnsIP()).c_str());
if (ETH.localIPv6().toString() != "0000:0000:0000:0000:0000:0000:0000:0000") {
shell.printfln(F("IPv6 address: %s"), uuid::printable_to_string(ETH.localIPv6()).c_str());
shell.printfln(F(" IPv6 address: %s"), uuid::printable_to_string(ETH.localIPv6()).c_str());
}
}
shell.println();
shell.println("Syslog:");
if (!syslog_enabled_) {
shell.printfln(F("Syslog: disabled"));
shell.printfln(F(" Syslog: disabled"));
} else {
shell.printfln(F("Syslog: %s"), syslog_.started() ? "started" : "stopped");
shell.printfln(F(" Syslog: %s"), syslog_.started() ? "started" : "stopped");
shell.print(F(" "));
shell.printfln(F_(host_fmt), !syslog_host_.isEmpty() ? syslog_host_.c_str() : read_flash_string(F_(unset)).c_str());
shell.printfln(F(" IP: %s"), uuid::printable_to_string(syslog_.ip()).c_str());
@@ -1207,15 +1187,15 @@ bool System::command_test(const char * value, const int8_t id) {
#endif
// takes a board profile and populates a data array with GPIO configurations
// returns false if profile is not found
// returns false if profile is unknown
//
// data = led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
//
// clock modes:
// ETH_CLOCK_GPIO0_IN = 0 RMII clock input to GPIO0
// ETH_CLOCK_GPIO0_OUT = 1 RMII clock output from GPIO0
// ETH_CLOCK_GPIO16_OUT = 2 RMII clock output from GPIO16
// ETH_CLOCK_GPIO17_OUT = 3 RMII clock output from GPIO17, for 50hz inverted cloc
// 0 = RMII clock input to GPIO0
// 1 = RMII clock output from GPIO0
// 2 = RMII clock output from GPIO16
// 3 = RMII clock output from GPIO17, for 50hz inverted clock
bool System::load_board_profile(std::vector<int8_t> & data, const std::string & board_profile) {
if (board_profile == "S32") {
data = {2, 18, 23, 5, 0, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // BBQKees Gateway S32
@@ -1243,7 +1223,7 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
(int8_t)EMSESP::system_.eth_phy_addr_,
(int8_t)EMSESP::system_.eth_clock_mode_};
} else {
// unknown, use defaults
// unknown, use defaults and return false
data = {
EMSESP_DEFAULT_LED_GPIO,
EMSESP_DEFAULT_DALLAS_GPIO,

View File

@@ -45,7 +45,7 @@ enum PHY_type : uint8_t { PHY_TYPE_NONE = 0, PHY_TYPE_LAN8720, PHY_TYPE_TLK110 }
class System {
public:
void start(uint32_t heap_start);
void start();
void loop();
// commands
@@ -72,9 +72,9 @@ class System {
void upload_status(bool in_progress);
bool upload_status();
void show_mem(const char * note);
void get_settings();
void reload_settings();
void wifi_tweak();
void syslog_start();
void syslog_init();
bool check_upgrade();
bool heartbeat_json(JsonObject & output);
void send_heartbeat();
@@ -180,7 +180,6 @@ class System {
private:
static uuid::log::Logger logger_;
static uint32_t heap_start_;
static bool restart_requested_;
// button
@@ -220,7 +219,7 @@ class System {
bool ethernet_connected_ = false;
// EMS-ESP settings
// copies from WebSettings class in WebSettingsService.h
// copies from WebSettings class in WebSettingsService.h and loaded with reload_settings()
std::string hostname_ = FACTORY_WIFI_HOSTNAME;
bool hide_led_;
uint8_t led_gpio_;

View File

@@ -45,7 +45,12 @@ void WebLogService::forbidden(AsyncWebServerRequest * request) {
request->send(403);
}
// start event source service
// start the log service with INFO level
void WebLogService::begin() {
uuid::log::Logger::register_handler(this, uuid::log::Level::INFO);
}
// apply the user settings
void WebLogService::start() {
EMSESP::webSettingsService.read([&](WebSettings & settings) {
maximum_log_messages_ = settings.weblog_buffer;
@@ -105,14 +110,6 @@ WebLogService::QueuedLogMessage::QueuedLogMessage(unsigned long id, std::shared_
}
void WebLogService::operator<<(std::shared_ptr<uuid::log::Message> message) {
/*
// special case for trace, show trace and notice messages only
// added by mvdp
if (log_level() == uuid::log::Level::TRACE && message->level != uuid::log::Level::TRACE && message->level != uuid::log::Level::NOTICE) {
return;
}
*/
if (log_messages_.size() >= maximum_log_messages_) {
log_messages_.pop_front();
}

View File

@@ -32,6 +32,7 @@ class WebLogService : public uuid::log::Handler {
WebLogService(AsyncWebServer * server, SecurityManager * securityManager);
void begin();
void start();
uuid::log::Level log_level() const;
void log_level(uuid::log::Level level);

View File

@@ -78,10 +78,12 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) {
// load default GPIO configuration based on board profile
std::vector<int8_t> data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE;
if (!System::load_board_profile(data, settings.board_profile.c_str())) {
settings.board_profile = EMSESP_DEFAULT_BOARD_PROFILE; // invalid board configuration, override the default in case it has been misspelled
settings.board_profile = "CUSTOM";
EMSESP::logger().info("No board profile found. Re-setting to %s", settings.board_profile.c_str());
} else {
EMSESP::logger().info("Loading board profile %s", settings.board_profile.c_str());
}
uint8_t default_led_gpio = data[0];
@@ -112,15 +114,12 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
prev = settings.syslog_enabled;
settings.syslog_enabled = root["syslog_enabled"] | EMSESP_DEFAULT_SYSLOG_ENABLED;
check_flag(prev, settings.syslog_enabled, ChangeFlags::SYSLOG);
prev = settings.syslog_level;
settings.syslog_level = root["syslog_level"] | EMSESP_DEFAULT_SYSLOG_LEVEL;
check_flag(prev, settings.syslog_level, ChangeFlags::SYSLOG);
prev = settings.syslog_mark_interval;
settings.syslog_mark_interval = root["syslog_mark_interval"] | EMSESP_DEFAULT_SYSLOG_MARK_INTERVAL;
check_flag(prev, settings.syslog_mark_interval, ChangeFlags::SYSLOG);
prev = settings.syslog_port;
settings.syslog_port = root["syslog_port"] | EMSESP_DEFAULT_SYSLOG_PORT;
check_flag(prev, settings.syslog_port, ChangeFlags::SYSLOG);
@@ -167,8 +166,22 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.analog_enabled = root["analog_enabled"] | EMSESP_DEFAULT_ANALOG_ENABLED;
check_flag(prev, settings.analog_enabled, ChangeFlags::ADC);
// ethernet
prev = settings.phy_type;
settings.phy_type = root["phy_type"] | default_phy_type;
check_flag(prev, settings.phy_type, ChangeFlags::RESTART);
prev = settings.eth_power;
settings.eth_power = root["eth_power"] | default_eth_power;
check_flag(prev, settings.eth_power, ChangeFlags::RESTART);
prev = settings.eth_phy_addr;
settings.eth_phy_addr = root["eth_phy_addr"] | default_eth_phy_addr;
check_flag(prev, settings.eth_phy_addr, ChangeFlags::RESTART);
prev = settings.eth_clock_mode;
settings.eth_clock_mode = root["eth_clock_mode"] | default_eth_clock_mode;
check_flag(prev, settings.eth_clock_mode, ChangeFlags::RESTART);
//
// these need reboots to be applied...
// these need system restarts first before settings are activated...
//
prev = settings.telnet_enabled;
settings.telnet_enabled = root["telnet_enabled"] | EMSESP_DEFAULT_TELNET_ENABLED;
@@ -186,25 +199,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.master_thermostat = root["master_thermostat"] | EMSESP_DEFAULT_MASTER_THERMOSTAT;
check_flag(prev, settings.master_thermostat, ChangeFlags::RESTART);
// use whatever came from the board profile
prev = settings.phy_type;
settings.phy_type = root["phy_type"] | default_phy_type;
check_flag(prev, settings.phy_type, ChangeFlags::RESTART);
prev = settings.eth_power;
settings.eth_power = root["eth_power"] | default_eth_power;
check_flag(prev, settings.eth_power, ChangeFlags::RESTART);
prev = settings.eth_phy_addr;
settings.eth_phy_addr = root["eth_phy_addr"] | default_eth_phy_addr;
check_flag(prev, settings.eth_phy_addr, ChangeFlags::RESTART);
prev = settings.eth_clock_mode;
settings.eth_clock_mode = root["eth_clock_mode"] | default_eth_clock_mode;
check_flag(prev, settings.eth_clock_mode, ChangeFlags::RESTART);
//
// without checks...
//
settings.trace_raw = root["trace_raw"] | EMSESP_DEFAULT_TRACELOG_RAW;
EMSESP::trace_raw(settings.trace_raw);
@@ -231,7 +228,6 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
if (flags_ == WebSettings::ChangeFlags::RESTART) {
return StateUpdateResult::CHANGED_RESTART; // tell WebUI that a restart is needed
}
return StateUpdateResult::CHANGED;
}
@@ -247,11 +243,11 @@ void WebSettingsService::onUpdate() {
}
if (WebSettings::has_flags(WebSettings::ChangeFlags::UART)) {
EMSESP::init_uart();
EMSESP::uart_init();
}
if (WebSettings::has_flags(WebSettings::ChangeFlags::SYSLOG)) {
EMSESP::system_.syslog_start(); // re-start (or stop)
EMSESP::system_.syslog_init(); // re-start (or stop)
}
if (WebSettings::has_flags(WebSettings::ChangeFlags::ADC)) {

View File

@@ -45,7 +45,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_start();
EMSESP::system_.syslog_init();
}
});
mDNS_start();
@@ -73,7 +73,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (!networkSettings.enableIPv6) {
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_start();
EMSESP::system_.syslog_init();
}
});
EMSESP::system_.ethernet_connected(true);
@@ -115,7 +115,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
EMSESP::logger().info(F("WiFi connected with IP=%s, hostname=%s"), WiFi.localIPv6().toString().c_str(), WiFi.getHostname());
}
EMSESP::system_.send_heartbeat();
EMSESP::system_.syslog_start();
EMSESP::system_.syslog_init();
mDNS_start();
break;
#endif