mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-06-14 20:06:27 +03:00
Merge branch 'core3' into core3
This commit is contained in:
@@ -19,3 +19,4 @@ For more details go to [emsesp.org](https://emsesp.org/).
|
||||
- various memory optimizations [#3083](https://github.com/emsesp/EMS-ESP32/issues/3083)
|
||||
- Scheduler name is mandatory
|
||||
- Scheduler with type "Immediate", click Execute does not run the command [#3092](https://github.com/emsesp/EMS-ESP32/issues/3092)
|
||||
- network fallback to AP only after start [#3090](https://github.com/emsesp/EMS-ESP32/issues/3090)
|
||||
|
||||
@@ -93,7 +93,7 @@ lib_deps =
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
ESP32Async/AsyncTCP @ 3.4.10
|
||||
ESP32Async/ESPAsyncWebServer @ 3.11.0
|
||||
https://github.com/mobizt/ReadyMail.git @ 0.4.0
|
||||
https://github.com/mobizt/ReadyMail.git @ 0.4.2
|
||||
https://github.com/mobizt/ESP_SSLClient.git @ 3.1.3
|
||||
; https://github.com/emsesp/EMS-ESP-Modules.git @ 1.0.8
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ void Network::begin() {
|
||||
WiFi.persistent(false);
|
||||
WiFi.setAutoReconnect(false);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect(true); // wipe old settings in NVS
|
||||
WiFi.disconnect(true, true); // wipe old settings in NVS
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
WiFi.setHostname(hostname_.c_str()); // updates shared default_hostname buffer
|
||||
WiFi.enableSTA(true); // creates the STA netif
|
||||
WiFi.STA.setHostname(hostname_.c_str()); // pushes to esp_netif_set_hostname
|
||||
@@ -235,7 +236,6 @@ void Network::reconnect() {
|
||||
last_disconnect_reason_ = 0;
|
||||
connect_retry_ = 0;
|
||||
reconnect_count_ = 0;
|
||||
phase_ = NetPhase::ETHERNET; // begin() will refine this once settings are reloaded
|
||||
|
||||
// reload the network settings and apply them
|
||||
begin();
|
||||
@@ -304,23 +304,15 @@ void Network::checkConnection() {
|
||||
}
|
||||
|
||||
if (!still_up) {
|
||||
if (network_iface_ == NetIface::WIFI) {
|
||||
uint8_t reason = last_disconnect_reason_;
|
||||
if (reason == 0) {
|
||||
reason = WIFI_REASON_UNSPECIFIED; // event hasn't fired yet (or was cleared); avoid logging "0"
|
||||
}
|
||||
LOG_INFO("WiFi connection lost (reason %u: %s)", reason, disconnectReason(reason));
|
||||
wifi_connect_pending_ = false;
|
||||
} else if (network_iface_ == NetIface::ETHERNET) {
|
||||
LOG_INFO("Ethernet connection lost");
|
||||
ethernet_connect_pending_ = false;
|
||||
}
|
||||
juststopped_ = true;
|
||||
network_iface_ = NetIface::NONE;
|
||||
network_ip_ = 0;
|
||||
has_ipv6_ = false;
|
||||
connect_retry_ = 0;
|
||||
phase_ = initialPhase();
|
||||
if (network_iface_ == NetIface::ETHERNET) {
|
||||
LOG_WARNING("Ethernet connection lost");
|
||||
return;
|
||||
}
|
||||
begin();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -543,12 +535,6 @@ void Network::startEthernet() {
|
||||
return;
|
||||
}
|
||||
|
||||
// disabled Ethernet for boards with only 4MB flash and no PSRAM
|
||||
if (ESP.getFlashChipSize() < 4194304 && !ESP.getPsramSize()) { // 4MB
|
||||
LOG_NOTICE("Ethernet disabled for boards with only 4MB flash");
|
||||
return;
|
||||
}
|
||||
|
||||
// reset power and add a delay as ETH doesn't not always start up correctly after a warm boot
|
||||
if (eth_power_ != -1) {
|
||||
pinMode(eth_power_, OUTPUT);
|
||||
@@ -657,7 +643,9 @@ void Network::findNetworks() {
|
||||
} else if (network_iface_ == NetIface::AP) {
|
||||
phase_ = NetPhase::AP;
|
||||
}
|
||||
|
||||
if (!ethernet_ever_connected && ethernet_connected()) {
|
||||
ethernet_ever_connected_ = true;
|
||||
}
|
||||
LOG_INFO("Network connected via %s (IP: " IPSTR ")",
|
||||
network_iface_ == NetIface::ETHERNET ? "Ethernet"
|
||||
: network_iface_ == NetIface::WIFI ? "WiFi"
|
||||
@@ -703,18 +691,21 @@ void Network::findNetworks() {
|
||||
if (connect_retry_ >= MAX_NETWORK_RECONNECTION_ATTEMPTS && phase_ != NetPhase::AP) {
|
||||
if (phase_ == NetPhase::ETHERNET) {
|
||||
if (ssid_.isEmpty()) {
|
||||
if (!ethernet_ever_connected_) {
|
||||
LOG_WARNING("Ethernet failed to connect after %u attempts, falling back to AP", connect_retry_);
|
||||
phase_ = NetPhase::AP;
|
||||
}
|
||||
} else {
|
||||
LOG_WARNING("Ethernet failed to connect after %u attempts, switching to WiFi", connect_retry_);
|
||||
phase_ = NetPhase::WIFI;
|
||||
}
|
||||
ethernet_connect_pending_ = false;
|
||||
} else if (phase_ == NetPhase::WIFI) {
|
||||
if (!wifi_ever_connected_) {
|
||||
LOG_WARNING("WiFi failed to connect after %u attempts, falling back to AP", connect_retry_);
|
||||
phase_ = NetPhase::AP;
|
||||
}
|
||||
wifi_connect_pending_ = false;
|
||||
WiFi.disconnect(true);
|
||||
}
|
||||
connect_retry_ = 0;
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ class Network {
|
||||
|
||||
bool wifi_events_registered_ = false; // ensure WiFi.onEvent() handlers are registered only once across begin()/reconnect() cycles
|
||||
bool wifi_ever_connected_ = false; // set true once we've successfully obtained an IP
|
||||
bool ethernet_ever_connected_ = false; // set true once we've successfully obtained an IP
|
||||
|
||||
// Network and AP settings
|
||||
bool enableMDNS_;
|
||||
|
||||
@@ -403,7 +403,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
||||
}
|
||||
|
||||
LOG_DEBUG("Sending %s Tx [#%d], telegram: %s",
|
||||
(telegram->operation != Telegram::Operation::TX_READ) ? ("write") : ("read"),
|
||||
(telegram->operation != Telegram::Operation::TX_READ) ? "write" : "read",
|
||||
tx_telegram.id_,
|
||||
Helpers::data_to_hex(telegram_raw, length - 1).c_str()); // exclude the last CRC byte
|
||||
|
||||
@@ -627,7 +627,7 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
|
||||
}
|
||||
|
||||
LOG_DEBUG("Last Tx %s operation failed. Retry #%d. sent message: %s, received: %s",
|
||||
(operation == Telegram::Operation::TX_WRITE) ? ("Write") : ("Read"),
|
||||
(operation == Telegram::Operation::TX_WRITE) ? "Write" : "Read",
|
||||
retry_count_,
|
||||
telegram_last_->to_string().c_str(),
|
||||
Helpers::data_to_hex(data, length - 1).c_str());
|
||||
|
||||
Reference in New Issue
Block a user