Skip to content

Commit

Permalink
network init
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Sep 17, 2023
1 parent 8a16566 commit d8c298f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
51 changes: 30 additions & 21 deletions lib/framework/NetworkSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,36 @@ void NetworkSettingsService::manageSTA() {
}

// Connect or reconnect as required
if ((WiFi.getMode() & WIFI_STA) == 0) {
if (_state.staticIPConfig) {
WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); // configure for static IP
}
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) {
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
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

// 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
});
// 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
// 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
Expand All @@ -89,4 +94,8 @@ void NetworkSettingsService::WiFiEvent(WiFiEvent_t event) {
_stopping = false;
}
}
// wait 3 seconds before reconnecting
if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
_lastConnectionAttempt = millis();
}
}
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ extra_scripts =
scripts/rename_fw.py

[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
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.08.01/platform-espressif32.zip
; 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.09.01/platform-espressif32.zip
framework = arduino
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.0-dev.0"
#define EMSESP_APP_VERSION "3.6.2-dev.0a"

0 comments on commit d8c298f

Please sign in to comment.