fix flashing led on ethernet connection

This commit is contained in:
proddy
2021-03-27 16:19:12 +01:00
parent e34620e1e8
commit fca458687e

View File

@@ -511,26 +511,8 @@ void System::network_init(bool refresh) {
return; // invalid combi return; // invalid combi
} }
bool have_ethernet = ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode); // bool have_ethernet = ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode);
(void)ETH.begin(phy_addr, power, mdc, mdio, type, clock_mode);
// disable ssid and AP when using Ethernet
if (have_ethernet) {
#ifndef EMSESP_STANDALONE
EMSESP::esp8266React.getNetworkSettingsService()->update(
[&](NetworkSettings & settings) {
settings.ssid == ""; // remove SSID
return StateUpdateResult::CHANGED;
},
"local");
EMSESP::esp8266React.getAPSettingsService()->update(
[&](APSettings & settings) {
settings.provisionMode = AP_MODE_NEVER;
return StateUpdateResult::CHANGED;
},
"local");
#endif
}
} }
// check health of system, done every few seconds // check health of system, done every few seconds
@@ -539,7 +521,7 @@ void System::system_check() {
last_system_check_ = uuid::get_uptime(); last_system_check_ = uuid::get_uptime();
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
if (WiFi.status() != WL_CONNECTED) { if (!ethernet_connected() && (WiFi.status() != WL_CONNECTED)) {
set_led_speed(LED_WARNING_BLINK_FAST); set_led_speed(LED_WARNING_BLINK_FAST);
system_healthy_ = false; system_healthy_ = false;
return; return;
@@ -876,8 +858,13 @@ bool System::check_upgrade() {
// e.g. http://ems-esp/api?device=system&cmd=settings // e.g. http://ems-esp/api?device=system&cmd=settings
// value and id are ignored // value and id are ignored
bool System::command_settings(const char * value, const int8_t id, JsonObject & json) { bool System::command_settings(const char * value, const int8_t id, JsonObject & json) {
JsonObject node;
node = json.createNestedObject("System");
node["version"] = EMSESP_APP_VERSION;
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) { EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & settings) {
JsonObject node = json.createNestedObject("WIFI"); node = json.createNestedObject("WIFI");
node["ssid"] = settings.ssid; node["ssid"] = settings.ssid;
node["hostname"] = settings.hostname; node["hostname"] = settings.hostname;
node["static_ip_config"] = settings.staticIPConfig; node["static_ip_config"] = settings.staticIPConfig;
@@ -890,7 +877,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
EMSESP::esp8266React.getAPSettingsService()->read([&](APSettings & settings) { EMSESP::esp8266React.getAPSettingsService()->read([&](APSettings & settings) {
JsonObject node = json.createNestedObject("AP"); node = json.createNestedObject("AP");
node["provision_mode"] = settings.provisionMode; node["provision_mode"] = settings.provisionMode;
node["ssid"] = settings.ssid; node["ssid"] = settings.ssid;
node["local_ip"] = settings.localIP.toString(); node["local_ip"] = settings.localIP.toString();
@@ -900,7 +887,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
#endif #endif
EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & settings) { EMSESP::esp8266React.getMqttSettingsService()->read([&](MqttSettings & settings) {
JsonObject node = json.createNestedObject("MQTT"); node = json.createNestedObject("MQTT");
node["enabled"] = settings.enabled; node["enabled"] = settings.enabled;
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
node["host"] = settings.host; node["host"] = settings.host;
@@ -926,7 +913,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) { EMSESP::esp8266React.getNTPSettingsService()->read([&](NTPSettings & settings) {
JsonObject node = json.createNestedObject("NTP"); node = json.createNestedObject("NTP");
node["enabled"] = settings.enabled; node["enabled"] = settings.enabled;
node["server"] = settings.server; node["server"] = settings.server;
node["tz_label"] = settings.tzLabel; node["tz_label"] = settings.tzLabel;
@@ -934,14 +921,14 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
}); });
EMSESP::esp8266React.getOTASettingsService()->read([&](OTASettings & settings) { EMSESP::esp8266React.getOTASettingsService()->read([&](OTASettings & settings) {
JsonObject node = json.createNestedObject("OTA"); node = json.createNestedObject("OTA");
node["enabled"] = settings.enabled; node["enabled"] = settings.enabled;
node["port"] = settings.port; node["port"] = settings.port;
}); });
#endif #endif
EMSESP::webSettingsService.read([&](WebSettings & settings) { EMSESP::webSettingsService.read([&](WebSettings & settings) {
JsonObject node = json.createNestedObject("Settings"); node = json.createNestedObject("Settings");
node["tx_mode"] = settings.tx_mode; node["tx_mode"] = settings.tx_mode;
node["ems_bus_id"] = settings.ems_bus_id; node["ems_bus_id"] = settings.ems_bus_id;
node["syslog_enabled"] = settings.syslog_enabled; node["syslog_enabled"] = settings.syslog_enabled;
@@ -1033,7 +1020,7 @@ bool System::command_test(const char * value, const int8_t id) {
// takes a board profile and populates a data array with GPIO configurations // takes a board profile and populates a data array with GPIO configurations
// data = led, dallas, rx, tx, button // data = led, dallas, rx, tx, button
// returns false if profile is not found, and uses default // returns false if profile is not found
bool System::load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile) { bool System::load_board_profile(std::vector<uint8_t> & data, const std::string & board_profile) {
if (board_profile == "S32") { if (board_profile == "S32") {
data = {2, 3, 23, 5, 0}; // Gateway S32 data = {2, 3, 23, 5, 0}; // Gateway S32
@@ -1055,7 +1042,7 @@ bool System::load_board_profile(std::vector<uint8_t> & data, const std::string &
data = {2, 4, 5, 17, 33}; // Generic Ethernet (LAN8720) data = {2, 4, 5, 17, 33}; // Generic Ethernet (LAN8720)
} else { } else {
data = {EMSESP_DEFAULT_LED_GPIO, EMSESP_DEFAULT_DALLAS_GPIO, EMSESP_DEFAULT_RX_GPIO, EMSESP_DEFAULT_TX_GPIO, EMSESP_DEFAULT_PBUTTON_GPIO}; data = {EMSESP_DEFAULT_LED_GPIO, EMSESP_DEFAULT_DALLAS_GPIO, EMSESP_DEFAULT_RX_GPIO, EMSESP_DEFAULT_TX_GPIO, EMSESP_DEFAULT_PBUTTON_GPIO};
return false; return (board_profile == "CUSTOM");
} }
return true; return true;