mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
start syslog when network connected
This commit is contained in:
@@ -125,8 +125,7 @@ void MqttSettingsService::configureMqtt() {
|
|||||||
_mqttClient.disconnect();
|
_mqttClient.disconnect();
|
||||||
|
|
||||||
// only connect if WiFi is connected and MQTT is enabled
|
// only connect if WiFi is connected and MQTT is enabled
|
||||||
if (_state.enabled && (WiFi.isConnected() || ETH.linkUp())) {
|
if (_state.enabled && emsesp::EMSESP::system_.network_connected()) {
|
||||||
// Serial.println(F("Connecting to MQTT..."));
|
|
||||||
_mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
|
_mqttClient.setServer(retainCstr(_state.host.c_str(), &_retainedHost), _state.port);
|
||||||
if (_state.username.length() > 0) {
|
if (_state.username.length() > 0) {
|
||||||
_mqttClient.setCredentials(retainCstr(_state.username.c_str(), &_retainedUsername), retainCstr(_state.password.length() > 0 ? _state.password.c_str() : nullptr, &_retainedPassword));
|
_mqttClient.setCredentials(retainCstr(_state.username.c_str(), &_retainedUsername), retainCstr(_state.password.length() > 0 ? _state.password.c_str() : nullptr, &_retainedPassword));
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
#endif
|
#endif
|
||||||
EMSESP::system_.wifi_tweak();
|
EMSESP::system_.wifi_tweak();
|
||||||
EMSESP::system_.send_heartbeat();
|
EMSESP::system_.send_heartbeat();
|
||||||
|
EMSESP::system_.syslog_start();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYSTEM_EVENT_ETH_START:
|
case SYSTEM_EVENT_ETH_START:
|
||||||
@@ -55,6 +56,7 @@ void WebStatusService::WiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) {
|
|||||||
EMSESP::logger().info(F("Ethernet Connected with IP=%s, speed %d Mbps"), ETH.localIP().toString().c_str(), ETH.linkSpeed());
|
EMSESP::logger().info(F("Ethernet Connected with IP=%s, speed %d Mbps"), ETH.localIP().toString().c_str(), ETH.linkSpeed());
|
||||||
#endif
|
#endif
|
||||||
EMSESP::system_.send_heartbeat();
|
EMSESP::system_.send_heartbeat();
|
||||||
|
EMSESP::system_.syslog_start();
|
||||||
EMSESP::system_.ethernet_connected(true);
|
EMSESP::system_.ethernet_connected(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -611,7 +611,7 @@ void Mqtt::on_connect() {
|
|||||||
|
|
||||||
doc["version"] = EMSESP_APP_VERSION;
|
doc["version"] = EMSESP_APP_VERSION;
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
if (ETH.linkUp()) {
|
if (EMSESP::system_.ethernet_connected()) {
|
||||||
doc["ip"] = ETH.localIP().toString();
|
doc["ip"] = ETH.localIP().toString();
|
||||||
} else {
|
} else {
|
||||||
doc["ip"] = WiFi.localIP().toString();
|
doc["ip"] = WiFi.localIP().toString();
|
||||||
|
|||||||
@@ -119,19 +119,29 @@ void System::format(uuid::console::Shell & shell) {
|
|||||||
System::restart();
|
System::restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void System::syslog_start() {
|
||||||
|
if (syslog_enabled_) {
|
||||||
|
#ifndef EMSESP_STANDALONE
|
||||||
|
syslog_.start();
|
||||||
|
#endif
|
||||||
|
EMSESP::logger().info(F("Starting Syslog"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void System::syslog_init(bool refresh) {
|
void System::syslog_init(bool refresh) {
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
get_settings();
|
get_settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
// check for empty hostname
|
// check for empty or invalid hostname
|
||||||
IPAddress addr;
|
IPAddress addr;
|
||||||
if (!addr.fromString(syslog_host_.c_str())) {
|
if (!addr.fromString(syslog_host_.c_str())) {
|
||||||
syslog_enabled_ = false;
|
syslog_enabled_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// in case service is still running, this flushes the queue - https://github.com/emsesp/EMS-ESP/issues/496
|
// in case service is still running, this flushes the queue
|
||||||
|
// https://github.com/emsesp/EMS-ESP/issues/496
|
||||||
if (!syslog_enabled_) {
|
if (!syslog_enabled_) {
|
||||||
syslog_.log_level((uuid::log::Level)-1);
|
syslog_.log_level((uuid::log::Level)-1);
|
||||||
syslog_.mark_interval(0);
|
syslog_.mark_interval(0);
|
||||||
@@ -140,13 +150,10 @@ void System::syslog_init(bool refresh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start & configure syslog
|
// start & configure syslog
|
||||||
syslog_.start();
|
|
||||||
syslog_.log_level((uuid::log::Level)syslog_level_);
|
syslog_.log_level((uuid::log::Level)syslog_level_);
|
||||||
syslog_.mark_interval(syslog_mark_interval_);
|
syslog_.mark_interval(syslog_mark_interval_);
|
||||||
syslog_.destination(addr, syslog_port_);
|
syslog_.destination(addr, syslog_port_);
|
||||||
syslog_.hostname(hostname_.c_str());
|
syslog_.hostname(hostname().c_str());
|
||||||
|
|
||||||
EMSESP::logger().info(F("Syslog started"));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +236,7 @@ void System::start(uint32_t heap_start) {
|
|||||||
get_settings();
|
get_settings();
|
||||||
|
|
||||||
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
|
||||||
hostname(networkSettings.hostname.c_str());
|
hostname(networkSettings.hostname.c_str()); // sets the hostname
|
||||||
LOG_INFO(F("System %s booted (EMS-ESP version %s) "), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message
|
LOG_INFO(F("System %s booted (EMS-ESP version %s) "), networkSettings.hostname.c_str(), EMSESP_APP_VERSION); // print boot message
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -238,7 +245,7 @@ void System::start(uint32_t heap_start) {
|
|||||||
adc_init(false); // analog ADC
|
adc_init(false); // analog ADC
|
||||||
button_init(false); // the special button
|
button_init(false); // the special button
|
||||||
network_init(false); // network
|
network_init(false); // network
|
||||||
syslog_init(false); // init SysLog, must start after network
|
syslog_init(false); // init SysLog
|
||||||
|
|
||||||
EMSESP::init_uart(); // start UART
|
EMSESP::init_uart(); // start UART
|
||||||
}
|
}
|
||||||
@@ -484,7 +491,7 @@ void System::network_init(bool refresh) {
|
|||||||
eth_clock_mode_t clock_mode; // ETH_CLOCK_GPIO0_IN or ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT for 50Hz inverted clock
|
eth_clock_mode_t clock_mode; // ETH_CLOCK_GPIO0_IN or ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT for 50Hz inverted clock
|
||||||
|
|
||||||
if (board_profile_.equals("E32") || board_profile_.equals("LAN8720")) {
|
if (board_profile_.equals("E32") || board_profile_.equals("LAN8720")) {
|
||||||
// Gateway E32 (LAN8720)
|
// BBQKees Gateway E32 (LAN8720)
|
||||||
phy_addr = 1;
|
phy_addr = 1;
|
||||||
power = 16;
|
power = 16;
|
||||||
mdc = 23;
|
mdc = 23;
|
||||||
|
|||||||
29
src/system.h
29
src/system.h
@@ -66,6 +66,9 @@ class System {
|
|||||||
void show_mem(const char * note);
|
void show_mem(const char * note);
|
||||||
void get_settings();
|
void get_settings();
|
||||||
void wifi_tweak();
|
void wifi_tweak();
|
||||||
|
void syslog_start();
|
||||||
|
bool check_upgrade();
|
||||||
|
void send_heartbeat();
|
||||||
|
|
||||||
void led_init(bool refresh);
|
void led_init(bool refresh);
|
||||||
void syslog_init(bool refresh);
|
void syslog_init(bool refresh);
|
||||||
@@ -75,12 +78,8 @@ class System {
|
|||||||
void commands_init();
|
void commands_init();
|
||||||
|
|
||||||
static bool is_valid_gpio(uint8_t pin);
|
static bool is_valid_gpio(uint8_t pin);
|
||||||
|
|
||||||
static bool load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile);
|
static bool load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile);
|
||||||
|
|
||||||
bool check_upgrade();
|
|
||||||
void send_heartbeat();
|
|
||||||
|
|
||||||
std::string hostname() {
|
std::string hostname() {
|
||||||
return hostname_;
|
return hostname_;
|
||||||
}
|
}
|
||||||
@@ -97,6 +96,14 @@ class System {
|
|||||||
ethernet_connected_ = b;
|
ethernet_connected_ = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool network_connected() {
|
||||||
|
#ifndef EMSESP_STANDALONE
|
||||||
|
return (ethernet_connected_ || WiFi.isConnected());
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uuid::log::Logger logger_;
|
static uuid::log::Logger logger_;
|
||||||
static uint32_t heap_start_;
|
static uint32_t heap_start_;
|
||||||
@@ -133,16 +140,16 @@ class System {
|
|||||||
void wifi_reconnect();
|
void wifi_reconnect();
|
||||||
int8_t wifi_quality();
|
int8_t wifi_quality();
|
||||||
|
|
||||||
bool system_healthy_ = false;
|
bool system_healthy_ = false;
|
||||||
uint32_t led_flash_speed_ = LED_WARNING_BLINK_FAST; // default boot flashes quickly
|
uint32_t led_flash_speed_ = LED_WARNING_BLINK_FAST; // default boot flashes quickly
|
||||||
uint32_t last_heartbeat_ = 0;
|
uint32_t last_heartbeat_ = 0;
|
||||||
uint32_t last_system_check_ = 0;
|
uint32_t last_system_check_ = 0;
|
||||||
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
bool upload_status_ = false; // true if we're in the middle of a OTA firmware upload
|
||||||
bool ethernet_connected_;
|
bool ethernet_connected_ = false;
|
||||||
uint16_t analog_;
|
uint16_t analog_;
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
std::string hostname_;
|
std::string hostname_ = "ems-esp";
|
||||||
bool hide_led_;
|
bool hide_led_;
|
||||||
uint8_t led_gpio_;
|
uint8_t led_gpio_;
|
||||||
bool syslog_enabled_;
|
bool syslog_enabled_;
|
||||||
|
|||||||
Reference in New Issue
Block a user