ZephyrRTOS - esp32c3 can't connect to WiFi when there is any security

Piotrulo1
Posts: 3
Joined: Wed Nov 08, 2023 11:31 am

ZephyrRTOS - esp32c3 can't connect to WiFi when there is any security

Postby Piotrulo1 » Mon Mar 04, 2024 12:56 pm

As in the subject, I can't connect to any network that uses e.g. WPA2, when there is network without password it connects everytime.
connectTo method:
  1. bool WifiDriver::connectTo(const SSIDstring& ssid, const PSKstring& password) {
  2.     if (k_sem_count_get(&connectionSemaphore) > 0) {
  3.         return false;
  4.     }
  5.     strncpy(reinterpret_cast<char*>(_ssid), ssid.c_str(), WIFI_SSID_MAX_LEN);
  6.     _wifiParams.ssid_length = ssid.length();
  7.     strncpy(
  8.         reinterpret_cast<char*>(_password), password.c_str(), WIFI_PSK_MAX_LEN);
  9.     _wifiParams.psk_length = password.length();
  10.  
  11.     _wifiParams.sae_password_length = password.length();
  12.  
  13.     printk("before connection request\n");
  14.     int res = net_mgmt(NET_REQUEST_WIFI_CONNECT,
  15.                  _netInterface,
  16.                  &_wifiParams,
  17.                  sizeof(_wifiParams));
  18.     if (res) {
  19.         printk("connection request failed: %d\n", res, strerror(res));
  20.         return false;
  21.     }
  22.     printk("connection succeded\n");
  23.     _connected = true;
  24.     return true;
  25. }
Init method:
  1. void WifiDriver::init() {
  2.     k_sem_init(&connectionSemaphore, 0, 1);
  3.  
  4.     net_mgmt_init_event_callback(
  5.         &_wifiCallback,
  6.         WifiDriver::wifiCallbackHandler,
  7.         NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT);
  8.  
  9.     net_mgmt_init_event_callback(&_ipv4Callback,
  10.                                  WifiDriver::ipv4CallbackHandler,
  11.                                  NET_EVENT_IPV4_ADDR_ADD);
  12.  
  13.     net_mgmt_add_event_callback(&_wifiCallback);
  14.     net_mgmt_add_event_callback(&_ipv4Callback);
  15.  
  16.     _netInterface = net_if_get_default();
  17.     if (_netInterface == NULL) {
  18.         printk("net_if_get_default failed! No default interface configured!\n");
  19.     }
  20.  
  21.     _wifiParams.ssid = _ssid;
  22.     _wifiParams.ssid_length = 0;
  23.     _wifiParams.psk = _password;
  24.     _wifiParams.psk_length = 0;
  25.     _wifiParams.sae_password = _password;
  26.     _wifiParams.sae_password_length = 0;
  27.     _wifiParams.band = WIFI_FREQ_BAND_2_4_GHZ;
  28.     _wifiParams.channel = WIFI_CHANNEL_ANY;
  29.     _wifiParams.security = WIFI_SECURITY_TYPE_UNKNOWN;
  30.     _wifiParams.mfp = WIFI_MFP_DISABLE;
  31.     _wifiParams.timeout = SYS_FOREVER_MS;
  32.  
  33.     _connected = false;
  34. }
logs:
  1. *** Booting Zephyr OS build v3.6.0 ***
  2.  
  3. [00:00:00.152,000] <inf> net_config: Initializing network
  4.  
  5. [00:00:00.152,000] <inf> net_config: Waiting interface 1 (0x3fcc0b00) to be up.                                                                                                    
  6.  
  7. [00:00:00.153,000] <inf> net_config: Interface 1 (0x3fcc0b00) coming up
  8.  
  9. [00:00:00.153,000] <inf> net_config: Running dhcpv4 client...
  10.  
  11. before connection request
  12.  
  13. connection request failed: -22

Who is online

Users browsing this forum: No registered users and 187 guests