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

Added ability to specify WPA2 PSK in place of WiFi password #276

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

devgs
Copy link
Contributor

@devgs devgs commented Apr 7, 2024

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

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
@kuba2k2 kuba2k2 added enhancement New feature or request BK7231 Beken BK72xx family labels Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BK7231 Beken BK72xx family enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants