Added ability to specify WPA2 PSK in place of WiFi password #276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 raisesPassphrase 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
andSTA_ADV_CFG
, in favor of the latter.More info on PSK can be found here: https://jorisvr.nl/wpapsk.html