-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
base: master
Are you sure you want to change the base?
Conversation
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
Hello, I tried to change my Strangely, I can see that the device can connect really fast in some cases (around 1/2s as you stated), but it can take the same time as before in other cases after waking up from deep sleep. Can you please share your setup, so that I can try testing it as well? Thanks |
@alessiocappa Seems like an issue that was fixed by #274. Have you used them both? |
Thanks, I didn't notice that the branch used for the PR was not up to date with the main one. Not sure what could be the reason behind this, I can share my |
You can enable debug logging and include an example output when this issue occurs. |
Thanks for the feedback, but I cannot seem to get any debug information related to WiFi using the wireless logging option. I don't think there is a way to get such information without connecting the device via serial port; I'll try to see if I can do it to better understand what's happening. Another thing I noticed is that it seems like this problem appears only if I close/open the sensor shortly after the device goes into deep sleep; if I wait a bit more time (like a couple of minutes), it seems to connect quicker to the WiFi network. |
Yes, you definitely need to connect it via serial. Also, maybe turning on the debugging of libretiny itself is going to be required. Just an example to consider:
|
Actually there might be a chance to see this debug info without serial - see my buff_log component. |
any news? I have tried use this solution but my esp says that remote branch doe's not exists |
@devgs |
@kuba2k2 It's a valid HEX exactly 64 bytes long. The passphrase length is limited to 63 bytes. For exactly this reason: to be able to easily distinguish them:
|
Ah, I was still ambiguous. I mean it's all handled internally by the BDK or even some lower layer. What I said above is what I saw in the source code and that has motivated me to experiment with it and achieve this nice speedup. |
Also, the code in |
The only difference in this fixup is the use of large enough buffer (on stack) when supplying And the reason for an explicit |
Oh - my bad. I assumed the actual PSK (binary data) was 64 bytes long, then a 0x00 byte inside would cause problems. But if the 64-byte long string is an ASCII hex representation - it should be fine indeed :) |
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