Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opinion / Feature request: Wireless Network Mode selection b/g/n #2012

Closed
Domosapiens opened this issue Nov 7, 2018 · 8 comments
Closed
Labels
Category: Wifi Related to the network connectivity Type: Enhancement Improve something already present

Comments

@Domosapiens
Copy link

Is it useful to add a selection for the preferred Wireless Network Mode?

From the ESP8266 datasheet:
802dot11 mode_bgn

One can expect more stable WiFi (stronger signals/longer range) at the cost of trough-put in b/g mode.
I think mode n is far over the top for IoT.

In many applications the ESP is cramped between other components in wall or housing.
Isn't 11Mbps enough at the advantage of much more Rx/Tx budget?

If this is useful, I request a 802.11 b/g/n/auto selection on the Config page.

Remark:
All my ESP nodes are n connected, even at the cost of signal strength.
My dd-wrt router has Wireless Network Mode "Mixed" but no possibilities to force per client the 802.11b/g. Do other routers have this?

@TD-er
Copy link
Member

TD-er commented Nov 7, 2018

I can look into the WiFi settings to see if I can set the mode.
But even so if you set the mode to B instead of N, you will run into network instability, due to the fact the access point has to change its mode back and forth between modes.
So it is better to have it connected via the same mode as others do, but only at a lower data rate.
Nodes will connect at different rates, depending on conditions.
When running at lower bandwidth (connection speed), the sensitivity is increased. Or to be more precise, the tolerance for faults due to bad reception will increase.

Having a mixed network (B/G/N) will cause more issues regarding stability (and speed for other nodes), but that also depends on the model/brand of the used access point.

@TD-er TD-er added Type: Enhancement Improve something already present Category: Wifi Related to the network connectivity labels Nov 7, 2018
@TD-er TD-er added this to ToDo in WiFi stability and UX via automation Nov 7, 2018
TD-er added a commit to TD-er/ESPEasy that referenced this issue Jan 24, 2019
TD-er added a commit to TD-er/ESPEasy that referenced this issue Feb 1, 2019
WiFi stability and UX automation moved this from ToDo to Done Apr 15, 2020
@podaen
Copy link

podaen commented Oct 8, 2022

I discovered that the protocol can only be set to const uint8_t protocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G || WIFI_PROTOCOL_11N; OR const uint8_t protocol = WIFI_PROTOCOL_11B OR const uint8_t protocol = WIFI_PROTOCOL_11B | 0 | 0; anything else fails.

#include "esp_wifi.h"
#include "esp_log.h"

esp_err_t err;

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
	err = esp_wifi_init(&cfg);
	if (err != ESP_OK) {
		Serial.println(err);
		Serial.println("Could not set wifi power mode!");
		return false;
	}

	err = esp_wifi_set_mode(WIFI_MODE_STA);
	if (err != ESP_OK) {
		Serial.println(err);
		Serial.println("Could not set sta!");
		return false;
	}

	//const uint8_t protocol = WIFI_PROTOCOL_11G;
	//const uint8_t protocol = WIFI_PROTOCOL_11B | 0 | 0;
	const uint8_t protocol = WIFI_PROTOCOL_11B;

	err = esp_wifi_set_protocol(WIFI_IF_STA, protocol);
	if (err != ESP_OK) {
		//258 = ESP_ERR_INVALID_ARG
		Serial.println(err);
		Serial.println("Could not set protocol!");
		return false;
	}

	uint8_t getprotocol;
	//esp_err_t err;
	err = esp_wifi_get_protocol(WIFI_IF_STA, &getprotocol);
	if (err != ESP_OK) {
		Serial.println("Could not get protocol!");
		//log_e("Could not get protocol! %d", err);
		return false;
	}
	if (getprotocol & WIFI_PROTOCOL_11N) {
		Serial.println("WiFi_Protocol_11n");
	}
	if (getprotocol & WIFI_PROTOCOL_11G) {
		Serial.println("WiFi_Protocol_11g");
	}
	if (getprotocol & WIFI_PROTOCOL_11B) {//worst, but dificuld to set else
		Serial.println("WiFi_Protocol_11b");
	}

@TD-er
Copy link
Member

TD-er commented Oct 8, 2022

Looks like ESP32 code.
For ESP8266 I have been working on these issues last week.
Connecting using 802.11n only seems to work on specific SDK versions.

I will take this code you posted to see if I can add this to the ESP32 code for ESPEasy too.
I already added code to detect which modes are advertised by the AP, so there is no need to try unsupported modes.

@TD-er TD-er reopened this Oct 8, 2022
WiFi stability and UX automation moved this from Done to ToDo Oct 8, 2022
@podaen
Copy link

podaen commented Oct 8, 2022

I still have the old ESP32. Do you have an ESP32-S3 to test it with? I think it might work...

@TD-er
Copy link
Member

TD-er commented Oct 8, 2022

ESP32-S3 is not yet supported by ESPEasy.

@podaen
Copy link

podaen commented Oct 8, 2022

You can take my code. Known that the wifi_config_t is not in there yet.

@TD-er
Copy link
Member

TD-er commented Oct 8, 2022

The esp_wifi_get_protocol was already used in ESPEasy:

WiFiConnectionProtocol getConnectionProtocol() {
if (WiFi.RSSI() < 0) {
#ifdef ESP8266
switch (wifi_get_phy_mode()) {
case PHY_MODE_11B:
return WiFiConnectionProtocol::WiFi_Protocol_11b;
case PHY_MODE_11G:
return WiFiConnectionProtocol::WiFi_Protocol_11g;
case PHY_MODE_11N:
return WiFiConnectionProtocol::WiFi_Protocol_11n;
}
#endif
#ifdef ESP32
uint8_t protocol;
esp_wifi_get_protocol(WIFI_IF_STA, &protocol);
if (protocol & WIFI_PROTOCOL_11N) {
return WiFiConnectionProtocol::WiFi_Protocol_11n;
}
if (protocol & WIFI_PROTOCOL_11G) {
return WiFiConnectionProtocol::WiFi_Protocol_11g;
}
if (protocol & WIFI_PROTOCOL_11B) {
return WiFiConnectionProtocol::WiFi_Protocol_11b;
}
#endif
}
return WiFiConnectionProtocol::Unknown;
}

The code for setting the b/g/n config for ESP32 was also already present:

#ifdef ESP32
/*
uint8_t protocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G; // Default to BG
if (!Settings.ForceWiFi_bg_mode() || (wifi_connect_attempt > 10)) {
// Set to use BGN
protocol |= WIFI_PROTOCOL_11N;
}
if (WifiIsSTA(WiFi.getMode())) {
esp_wifi_set_protocol(WIFI_IF_STA, protocol);
}
if (WifiIsAP(WiFi.getMode())) {
esp_wifi_set_protocol(WIFI_IF_AP, protocol);
}
*/
#endif // ifdef ESP32

But commented out as it wasn't working very well, which probably got to do with what you reported that not all combinations are considered valid.

So I will have a look at that part too and also check against the (newly added) info whether an AP advertises some mode so we don't need to attempt to connect to it when not supported.

See also my pending PR regarding fixes for WiFi: #4285
Would really appreciate it if you could test this PR too.
See here for test builds: https://github.com/letscontrolit/ESPEasy/actions/runs/3211994332

@TD-er
Copy link
Member

TD-er commented May 11, 2023

This is now working well on the newly supported platforms like ESP32-S2/S3/C3
I also updated the sensitivity values based on the active connection mode and use those for the automatic TX power setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Wifi Related to the network connectivity Type: Enhancement Improve something already present
Projects
Development

No branches or pull requests

3 participants