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

fix(bsc): wifi connection; need to wait until the status is right #84

Closed
wants to merge 20 commits into from

Conversation

amanjeev
Copy link
Contributor

I was trying to flash my esp32-c3 board and while I was successful at that, my wifi did not connect.

It turns out that the code in the bsc vendoered lib did not lend way to check for the status in a loop until it is either connected of disconnected. This is unhelpful because there are three states of the connection status enum and one of them is Connecting which may take a few ms.

Caveat: I am new to this so I did what I thought was the right thing. Please help improve this if you think I made a mistake.

Copy link
Contributor

@Dajamante Dajamante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

previous commit was using a custom loop but this PR comment[1] points to
a better way `wait_status_with_timeout` method. this method was dependent
upon using the latest versions of the dependencies, esp. esp-idf-svc.
Without these updates to respective crates, Cargo was unhappy with conflicts
of base crates like embeddad-hal.

[1] #84 (comment)
@amanjeev
Copy link
Contributor Author

This works now, thanks to you all - @Dajamante , @justahero and @SergioGasquez. I see wifi connecting and the output is

…dware-check  on  amanjeev/flashing-and-wifi-connection is 📦 v0.1.0 via 🦀 v1.61.0-nightly took 28s 
at 13:57:29  ❤  RUST_LOG=info cargo espflash --release --monitor /dev/ttyACM0
Serial port: /dev/ttyACM0
Connecting...

    Finished release [optimized] target(s) in 0.06s
Chip type:         ESP32-C3 (revision 3)
Crystal frequency: 40MHz
Flash size:        4MB
Features:          WiFi
MAC address:       60:55:f9:c0:1f:c0
[00:00:00] ########################################      12/12      segment 0x0
[00:00:00] ########################################       1/1       segment 0x8000
[00:00:07] ########################################     412/412     segment 0x10000

Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit
......snip.......
I (7361) esp_idf_svc::wifi: STA IP event DhcpIpAssigned(DhcpIpAssignment { netif_handle: 0x3fca477c, ip_settings: ClientSettings { ip: 192.168.1.148, subnet: Subnet { gateway: 192.168.1.1, mask: Mask(24) }, dns: None, secondary_dns: None }, ip_changed: true }) handled, set status: Status(Started(Connected(Done(ClientSettings { ip: 192.168.1.148, subnet: Subnet { gateway: 192.168.1.1, mask: Mask(24) }, dns: None, secondary_dns: None }))), Stopped)
I (7401) esp_netif_handlers: sta ip: 192.168.1.148, mask: 255.255.255.0, gw: 192.168.1.1
I (7411) esp_idf_svc::wifi: Waiting for status done - success
I (7421) esp_idf_svc::wifi: Providing status: Status(Started(Connected(Done(ClientSettings { ip: 192.168.1.148, subnet: Subnet { gateway: 192.168.1.1, mask: Mask(24) }, dns: None, secondary_dns: None }))), Stopped)
I (7431) esp32_c3_dkc02_bsc::wifi: Wifi connected
I (8441) hardware_check: Hello, world!
I (10441) hardware_check: Hello, world!
I (12441) hardware_check: Hello, world!
I (14441) hardware_check: Hello, world!

@BriocheBerlin , @Mirabellensaft could you please try my branch too and maybe it works?

@Dajamante maybe flashing may work for you this time?

@amanjeev
Copy link
Contributor Author

I am not sure why there is a cargo deps conflict in the docker check test run. this does not happen to me on my local.

@9names
Copy link
Contributor

9names commented Jul 30, 2022

The conflict doesn't show when running intro/hardware-check or intro/hello-world, but it does for me when trying to build intro/http-client/exercise

@SergioGasquez
Copy link
Member

I am not sure why there is a cargo deps conflict in the docker check test run. this does not happen to me on my local.

You may need to update the dependencies in all the projects, as common/lib/esp32-c3-dkc02-bsc crate gets used in all of them (or most of them, if I recall properly).
I am currently ooo but looking at the modified files and with @9names comment it looks like that should be the issue.

@9names
Copy link
Contributor

9names commented Jul 30, 2022

I made a PR against this PR branch, forgot that the branch was on the main repo - I'm more used to the fork and branch model

@amanjeev amanjeev marked this pull request as draft July 31, 2022 13:55
@Mirabellensaft
Copy link
Contributor

with this branch, my wifi works! Can you rebase, so it's on the same state as main, minus your changes? Just to make sure it fixed the right issue

@amanjeev
Copy link
Contributor Author

amanjeev commented Aug 2, 2022

@Mirabellensaft I rebased and pushed but now i see stuff 🙈 i did not commit...

@SergioGasquez
Copy link
Member

Hello! I was ooo for a few days, can someone update me on the state of this PR? Why it was changed to draft?

Thanks in advance!

9names pushed a commit to 9names/espressif-trainings that referenced this pull request Aug 9, 2022
previous commit was using a custom loop but this PR comment[1] points to
a better way `wait_status_with_timeout` method. this method was dependent
upon using the latest versions of the dependencies, esp. esp-idf-svc.
Without these updates to respective crates, Cargo was unhappy with conflicts
of base crates like embeddad-hal.

[1] esp-rs#84 (comment)
@amanjeev
Copy link
Contributor Author

@SergioGasquez it was changed to draft primarily because this PR/branch is being used to test the material internally. Until our checks are all green, it was suggested this be draft. Fear not, this will be merged once all the folks at FS have finished their checks.

cc/ @Mirabellensaft @justahero

@SergioGasquez
Copy link
Member

@amanjeev Thanks for the update! I think merging #85 would make the CI tests pass.

@amanjeev
Copy link
Contributor Author

@SergioGasquez we have pinged on the #85 already but not sure why #85 is a draft as well?

@markfarnan
Copy link

markfarnan commented Aug 11, 2022

FYI, I have a related issue, which this PR seems to PARTIALY fix.

Currently, when flashing/monitoring via the USB/JTAG port, the Wifi dosn't connect.

  • Stopping the monitor and resetting board, WIFI connects fine
  • using the normal USB port with monitor, WIFI connects fine
  • Using USB/JTAG, Wifi won't connect with either monitor running, or OpenOCD Debug running.

Testing with this PR, USB/JTAG with monitor, Wifi now connects about 75% of the time, (three out of four tries it works, one it fails.) So much more reliable, but not always.

Can actually debug now with this PR, with Wifi connecting. (generally).

Trace from a fail in case it is usefull:
I (3572) esp_idf_svc::wifi: About to wait 2100s for status
I (3572) wifi:state: assoc -> run (10)
I (3592) esp_idf_svc::wifi: Timeout while waiting for status
I (3592) wifi:connected with Gumtrees, aid = 2, channel 1, BW20, bssid = 78:8a:20:da:6f:97
I (3602) wifi:security: WPA2-PSK, phy: bgn, rssi: -51
I (3602) wifi:pm start, type: 1
I (3602) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
I (3612) esp_idf_svc::wifi: Got wifi event: StaConnected
I (3622) esp_idf_svc::wifi: STA event StaConnected handled, set status: Status(Started(Connected(Waiting)), Stopped)
I (3632) esp_idf_svc::wifi: Stopping
I (3632) wifi:state: run -> init (0)
I (3642) wifi:pm stop, total sleep time: 0 us / 33289 us
I (3642) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
I (3652) esp_idf_svc::wifi: Disconnect requested
I (3662) wifi:flush txq
I (3662) wifi:stop sw txq
I (3662) wifi:lmac stop hw txq
I (3662) esp_idf_svc::wifi: Stop requested
I (3672) esp_idf_svc::wifi: About to wait for status
I (3672) esp_idf_svc::wifi: Got wifi event: StaDisconnected
I (3682) esp_idf_svc::wifi: STA event StaDisconnected handled, set status: Status(Started(Disconnected), Stopped)
I (3692) esp_idf_svc::wifi: Got wifi event: StaStopped
I (3702) esp_idf_svc::wifi: STA event StaStopped handled, set status: Status(Stopped, Stopped)
I (3702) esp_idf_svc::wifi: Waiting for status done - success
I (3712) esp_idf_svc::wifi: Stopped
I (3722) esp_idf_svc::wifi: Event handlers deregistered
I (3722) wifi:Deinit lldesc rx mblock:10
I (3732) esp_idf_svc::wifi: Driver deinitialized
I (3732) esp_idf_svc::wifi: Deinitialization complete
I (3742) esp_idf_svc::wifi: Dropped
I (3742) esp_idf_svc::nvs: Dropped
I (3742) esp_idf_svc::eventloop: Dropped
I (3752) esp_idf_svc::netif: Dropped
Error: could not connect to Wi-Fi network: Unexpected Wifi status (Transitional state): Status(Started(Connecting), Stopped)

Note: There is no 'delay' when it is waiting for status, it seems to blow right through that line. Certainly dosn't wait 2100s !

9names pushed a commit to 9names/espressif-trainings that referenced this pull request Aug 15, 2022
previous commit was using a custom loop but this PR comment[1] points to
a better way `wait_status_with_timeout` method. this method was dependent
upon using the latest versions of the dependencies, esp. esp-idf-svc.
Without these updates to respective crates, Cargo was unhappy with conflicts
of base crates like embeddad-hal.

[1] esp-rs#84 (comment)
BriocheBerlin pushed a commit that referenced this pull request Aug 24, 2022
previous commit was using a custom loop but this PR comment[1] points to
a better way `wait_status_with_timeout` method. this method was dependent
upon using the latest versions of the dependencies, esp. esp-idf-svc.
Without these updates to respective crates, Cargo was unhappy with conflicts
of base crates like embeddad-hal.

[1] #84 (comment)
BriocheBerlin pushed a commit that referenced this pull request Sep 2, 2022
previous commit was using a custom loop but this PR comment[1] points to
a better way `wait_status_with_timeout` method. this method was dependent
upon using the latest versions of the dependencies, esp. esp-idf-svc.
Without these updates to respective crates, Cargo was unhappy with conflicts
of base crates like embeddad-hal.

[1] #84 (comment)
@Dajamante
Copy link
Contributor

Solved by #99

@Dajamante Dajamante closed this Sep 6, 2022
@SergioGasquez SergioGasquez deleted the amanjeev/flashing-and-wifi-connection branch March 17, 2023 14:47
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.

8 participants