diff --git a/interface/src/framework/network/NetworkSettingsForm.tsx b/interface/src/framework/network/NetworkSettingsForm.tsx
index a1a0af29e..bf39145b8 100644
--- a/interface/src/framework/network/NetworkSettingsForm.tsx
+++ b/interface/src/framework/network/NetworkSettingsForm.tsx
@@ -82,7 +82,9 @@ const WiFiSettingsForm: FC = () => {
if (selectedNetwork) {
updateState('networkSettings', (current_data) => ({
ssid: selectedNetwork.ssid,
- password: '',
+ bssid: selectedNetwork.bssid,
+ channel: selectedNetwork.channel,
+ password: current_data ? current_data.password : '',
hostname: current_data?.hostname,
static_ip_config: false,
enableIPv6: false,
@@ -117,6 +119,12 @@ const WiFiSettingsForm: FC = () => {
} catch (errors: any) {
setFieldErrors(errors);
}
+ deselectNetwork();
+ };
+
+ const setCancel = async () => {
+ deselectNetwork();
+ await loadData();
};
const restart = async () => {
@@ -139,10 +147,17 @@ const WiFiSettingsForm: FC = () => {
-
+
@@ -160,6 +175,27 @@ const WiFiSettingsForm: FC = () => {
margin="normal"
/>
)}
+
+
{(!selectedNetwork || !isNetworkOpen(selectedNetwork)) && (
{
)}
- {!restartNeeded && dirtyFlags && dirtyFlags.length !== 0 && (
+ {!restartNeeded && (selectedNetwork || (dirtyFlags && dirtyFlags.length !== 0)) && (
}
diff --git a/interface/src/framework/network/WiFiNetworkSelector.tsx b/interface/src/framework/network/WiFiNetworkSelector.tsx
index 865db65ab..3d70c5a68 100644
--- a/interface/src/framework/network/WiFiNetworkSelector.tsx
+++ b/interface/src/framework/network/WiFiNetworkSelector.tsx
@@ -65,7 +65,9 @@ const WiFiNetworkSelector: FC = ({ networkList }) => {
diff --git a/interface/src/types/network.ts b/interface/src/types/network.ts
index ec93ad757..1bab9397d 100644
--- a/interface/src/types/network.ts
+++ b/interface/src/types/network.ts
@@ -37,6 +37,8 @@ export interface NetworkStatus {
export interface NetworkSettings {
ssid: string;
+ bssid: string;
+ channel: number;
password: string;
hostname: string;
static_ip_config: boolean;
diff --git a/interface/src/validators/network.ts b/interface/src/validators/network.ts
index 761ce0de7..2fd25cdc8 100644
--- a/interface/src/validators/network.ts
+++ b/interface/src/validators/network.ts
@@ -5,6 +5,7 @@ import type { NetworkSettings } from 'types';
export const createNetworkSettingsValidator = (networkSettings: NetworkSettings) =>
new Schema({
ssid: [{ type: 'string', max: 32, message: 'SSID must be 32 characters or less' }],
+ bssid: [{ type: 'string', max: 17, message: 'BSSID must be 17 characters or empty' }],
password: { type: 'string', max: 64, message: 'Password must be 64 characters or less' },
hostname: [{ required: true, message: 'Hostname is required' }, HOSTNAME_VALIDATOR],
...(networkSettings.static_ip_config && {
@@ -17,5 +18,9 @@ export const createNetworkSettingsValidator = (networkSettings: NetworkSettings)
tx_power: [
{ required: true, message: 'Tx Power is required' },
{ type: 'number', min: 0, max: 20, message: 'Tx Power must be between 0 and 20dBm' }
+ ],
+ channel: [
+ { required: true, message: 'Channel is required' },
+ { type: 'number', min: 0, max: 13, message: 'Channel must be between 0 and 13' }
]
});
diff --git a/lib/framework/NetworkSettingsService.cpp b/lib/framework/NetworkSettingsService.cpp
index a9c831686..75597240c 100644
--- a/lib/framework/NetworkSettingsService.cpp
+++ b/lib/framework/NetworkSettingsService.cpp
@@ -22,6 +22,8 @@ void NetworkSettingsService::begin() {
WiFi.mode(WIFI_MODE_MAX);
WiFi.mode(WIFI_MODE_NULL);
+ WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); // default is FAST_SCAN
+ WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); // is default, no need to set
WiFi.onEvent(std::bind(&NetworkSettingsService::WiFiEvent, this, _1));
@@ -54,36 +56,42 @@ void NetworkSettingsService::manageSTA() {
}
// Connect or reconnect as required
- 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
+ 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.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
+ 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
+ }
+ // attempt to connect to the network
+ uint mac[6];
+ if (!_state.bssid.isEmpty() && sscanf(_state.bssid.c_str(), "%X:%X:%X:%X:%X:%X", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) {
+ uint8_t mac1[6];
+ for (uint8_t i = 0; i < 6; i++) {
+ mac1[i] = (uint8_t)mac[i];
+ }
+ WiFi.begin(_state.ssid.c_str(), _state.password.c_str(), _state.channel, mac1);
+ } else {
+ WiFi.begin(_state.ssid.c_str(), _state.password.c_str(), _state.channel);
+ }
- // set power after wifi is startet, fixed value for C3_V1
+ // 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);
+ // esp_wifi_set_max_tx_power(_state.tx_power * 4);
+ WiFi.setTxPower((wifi_power_t)(_state.tx_power * 4));
#endif
+ }
}
// handles if wifi stopped
diff --git a/lib/framework/NetworkSettingsService.h b/lib/framework/NetworkSettingsService.h
index 407282413..36823f357 100644
--- a/lib/framework/NetworkSettingsService.h
+++ b/lib/framework/NetworkSettingsService.h
@@ -30,17 +30,19 @@
class NetworkSettings {
public:
// core wifi configuration
- String ssid;
- String password;
- String hostname;
- bool staticIPConfig;
- bool enableIPv6;
- bool bandwidth20;
- int8_t tx_power;
- bool nosleep;
- bool enableMDNS;
- bool enableCORS;
- String CORSOrigin;
+ String ssid;
+ String bssid;
+ String password;
+ String hostname;
+ uint8_t channel;
+ bool staticIPConfig;
+ bool enableIPv6;
+ bool bandwidth20;
+ int8_t tx_power;
+ bool nosleep;
+ bool enableMDNS;
+ bool enableCORS;
+ String CORSOrigin;
// optional configuration for static IP address
IPAddress localIP;
@@ -52,6 +54,8 @@ class NetworkSettings {
static void read(NetworkSettings & settings, JsonObject & root) {
// connection settings
root["ssid"] = settings.ssid;
+ root["bssid"] = settings.bssid;
+ root["channel"] = settings.channel;
root["password"] = settings.password;
root["hostname"] = settings.hostname;
root["static_ip_config"] = settings.staticIPConfig;
@@ -75,6 +79,8 @@ class NetworkSettings {
auto enableCORS = settings.enableCORS;
auto CORSOrigin = settings.CORSOrigin;
settings.ssid = root["ssid"] | FACTORY_WIFI_SSID;
+ settings.bssid = root["bssid"] | "";
+ settings.channel = root["channel"] | 0;
settings.password = root["password"] | FACTORY_WIFI_PASSWORD;
settings.hostname = root["hostname"] | FACTORY_WIFI_HOSTNAME;
settings.staticIPConfig = root["static_ip_config"] | false;