Hi,
I'm currently trying to write a simple Wi-Fi driver code that can connect to my Wi-Fi network. I'm building for the nrf7002dk_nrf5340_cpuapp
and am using NCS v2.5.3.
For this, I based my code on Exercise 2 of the Wi-Fi fundementals lesson 2.
However, when I try to run my wifi_connect
function, it returns an error -134.
int8_t wifi_connect(char* ssid, char* passkey) { struct net_if *iface = net_if_get_first_wifi(); if (iface == NULL) { LOG_ERR("No Wi-Fi network interface found!"); return -ENODEV; } struct wifi_connect_req_params params = { .ssid = ssid, .ssid_length = strlen(ssid), .psk = passkey, .psk_length = strlen(passkey), .channel = WIFI_CHANNEL_ANY, .security = WIFI_SECURITY_TYPE_PSK, .mfp = WIFI_MFP_OPTIONAL, .timeout = SYS_FOREVER_MS, }; int err = net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, ¶ms, sizeof(params)); if (err) { LOG_ERR("Wi-Fi Connection Failed (Error: %d)", err); return err; } LOG_INF("Connecting to Wi-Fi: %s", ssid); return 0; }
When stepping into the
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); if (wifi_mgmt_api == NULL || wifi_mgmt_api->connect == NULL) { return -ENOTSUP; }
When I look at wifi_mgmt_api
, I see that there is data in it, but not in wifi_mgmt_api->connect
. It does, however, contain data in the scan
variable.
I think it has something to do with the iface
, but I can't find anything about it online.
Could someone please explain to me how the iface
works,
what determines whether wifi_mgmt_api->connect
is populated,
and what might cause it to not want to connect to Wi-Fi?
#wifi settings CONFIG_WIFI=y CONFIG_WIFI_NRF700X=y CONFIG_NET_L2_WIFI_MGMT=y CONFIG_NET_CONFIG_SETTINGS=y # Networking CONFIG_NETWORKING=y CONFIG_NET_L2_ETHERNET=y CONFIG_NET_NATIVE=n CONFIG_NET_OFFLOAD=y CONFIG_NET_SOCKETS=y CONFIG_NET_IPV6=y CONFIG_NET_IPV4=y CONFIG_NET_UDP=y CONFIG_NET_TCP=y # Enable network management CONFIG_NET_MGMT=y CONFIG_NET_MGMT_EVENT=y CONFIG_INIT_STACKS=y # Memory and Stack Settings CONFIG_HEAP_MEM_POOL_SIZE=25000 CONFIG_MAIN_STACK_SIZE=4096 CONFIG_INIT_STACKS=y CONFIG_STACK_SENTINEL=y # Debugging and Logging CONFIG_DEBUG_COREDUMP=y CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y CONFIG_DEBUG_COREDUMP_MEMORY_DUMP_MIN=y CONFIG_LOG=y # Bluetooth Configuration CONFIG_BT=y CONFIG_BT_BROADCASTER=y CONFIG_BT_OBSERVER=y CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_BUF_ACL_RX_SIZE=151 CONFIG_BT_L2CAP_TX_MTU=147 CONFIG_BT_BUF_ACL_TX_SIZE=151 CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_BONDABLE=n CONFIG_BT_DEVICE_NAME_DYNAMIC=y # NFC Configuration CONFIG_NFC_T4T_NRFXLIB=y CONFIG_NFC_NDEF=y CONFIG_NFC_NDEF_MSG=y CONFIG_NFC_NDEF_RECORD=y CONFIG_NFC_NDEF_LE_OOB_REC=y CONFIG_NFC_NDEF_CH_MSG=y CONFIG_NFC_NDEF_TNEP_RECORD=y CONFIG_NFC_TNEP_TAG=y CONFIG_NFC_NDEF_PARSER=y CONFIG_NFC_NDEF_CH_PARSER=y CONFIG_NFC_NDEF_LE_OOB_REC_PARSER=y CONFIG_NFC_TNEP_CH=y # System Settings CONFIG_NEWLIB_LIBC=y CONFIG_REBOOT=y # Enable UART driver CONFIG_SERIAL=y CONFIG_UART_ASYNC_API=y CONFIG_UART_CONSOLE=y # Enable UART console