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

Wifi(init): Unexpected behavior when initializing subsystems (IDFGH-12651) #13643

Open
3 tasks done
safocl opened this issue Apr 18, 2024 · 7 comments
Open
3 tasks done
Assignees
Labels
Status: Opened Issue is new

Comments

@safocl
Copy link

safocl commented Apr 18, 2024

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

This line is misleading because it expects initialization with the config attached, but if the subsystem is already initialized it simply returns ESP_OK. From which it is not clear whether the attached config was applied or not. But the API does not provide the ability to check whether the subsystem was initialized earlier.

Perhaps we should return a code that signals that the subsystem is already running?

@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 18, 2024
@github-actions github-actions bot changed the title Wifi(init): Unexpected behavior when initializing subsystems Wifi(init): Unexpected behavior when initializing subsystems (IDFGH-12651) Apr 18, 2024
@KaeLL
Copy link
Contributor

KaeLL commented Apr 18, 2024

#8745 Welcome to the club

@mhdong
Copy link
Collaborator

mhdong commented May 13, 2024

Hi @KaeLL
It is recommended that if you want to reapply the new configuration in WiFi init, you first need to do WiFi deinit. Adding new error codes may damage certain applications. And we will update the document to describe this.

@safocl
Copy link
Author

safocl commented May 13, 2024

Hi @KaeLL It is recommended that if you want to reapply the new configuration in WiFi init, you first need to do WiFi deinit. Adding new error codes may damage certain applications. And we will update the document to describe this.

Why then are return codes needed at all, if everything is recommended in the documentation? This turns out to be an extra binary code.
Here the function returns the status OK, even when in reality the status is not OK (the action had no effect).

@safocl
Copy link
Author

safocl commented May 13, 2024

Hi @KaeLL It is recommended that if you want to reapply the new configuration in WiFi init, you first need to do WiFi deinit. Adding new error codes may damage certain applications. And we will update the document to describe this.

The esp_wifi_deinit function will return ESP_ERR_WIFI_NOT_INIT when wifi is not inited. From which it follows that without knowing whether Wi-Fi was launched earlier, it is not clear whether esp_wifi_deinit can be used or not.

esp_err_t esp_wifi_deinit(void)

@safocl
Copy link
Author

safocl commented May 13, 2024

Maybe we should introduce a bool wifi_is_inited() check function?
bool esp_wifi_is_inited(){ return s_wifi_inited; }

@mhdong
Copy link
Collaborator

mhdong commented May 14, 2024

Hi @safocl
Yes,you can introduce a bool wifi_is_reset_init_config(const wifi_init_config_t *new_config) to check.
bool wifi_is_reset_init_config(const wifi_init_config_t *new_config) { if(global_old_config same as new_config) { return true; } else { return false; } }

Change in the esp_wifi_init function
if (s_wifi_inited && wifi_is_reset_init_config(config)) { return ESP_OK; } else { /*Prompt call deinitit then return. Or directly call deinit to continue the subsequent process*/ }
We suggest that users do not modify the init config.

@KaeLL
Copy link
Contributor

KaeLL commented May 14, 2024

@mhdong Did you really mean to reply to me? I don't care about reapplying configurations to an already initialized component. What I want is for init functions in IDF to be idempotent (like esp_wifi_init) but also to return a new esp_err_t code signaling that the component has already been initialized.
It's interesting how IDF can be inconsiderate of this issue, given that some components are global, like the default event loop or the GPIO interrupt, and also how inconsistent it can be, given that some components can be lazy-initialized and others can't, esp_wifi_init is idempotent while esp_event_loop_create_default isn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests

4 participants