-
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
Enhanced connection management for esp32 network driver #1181
base: main
Are you sure you want to change the base?
Conversation
@@ -74,7 +76,8 @@ gotIp(IpInfo) -> | |||
io:format("Got IP: ~p~n", [IpInfo]). | |||
|
|||
disconnected() -> | |||
io:format("Disconnected from AP.~n"). | |||
io:format("Disconnected from AP, attempting to reconnect~n"), | |||
network:connect(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a delay here eg 500-1000ms or something? (ideally exponential backoff - but static delay should be fine..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This just signals the driver to start attempting a connection, if that attempt succeeds the connected callback will be triggered, otherwise a disconnected callback will be triggered - in which case the attempt will be made again… this would function exactly as the driver always has… by defining a custom callback the user could add any extra delay, or scan for networks instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference is this was connection was called internally, so stop would never be possible. Now by defining a callback the user can control when a reconnection (or now a new connection) will happen.
21fcf76
to
887b3d1
Compare
887b3d1
to
22678d8
Compare
246d3b5
to
ae6e359
Compare
ae6e359
to
2611050
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 descriptions of new configuration options and connect/0,1 and disconnect/0 functions. Signed-off-by: Winford <[email protected]>
2611050
to
be980c2
Compare
This PR adds the ability to stop a connection to an access point, and to start a connection to a new, or the last configured access point. The driver can also enable STA mode without performing an initial connection by supplying the
managed
atom in the STA configuration and omitting thessid
andpsk
settings. Combined with the network scan feature in #1165 this gives the esp32 platform the ability to act as a roaming device, and connect to any known wifi networks found after performing a wifi scan. Thedisconnected
event callback can be used to override the default automatic re-connect action of the driver, and a network scan or other means may now be used to determine if, when, and which access point to connect to.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