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

NOT CONNECTING TO WIFI WHEN PASSING AS PARAMETERS BY CREATING AS FUNCTION (IDFGH-8623) #10070

Closed
3 tasks done
beginner140BB opened this issue Oct 28, 2022 · 3 comments
Closed
3 tasks done
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally

Comments

@beginner140BB
Copy link

beginner140BB commented Oct 28, 2022

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

I need to create a simple function for wifi initialisation (as AP )using espressif ide platform have found that when passing as arguments its not working.

wifi_config_t wifi_config1 ;
printf("before structure ssid %s\n",wifi_config1.sta.ssid);
printf("before structure pswd %s\n",wifi_config1.sta.password);
strcpy( (char *)wifi_config1.sta.ssid ,ssid);
printf("structure ssid %s\n",wifi_config1.sta.ssid);
strcpy((char *)wifi_config1.sta.password ,pass);
printf("structure pswd %s\n",wifi_config1.sta.password);
wifi_config1.sta.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD;

when printing the structure the ssid and password is there in the array.
don,t know what makes the issue here.

the output log is

before structure ssid ���?���?
�p��?╚ structure pswd �^
structure ssid IDCESP2
structure pswd 12345678
I (658) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (768) wifi:mode : sta (8c:4b:14:7a:e6:f0)
I (768) wifi:enable tsf
I (778) wifi station: wifi_init_sta finished.
I (3188) wifi station: retry to connect to the AP
I (3188) wifi station: connect to the AP fail
I (5598) wifi station: retry to connect to the AP
I (5598) wifi station: connect to the AP fail
I (8008) wifi station: retry to connect to the AP
I (8008) wifi station: connect to the AP fail
I (10408) wifi station: retry to connect to the AP
I (10418) wifi station: connect to the AP fail
I (12818) wifi station: retry to connect to the AP
I (12818) wifi station: connect to the AP fail
I (15228) wifi station: connect to the AP fail
I (15228) wifi station: Failed to connect to SSID:IDCESP2, password:12345678

@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 28, 2022
@github-actions github-actions bot changed the title NOT CONNECTING TO WIFI WHEN PASSING AS ARGUMENTS. NOT CONNECTING TO WIFI WHEN PASSING AS ARGUMENTS. (IDFGH-8623) Oct 28, 2022
@beginner140BB beginner140BB changed the title NOT CONNECTING TO WIFI WHEN PASSING AS ARGUMENTS. (IDFGH-8623) NOT CONNECTING TO WIFI WHEN PASSING AS PARAMETERS. (IDFGH-8623) Oct 28, 2022
@beginner140BB beginner140BB changed the title NOT CONNECTING TO WIFI WHEN PASSING AS PARAMETERS. (IDFGH-8623) NOT CONNECTING TO WIFI WHEN PASSING AS PARAMETERS BY CREATING AS FUNCTION (IDFGH-8623) Oct 28, 2022
@beginner140BB
Copy link
Author

This is the function i am using

`void Wifi_init(const char *ssid, const char *pass)
{
s_wifi_event_group = xEventGroupCreate();

ESP_ERROR_CHECK(esp_netif_init());

ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_sta();

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));

esp_event_handler_instance_t instance_any_id;
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                    ESP_EVENT_ANY_ID,
                                                    &event_handler,
                                                    NULL,
                                                    &instance_any_id));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                    IP_EVENT_STA_GOT_IP,
                                                    &event_handler,
                                                    NULL,
                                                    &instance_got_ip));

wifi_config_t wifi_config ;

printf("before structure ssid %s\n",wifi_config.sta.ssid);
printf("before structure pswd %s\n",wifi_config.sta.password);
strcpy( (char *)wifi_config.sta.ssid ,ssid);
printf("structure ssid %s\n",wifi_config.sta.ssid);
strcpy((char *)wifi_config.sta.password ,pass);
printf("structure pswd %s\n",wifi_config.sta.password);
wifi_config.sta.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD;
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
ESP_ERROR_CHECK(esp_wifi_start() );

ESP_LOGI(TAG, "wifi_init_sta finished.");

/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
 * number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
        WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
        pdFALSE,
        pdFALSE,
        portMAX_DELAY);

/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
 * happened. */
if (bits & WIFI_CONNECTED_BIT) {
    ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
    		ssid, pass);
} else if (bits & WIFI_FAIL_BIT) {
    ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
    		ssid, pass);
} else {
    ESP_LOGE(TAG, "UNEXPECTED EVENT");
}

}`

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new labels Jun 2, 2023
@emaema464
Copy link

HI , please can you share with me the solution of this issue

@beginner140BB
Copy link
Author

beginner140BB commented Jul 25, 2023

HI , please can you share with me the solution of this issue

just pass the parameters and please have a look at the example code in esp-idf

https://sourcegraph.com/github.com/espressif/esp-idf/-/blob/examples/wifi/getting_started/station/main/station_example_main.c

char Wifi_init(char *ssid, char *pass)
{
    wifi_config_t wifi_config = {
        .sta = {
	     .threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
        },
    };
    strcpy( (char *)wifi_config.sta.ssid ,ssid);
    strcpy( (char *)wifi_config.sta.password ,pass);
    
    esp_wifi_set_mode(WIFI_MODE_STA);
    esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
    esp_wifi_start();
    
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants