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

Feature/psk as wifi password #2

Merged

Conversation

Cossid
Copy link
Owner

@Cossid Cossid commented Apr 19, 2024

No description provided.

This is a feature that's already supported by ESP devices. However, in case of
Tuya devices (at least for BK7231N) it's invaluable as it can reduce the connect
time by 4 seconds or more. It's all because in order to start negotiation, each
client is required to derive the PSK that is a function of SSID and Password.
And it's a deterministic function: it can be calculated once, stored somewhere
and used many times for the same pair of SSID and Password. Actually, looking at
BDK it's obvious that native firmware does exactly that. It even has a caching
system that from looks of it is capable of storing multiple records.

Saving and restoring connection parameters is a more complex feature that is not
implemented by this PR. However, it can now be easily done with the fixes made
in `bk_wlan_start_sta_adv_fix`. This PR allows user to manually pre-calculate
PSK for each of hist networks and use them instead of plain passwords in YAML.
Which already works with ESP32/ESP8266, but raises `Passphrase too long` error
in LibreTiny: all due to BDK limitations that are now circumvented.

On my cb3s based door sensor, using `fast_connect: true` with pre-calculated PSK
I have managed to achieve a boot-to-mqtt-and-sleep time that is faster than the
original firmware (probably because of higher latency): around 1.25-1.40s. Using
a fixed BSSID and channel can push it down 1s or less.

Additionally, this PR removes the need for two supplemental config structs in
WiFiClass, STA_CFG and STA_ADV_CFG, in favor of the latter.

More info on PSK can be found here: https://jorisvr.nl/wpapsk.html
@Cossid Cossid merged commit 248b76d into Cossid:wifi-improvements-combined Apr 19, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants