-
Notifications
You must be signed in to change notification settings - Fork 183
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
Problems trying to reconnect to WIFI using NVS #304
Comments
Well i think with the information you gave, one cant really help here. First why do you think the NVS has anything to do with your problem? And you are talking about few months ago? What does that mean? You are using esp-idf-* versions from a view months ago? You need to give some more information about your complete setup, what esp-idf versions are you using, how you assemble your project with regarding to wifi etc. Without that i think there is nothing really what others can help here if you are that vague. |
Sorry, I really wasn't very clear. The project was run using version 5.1, so with the errors happening I also tried running it on version 4.4 but without success. To execute the project, I am using an Esp32 Dev Kit. For the code, I use an NVS partition to store the WIFI data and I created another partition (because I thought the error could be related to a conflict of writing to the same partition) to store values that must be remembered as soon as it boots. I then used:
Any additional information you need, I will send. Thank you! |
Can you paste a short code snippet please which outlines what is supposed to work and doesn't? As in what methods exactly you are calling of the Wifi driver? |
This is the part I create and call the driver:
The problem is that it is not reconnecting to the internet when I use NVS at the same time on a second boot:
The system appears to initialize the WIFI as an access point, which wouldn't be what I want. Well, any more details you need I will send. Thank you very much for now! |
its not good practice to just use core::mem::forget on an object you want to possible use on the complete lifetime of your app. Also note that the wifi example itself is only a basic setup. If you want to react on different states your wifi might be in, it is always recommended to listen to the specific wifi-events and act on them. You can find all wifi-events here. You can subscribe to this events through the sysloop.subscribe() method. It looks rougly like that:
sysloop.subscribe::<WifiEvent>(move |event| {
if *event == WifiEvent::<SPECIFIC WIFI EVENT VARIANT>{
// your event handling code
} you can get more fancy than that, using other eventloop mechanisms / notifications. But this will let you react on things on runetime. If you are in an undesirable state you can try to force a new connection or just reboot or do whatever to handle it. Also if you are not using an async runtime / executor, try to use normal blocking rust calls to make your life easier at this stage. |
Hello Vollbrecht I sincerely appreciate the response! Would there be a link to specific documentation on the method of use? I believe this way is right, correct?
If it doesn't create a station, it will restart soon so that the next time it reconnects normally, right? Thanks again for your time! |
For an overall overview check out the official esp-idf documentation. Keep in mind that there are many EspWifi Events. You can find out what emits specific events by searching for "wifi_event" inside that linked documentation. You should not blindly just reboot on any wifievent you get that is not StaConnected. |
Goodnight! This is already a huge help, so I will focus more on these details. |
Hello, For me this behaviour seems to be triggered whenever the system resets while connected to a network. I noticed this across multiple projects utilizing the esp32c3 which use more or less the stock blocking wifi example with some gpio (spi, ...) and mqtt functionality added. I haven't validated that this happens when the connection drops out, but had some devices randomly stuck at the connect step without a manual reset (probably my code panicked when the connection dropped and thus had a soft reset). To be complete, following are the relevant dependencies and idf versions I use:
|
I have a possibly related problem. The very first
The problem occurs both with and without NVS. The reset button or CTRL+R always fixes this. This didn't happen before with ESP-IDF v4. The same problem appears when the connection is lost so the following code for reconnecting didn't work: sysloop.subscribe(move |parsed_event: &WifiEvent| {
if *parsed_event == WifiEvent::StaDisconnected {
wifi.connect.unwrap();
}
})?; I ended up with this hack, that works for both the initial connect and the reconnect: pub trait WifiConnectFix {
fn connect_with_retry(&mut self, retry_delay_ms: u64) -> anyhow::Result<()>;
}
pub fn sleep_ms(ms: u64) {
thread::sleep(Duration::from_millis(ms));
}
impl WifiConnectFix for BlockingWifi<EspWifi<'_>> {
fn connect_with_retry(&mut self, retry_delay_ms: u64) -> anyhow::Result<()> {
loop {
info!("Connecting wifi...");
match self.connect() {
Ok(()) => break,
Err(e) => {
warn!(
"Wifi connect failed, reason {}, retrying in {}s",
e,
retry_delay_ms / 1000
);
sleep_ms(retry_delay_ms);
self.stop()?;
self.start()?;
}
}
}
info!("Waiting for DHCP lease...");
self.wait_netif_up()?;
Ok(())
}
} I'm using ESP-IDF [dependencies]
anyhow = { version = "1.0.75", features = ["backtrace"] }
embedded-hal = "0.2.7"
embedded-svc= "0.26.2"
esp-idf-svc = "0.47.3"
log = "0.4.20"
[build-dependencies]
dotenv-build = "0.1.1"
embuild = "0.31.4" |
I observed the behaviour a little further and noticed this bug isn't consistent across different wifi networks. As far as I can tell without testing it thoroughly, it works without problems on some networks, but has problems on other ones. (I have problems on my home network but not on the local hackerspaces network for example.) |
Hello everybody. I recently carried out some tests on how the chip works, and as @embediver said, it appears to work perfectly on some networks. unsafe { esp_idf_svc::sys::vTaskDelay(10) };
let _ = nvs_data.clone().lock().unwrap().set_str(your_tag, data.trim_end_matches(char::from(0)));
unsafe { esp_idf_svc::sys::vTaskDelay(10) }; and set after the wifi instance as Power Save 0: let mut wifi = AsyncWifi::wrap(
EspWifi::new(peripherals.modem, sys_loop.clone(), Some(nvs)).unwrap(),
sys_loop,
imer_service
).unwrap();
// set Power Save 0 below
unsafe {
esp_idf_svc::sys::esp_wifi_set_ps(esp_idf_svc::sys::wifi_ps_type_t_WIFI_PS_NONE);
} I was only able to "solve" it by making these additions to the code. I don't know if it would be ideal, but it's working. |
Hi, |
Folks, can you try with |
Unfortunately, even master doesn't fix the problem for me.
|
How are you using |
FYI In my case, this problem disappeared once I bought a new router (TP-Link Archer AX72 Pro) |
I'm not entirely sure. I actually only specified the github link in my Cargo.toml and set branch to master. Is that correct? |
You need to show the relevant part of |
Yes of course
But im running into an error now: Deactivating the features lets it build but I think that this is not intended. |
No not this way. Revert to the released versions and then add this to your [patch.crates-io]
esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf-svc" }
esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf-hal" }
esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf-sys" }
cmake = { git = "https://github.com/ivmarkov/cmake-rs" } |
Thanks! It seems to resolve the error. Will have a closer look in future. |
Good afternoon!
A few months ago I was trying to resolve an error that persists when using another NVS partition and the Wifi does not reconnect automatically. Only working after a manual reboot.
I'm using the standard Esp libs, following similar to the lib examples folder.
I (8345) wifi:new:<11,2>, old:<1,0>, ap:<255,255>, sta:<11,2>, prof:1 I (9095) wifi:state: init -> auth (b0) I (9095) wifi:state: auth -> init (8a0) I (9095) wifi:new:<11,0>, old:<11,2>, ap:<255,255>, sta:<11,2>, prof:1
Problem above.
I would appreciate any possible advice on how to solve this problem.
Thanks!
The text was updated successfully, but these errors were encountered: