esp32 doesnt connect to AP when using my WIFI, but it does if I use my cellphone hotspot

AlexIbarra04
Posts: 1
Joined: Tue Jun 16, 2020 7:20 pm

esp32 doesnt connect to AP when using my WIFI, but it does if I use my cellphone hotspot

Postby AlexIbarra04 » Tue Jun 16, 2020 7:24 pm

Hello,

My ESP32 connects and gets an IP address when I try to use my cellphone hotspot but it doesnt connect when trying to use my home wifi. When trying to use the home wifi, it says AP was not found. Does anyone can provide any help on this? I need it to connect to my home's wifi.

Here is the code I use:
  1. #include <freertos/FreeRTOS.h>
  2. #include <esp_wifi.h>
  3. #include <esp_system.h>
  4. #include <esp_event.h>
  5. #include <esp_event_loop.h>
  6. #include <nvs_flash.h>
  7. #include <tcpip_adapter.h>
  8.  
  9. esp_err_t event_handler(void *ctx, system_event_t *event)
  10. {
  11.     if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
  12.         printf("\n\n\nOur IP address is " IPSTR "\n",
  13.                 IP2STR(&event->event_info.got_ip.ip_info.ip));
  14.         printf("We have now connected to a station and can do things...\n\n\n");
  15.      }
  16.     if (event->event_id == SYSTEM_EVENT_STA_START) {
  17.         ESP_ERROR_CHECK(esp_wifi_connect());
  18.         printf("\n\n\nevent started\n\n\n");
  19.     }
  20.     return ESP_OK;
  21. }
  22.  
  23.  
  24. int app_main(void)
  25. {
  26.    
  27.     nvs_flash_init();
  28.     tcpip_adapter_init();
  29.     ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
  30.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  31.     ESP_ERROR_CHECK(esp_wifi_init(&cfg) );
  32.     ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
  33.     ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_APSTA));
  34.     wifi_config_t sta_config = {
  35.             .sta = {
  36.                      .ssid = "<wifi name here>",
  37.                      .password = "<password here>",
  38.                      .bssid_set = 0
  39.             }
  40.     };
  41.     ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config));
  42.     ESP_ERROR_CHECK(esp_wifi_start());
  43.     return 0;
  44. }

Who is online

Users browsing this forum: Google [Bot] and 100 guests