mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
network init
This commit is contained in:
@@ -54,32 +54,37 @@ 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
|
||||||
|
WiFiMode_t currentWiFiMode = WiFi.getMode();
|
||||||
|
if (currentWiFiMode == WIFI_MODE_APSTA || currentWiFiMode == WIFI_MODE_AP) {
|
||||||
|
WiFi.mode(WIFI_MODE_AP);
|
||||||
|
} else {
|
||||||
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
|
}
|
||||||
if (_state.staticIPConfig) {
|
if (_state.staticIPConfig) {
|
||||||
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP
|
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP
|
||||||
}
|
}
|
||||||
|
|
||||||
WiFi.setHostname(_state.hostname.c_str()); // set hostname
|
WiFi.setHostname(_state.hostname.c_str()); // set hostname
|
||||||
|
|
||||||
// www.esp32.com/viewtopic.php?t=12055
|
// www.esp32.com/viewtopic.php?t=12055
|
||||||
read([&](NetworkSettings & networkSettings) {
|
if (_state.bandwidth20) {
|
||||||
if (networkSettings.bandwidth20) {
|
|
||||||
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT20);
|
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT20);
|
||||||
} else {
|
} else {
|
||||||
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT40);
|
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_STA, WIFI_BW_HT40);
|
||||||
}
|
}
|
||||||
if (networkSettings.nosleep) {
|
if (_state.nosleep) {
|
||||||
WiFi.setSleep(false); // turn off sleep - WIFI_PS_NONE
|
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
|
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
|
|
||||||
});
|
// set power after wifi is startet, fixed value for C3_V1
|
||||||
#ifdef BOARD_C3_MINI_V1
|
#ifdef BOARD_C3_MINI_V1
|
||||||
// v1 needs this value, see https://github.com/emsesp/EMS-ESP32/pull/620#discussion_r993173979
|
// 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
|
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
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// handles if wifi stopped
|
// handles if wifi stopped
|
||||||
void NetworkSettingsService::WiFiEvent(WiFiEvent_t event) {
|
void NetworkSettingsService::WiFiEvent(WiFiEvent_t event) {
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define EMSESP_APP_VERSION "3.7.0-dev.0"
|
#define EMSESP_APP_VERSION "3.6.2-dev.0a"
|
||||||
|
|||||||
Reference in New Issue
Block a user