-
Notifications
You must be signed in to change notification settings - Fork 139
Add wifi_settings_connect library #94
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
base: develop
Are you sure you want to change the base?
Add wifi_settings_connect library #94
Conversation
The library provides a way to store WiFi hotspot details in Flash and connect automatically, avoiding the need to specify build-time flags such as WIFI_SSID and WIFI_PASSWORD.
src/rp2_common/wifi_settings_connect/include/wifi_settings/wifi_settings_configuration.h
Outdated
Show resolved
Hide resolved
src/rp2_common/wifi_settings_connect/include/wifi_settings/wifi_settings_configuration.h
Outdated
Show resolved
Hide resolved
FYI I've changed the base-branch on both your PRs to |
@peterharperuk and @kilograham |
Thank you for looking at this PR. I have made some changes to the upstream library to improve configurability and avoid a conflict with the Bluetooth library. I have also made the documentation more self-contained. Please could you look at it again? Thanks. |
# File format details | ||
|
||
The file format is very simple so that it can be read by a simple algorithm | ||
that doesn't require much code space. The parser ignores any line that it | ||
doesn't understand, and skips any keys that are not known. Here are the rules: | ||
|
||
- The key and the value should be separated only by an `=` character, e.g. `ssid1=HomeWiFi`. | ||
- Lines that don't match the form `key=value` are completely ignored; | ||
you can add text, comments etc. in order to help you manage your configuration. | ||
- On a line that does match `key=value`, whitespace is NOT ignored. | ||
Be careful to avoid adding extra spaces around `=`. | ||
A space before `=` will be part of the key, and a space after `=` will be part of the value. | ||
- Unix and Windows line endings are supported. | ||
- The maximum size of the file is 4096 bytes. | ||
- Values can contain any printable UTF-8 character. | ||
- Keys can also contain any printable UTF-8 character except for '='. | ||
- There is no maximum size for a key or a value (except for the file size). | ||
- Values can be zero length. | ||
- Keys must be at least 1 byte. | ||
- If a key appears more than once in the file, the first value is used. | ||
- The end of the file is the first byte with value 0x00, 0xff or 0x1a, or the 4097th byte, | ||
whichever comes first. |
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.
It's easy to imagine this "settings-file reader" code being useful for multiple projects beyond your wifi-settings-connect library. I wonder if it might be worth splitting it out into a library of its own? (If you have the energy & time, of course 🙂 )
EDIT: Haha, I've just read your later "This can be a useful way to store additional configuration data for your Pico application." line 😁
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.
I have certainly found it useful for more than WiFi settings, but I have been thinking that a filesystem module would be a better solution, being much more general, and also avoiding the problem of having to find unused addresses (as in raspberrypi/pico-sdk#1378 ). Is there a plan to officially adopt a filesystem as part of the SDK? In the hope of enabling this library to use a filesystem in the future, I have turned wifi_settings_get_value_for_key
into a weak symbol so it can be reimplemented in some other way.
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.
Is there a plan to officially adopt a filesystem as part of the SDK?
See https://github.com/raspberrypi/pico-sdk/labels/filesystem
src/rp2_common/wifi_settings_connect/include/wifi_settings/wifi_settings_configuration.h
Outdated
Show resolved
Hide resolved
Thanks for responding to all my comments; your speed of updates has been very commendable 👍 I don't want to give you false hopes though, so I probably ought to let you know that whilst I "help out" by commenting on issues and PRs in |
This Pico library provides a way to store WiFi hotspot details in Flash and connect automatically, avoiding the need to specify build-time flags such as WIFI_SSID and WIFI_PASSWORD, as is required for all of the Pico W WiFi examples in the pico-examples repo.
The library loads WiFi settings from a configurable Flash location. The default is 16kb before the end of Flash, i.e. 0x101fc000 for Pico, 0x0103fc000 for Pico 2. This avoids locations already used for Bluetooth and for the RP2350-E10 workaround.
The library searches for hotspots using cyw43 API functions, and, if a known hotspot is found, uses the details from Flash to connect to it. It will also automatically reconnect if the connection is lost.
This part of the library is useful by itself, and the documentation should also be self-contained, though in some places it does refer to the pico-wifi-settings homepage at https://github.com/jwhitham/pico-wifi-settings where a larger version of the library can be found. Additional features in the full library include support for OTA updates of WiFi settings and firmware, and a setup application for creating the WiFi settings file.
There is a second PR for pico-playground which adds a usage example: raspberrypi/pico-playground#55