-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add support for esp32 network driver scanning for access points #1165
base: main
Are you sure you want to change the base?
Conversation
58cf1f8
to
cdadc33
Compare
I struggled here: I started out empty example and tried:
This crashes with: Then I read docs, about having to start the network, and tried:
which crashed with: delaying things and scanning after connection is done made it further to a crash:
It also seems that connecting to a network not available, disallows scanning with: Would be great seeing an example that could be used in CI eg:
I'll work on getting wokwi CI going so this can be covered by CI. |
I did not add an example yet, my plan was to write a demonstration of “roaming” for atomvm_examples. It is a little difficult to use until #1181 is merged, that will allow starting WiFi without immediately starting a connection. Scans will always fail when a connection is in progress, so your application will need to start a scan after obtaining an IP address, or before any connection is started (which is not possible until after #1181). |
I wish your second example had a stacktrace! You can see the scan result did come back with no networks found… this can happen with default scans (the dwell time is very short by default - and can easily miss networks, in my experience). I think it’s just a bad match in your test that is crashing there. |
ohh the embarrassment lol - it's the IO.inspect call that crashes, will look into it - used to throwing anything at IO.inspect.. Makes sense with the other stuff, suppose some kind of WifiManager GenServer will materialize, while this PR is on driver primitives level.. I'll test #1181 and help land that first.. |
My plan precisely! The PRs I have already submitted will provide all the necessary low level functionality, but I would like to create a higher level network_manager module that can simplify configuration and orchestration. |
As far as “dwell” time for the scan, I have found between 300-500ms will find all of the available networks, with the default (120ms) I do notice networks being frequently missed. |
cdadc33
to
b70a385
Compare
That does sound like a bug, from my limmited understanding of Elixir you should be able to give it just about anything, much like |
b70a385
to
aa3a56d
Compare
You did point me to a problem here, I started testing more boards and realized that even with maximum dwell time no network are being found. I cherry-picked these commits from a different local branch and must have missed something. |
480b056
to
50a78c7
Compare
When I split up the working branch I was testing new network features on I mistakenly submitted this PR first, but in order to use the scan function PR #1181 needs to be merged first, and this will need to be rebased. |
I did find a bug that would cause the results to be empty if only a single network was found, during most of my testing I had multiple networks, so this didn't get caught. @petermm, thanks for testing and helping me correct this! |
50a78c7
to
d0a4ea5
Compare
For more fine grained connection management in applications the driver can now be started, without perfoming an inital connection, by the use of the key `managed` in the STA configuration. Adds network:sta_connect/0,1 to allow connecting to an access point after the driver has been started in STA or STA+AP mode. If the function is used without parameters a connection to the last configured access point will be started. Adds network:sta_disconnect/0 to disconnect a station from an access point. The station mode disconnected callback now maintains the default behavior of reconnecting to the last access point if the connection is lost, but if the user defines a custom callback the automatic re-connection will not happen, allowing for users to take advantage of scan results or some other means to determine when and which access point to associate with. The combination of the use of a disconnected callback and `managed` mode allow for the use of `network:wifi_scan/0,1` (PR atomvm#1165), since the wifi must not be connected to a station when perfoming a scan and the current implementation always starts a connection immediatly and always reconnects when disconnected. Signed-off-by: Winford <[email protected]>
Corrects the type name db() to the more correct `dbm()`, and adds a brief edoc explanation for the value. Signed-off-by: Winford <[email protected]>
d0a4ea5
to
d72b955
Compare
For more fine grained connection management in applications the driver can now be started, without perfoming an inital connection, by the use of the key `managed` in the STA configuration. Adds network:sta_connect/0,1 to allow connecting to an access point after the driver has been started in STA or STA+AP mode. If the function is used without parameters a connection to the last configured access point will be started. Adds network:sta_disconnect/0 to disconnect a station from an access point. The station mode disconnected callback now maintains the default behavior of reconnecting to the last access point if the connection is lost, but if the user defines a custom callback the automatic re-connection will not happen, allowing for users to take advantage of scan results or some other means to determine when and which access point to associate with. The combination of the use of a disconnected callback and `managed` mode allow for the use of `network:wifi_scan/0,1` (PR atomvm#1165), since the wifi must not be connected to a station when perfoming a scan and the current implementation always starts a connection immediatly and always reconnects when disconnected. Signed-off-by: Winford <[email protected]>
Adds the ability for devices configured for sta or ap+sta to scan for available access points when not currently associated to an AP. With no arguments the default maximum results returned is 6. All default options can be configured in the `sta_config()` section of the configuration used to start the network driver, or set in the configuration parameter of `network:wifi_scan/1`. Signed-off-by: Winford <[email protected]>
d72b955
to
b3b0558
Compare
Adds documentation for `network:wifi_scan/0,1` and updates details for `network:sta_rssi/0`, as well as better organizing the sub sections that these commands are documented in. Signed-off-by: Winford <[email protected]>
b3b0558
to
29c9c9f
Compare
Add
network:wifi_scan/0,1
to esp32 network driver, giving the ability for devices configured for "station mode" (or with "station + access point mode") to scan for available access points.note: these changes depend on PR #1181
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