network init

This commit is contained in:
MichaelDvP
2023-09-17 09:27:08 +02:00
parent 8a16566f53
commit d8c298f6fe
3 changed files with 36 additions and 27 deletions

View File

@@ -54,31 +54,36 @@ void NetworkSettingsService::manageSTA() {
} }
// Connect or reconnect as required // Connect or reconnect as required
if ((WiFi.getMode() & WIFI_STA) == 0) { WiFi.disconnect(true); // turn radio off
if (_state.staticIPConfig) { WiFiMode_t currentWiFiMode = WiFi.getMode();
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP if (currentWiFiMode == WIFI_MODE_APSTA || currentWiFiMode == WIFI_MODE_AP) {
} WiFi.mode(WIFI_MODE_AP);
} else {
WiFi.setHostname(_state.hostname.c_str()); // set hostname WiFi.mode(WIFI_MODE_NULL);
// www.esp32.com/viewtopic.php?t=12055
read([&](NetworkSettings & networkSettings) {
if (networkSettings.bandwidth20) {
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT20);
} else {
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT40);
}
if (networkSettings.nosleep) {
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
}
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
esp_wifi_set_max_tx_power(networkSettings.tx_power * 4); // set power after wifi is startet for C3
});
#ifdef BOARD_C3_MINI_V1
// v1 needs this value, see https://github.com/emsesp/EMS-ESP32/pull/620#discussion_r993173979
WiFi.setTxPower(WIFI_POWER_8_5dBm); // https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
#endif
} }
if (_state.staticIPConfig) {
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP
}
WiFi.setHostname(_state.hostname.c_str()); // set hostname
// www.esp32.com/viewtopic.php?t=12055
if (_state.bandwidth20) {
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT20);
} else {
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT40);
}
if (_state.nosleep) {
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
}
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
// set power after wifi is startet, fixed value for C3_V1
#ifdef BOARD_C3_MINI_V1
// v1 needs this value, see https://github.com/emsesp/EMS-ESP32/pull/620#discussion_r993173979
WiFi.setTxPower(WIFI_POWER_8_5dBm); // https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
#else
esp_wifi_set_max_tx_power(_state.tx_power * 4);
#endif
} }
// handles if wifi stopped // handles if wifi stopped
@@ -89,4 +94,8 @@ void NetworkSettingsService::WiFiEvent(WiFiEvent_t event) {
_stopping = false; _stopping = false;
} }
} }
// wait 3 seconds before reconnecting
if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
_lastConnectionAttempt = millis();
}
} }

View File

@@ -48,8 +48,8 @@ extra_scripts =
scripts/rename_fw.py scripts/rename_fw.py
[espressi32_base_tasmota] [espressi32_base_tasmota]
; use Tasmota's 2.0.11 core based libary from https://github.com/tasmota/platform-espressif32 which removes some libs (like mbedtsl) and increases available heap ; use Tasmota's 2.0.13 core based libary from https://github.com/tasmota/platform-espressif32 which removes some libs (like mbedtsl) and increases available heap
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.08.01/platform-espressif32.zip platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.09.01/platform-espressif32.zip
framework = arduino framework = arduino
build_flags = ${common.build_flags} build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags} build_unflags = ${common.unbuild_flags}

View File

@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.0-dev.0" #define EMSESP_APP_VERSION "3.6.2-dev.0a"