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

Handle network_driver: Unhandled wifi event: 21. #1100

Closed
petermm opened this issue Mar 4, 2024 · 7 comments
Closed

Handle network_driver: Unhandled wifi event: 21. #1100

petermm opened this issue Mar 4, 2024 · 7 comments

Comments

@petermm
Copy link
Contributor

petermm commented Mar 4, 2024

I (1593851) wifi:bcn_timeout,ap_probe_send_start
I (1593851) network_driver: Unhandled wifi event: 21.

repeatedly.. on a C3card - most likely poor Rssi..

Solution:

Silently handle it - as there already is the wifi:bcn_timeout,ap_probe_send_start log

or

gracefully log "bcn_timeout: Potentially weak wifi signal", or better wording.

What does bcn_timeout, ap_probe_send_start mean?

The STA does not receive the Beacon frame within the specified time (6 s by default for ESP32, equals to 60 Beacon Intervals). - The reason could be:

Insufficient memory. “ESP32_WIFI_MGMT_SBUF_NUM” is not enough (there will be errors like “esf_buf: t=8, l=beacon_len, …” in the log). You can check this by typing the heap size when received a Disconnect event.
The AP did not send a beacon. This can be checked by capturing beacons from AP.
Rssi too low. When the Rssi value is too low in complex environments, the STA may not receive the beacon. This can be checked by retrieving Rssi values via esp_wifi_sta_get_ap_info.
Hardware related issues. Bad package capturing performance.
When there is a bcn_timeout, the STA will try to send Probe Request for five times. If a Probe Response is received from the AP, the connection will be kept, otherwise, the STA will send a Disconnect event and the connection will fail.

@UncleGrumpy
Copy link
Collaborator

This could also be due to the beacon interval used by the router, if it is set for a longer than normal time, or itself is suffering degraded performance due to congestion, may exaggerate this problem. And as you point out, it could be poor RSSI, which, compounded with a longer beacon interval could trigger this callback if just a single beacon ping is missed.

@UncleGrumpy
Copy link
Collaborator

I looked closer at esp-idf/components/esp_wifi/include/esp_wifi.h the beacon timeout is actually due to the event 21 which is ESP_ERR_WIFI_NOT_ASSOC, the WiFi connection is not associated with an access point. At what point in the application execution does this happen, when starting the network, or at some point after? Does any network activity succeed before this error occurs?

@petermm
Copy link
Contributor Author

petermm commented Apr 16, 2024

cc @arpunk - whom I believe reported it on telegram..

@arpunk
Copy link
Contributor

arpunk commented Apr 16, 2024

@UncleGrumpy @petermm this only happened to me during that session and haven't seen that log warning again, but I agree that instead of event 21 a possible ESP_ERR_WIFI_NOT_ASSOC would be more descriptive.

@UncleGrumpy
Copy link
Collaborator

The error 21 is being reported directly by the esp-idf, and as you pointed out, a handler for this could be useful, the default should just report a more useful error, but users could override that with a custom handler.

@UncleGrumpy
Copy link
Collaborator

My mistake... I was accidentally looking error codes and not event codes 🤦🏾‍♂️. The unhandled wifi event 21 is indeed WIFI_EVENT_STA_BEACON_TIMEOUT, I don't think there is anything a user can to in their application to remedy this situation, unless someone builds a wifi connected autonomous robot, they may need to have a handler for this event to have the robot move closer to the AP. For now we can log a more helpful error. I believe if enough beacon timeouts occur in a row a WIFI_EVENT_STA_DISCONNECTED will be emitted.

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Apr 23, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
@UncleGrumpy
Copy link
Collaborator

PR #1137 adds a handler and a configurable (optional) STA mode callback for the beacon_timeout event. Also improves the log message, so it will be helpful, even if the callback isn't used.

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Apr 29, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Apr 29, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Apr 29, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue May 1, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue May 12, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue May 22, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue May 25, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 3, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 4, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 6, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 27, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 28, 2024
Adds an event handler for `event 21` the `WIFI_EVENT_STA_BEACON_TIMEOUT` event
and an option to add an Erlang callback handler for the event. The event will
be logged with an info level message that includes a suggestion about the two
most likely causes, poor rssi and network congestion. A callback config option
`{beacon_timeout, fun()}` may be added to the `sta` config.

Closes atomvm#1100

Signed-off-by: Winford <winford@object.stream>
bettio added a commit that referenced this issue Oct 3, 2024
Address several ESP32 network driver issues

These changes close the following issues for the ESP32 network driver:
* [#643] When network:stop/0 is used the driver is now completely stopped and
all resources are freed.
* [#1100] Adds a configurable event handler for STA beacon timeouts
(Event: 21).
* Fixes several possible cases of double free() when using network:start/1.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
@bettio bettio closed this as completed in ec7602c Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants