Hello,
I am attempting to connect to a Wi-Fi network using Exercise 2 from Lesson 2 of the Wi-Fi training in Nordic Academy. However, when I try to connect to the network, I encounter a -134 error while executing the following function:
net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, sizeof(struct wifi_connect_req_params));
Here's my main.c
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/types.h>
#include <zephyr/logging/log.h>
#include <dk_buttons_and_leds.h>
/* STEP 3 - Include the necessary header files */
#include <zephyr/net/wifi.h>
#include <zephyr/net/wifi_mgmt.h>
#include <zephyr/net/net_mgmt.h>
#include <net/wifi_mgmt_ext.h>
/* STEP 12.4 - Include the header file for the Wi-FI credentials library */
#include <net/wifi_credentials.h>
LOG_MODULE_REGISTER(Lesson2_Exercise2, LOG_LEVEL_INF);
/* STEP 4 - Define a macro for the relevant network events */
#define EVENT_MASK (NET_EVENT_L4_CONNECTED | NET_EVENT_L4_DISCONNECTED)
/* STEP 5 - Declare the callback structure for Wi-Fi events */
static struct net_mgmt_event_callback mgmt_cb;
/* STEP 6.1 - Define the boolean connected and the semaphore run_app */
static bool connected;
static K_SEM_DEFINE(run_app, 0, 1);
/* STEP 6.2 - Define the callback function for network events */
static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
if ((mgmt_event & EVENT_MASK) != mgmt_event) {
LOG_ERR("Event is not CONN | DISCONN");
return;
}
if (mgmt_event == NET_EVENT_L4_CONNECTED) {
LOG_INF("Network connected");
connected = true;
dk_set_led_on(DK_LED1);
k_sem_give(&run_app);
return;
}
if (mgmt_event == NET_EVENT_L4_DISCONNECTED) {
if (connected == false) {
LOG_INF("Waiting for network to be connected");
} else {
dk_set_led_off(DK_LED1);
LOG_INF("Network disconnected");
connected = false;
}
k_sem_reset(&run_app);
return;
}
}
/* STEP 7 - Define the function to populate the Wi-Fi credential parameters */
static int wifi_args_to_params(struct wifi_connect_req_params *params)
{
/* STEP 7.1 Populate the SSID and password */
params->ssid = CONFIG_WIFI_CREDENTIALS_STATIC_SSID;
params->ssid_length = strlen(params->ssid);
params->psk = CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD;
params->psk_length = strlen(params->psk);
/* STEP 7.2 - Populate the rest of the relevant members */
params->channel = WIFI_CHANNEL_ANY;
params->security = WIFI_SECURITY_TYPE_PSK;
params->mfp = WIFI_MFP_OPTIONAL;
params->timeout = SYS_FOREVER_MS;
params->band = WIFI_FREQ_BAND_5_GHZ;
#if NCS_VERSION_NUMBER > 0x20600
memset(params->bssid, 0, sizeof(params->bssid));
#endif
return 0;
}
int main(void)
{
/* STEP 8.1 - Declare the variable for the network configuration parameters */
struct wifi_connect_req_params cnx_params;
/* STEP 8.2 - Get the network interface */
struct net_if *iface = net_if_get_first_wifi();
if (iface == NULL) {
LOG_ERR("Returned network interface is NULL");
return -1;
}
LOG_INF("Hello this is connect wifi sample");
if (dk_leds_init() != 0) {
LOG_ERR("Failed to initialize the LED library");
}
/* Sleep to allow initialization of Wi-Fi driver */
k_sleep(K_SECONDS(1));
/* STEP 9 - Initialize and add the callback function for network events */
net_mgmt_init_event_callback(&mgmt_cb, net_mgmt_event_handler, EVENT_MASK);
net_mgmt_add_event_callback(&mgmt_cb);
/* STEP 10 - Populate cnx_params with the network configuration */
wifi_args_to_params(&cnx_params);
/* STEP 11 - Call net_mgmt() to request the Wi-Fi connection */
LOG_INF("Connecting to Wi-Fi");
int err;
while(true){
err = net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, &cnx_params, sizeof(struct wifi_connect_req_params));
if (!err) {
LOG_INF("Connecting to Wi-Fi succesfull, err: %d", err);
break;
}
LOG_ERR("Failed to connect to Wi-Fi, err: %d", err);
LOG_INF("Trying again in 1 second...");
k_sleep(K_SECONDS(1));
}
k_sem_take(&run_app, K_FOREVER);
return 0;
}
my prj.conf :
# # Copyright (c) 2022 Nordic Semiconductor ASA # # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause # # Wi-Fi # STEP 1.1 - Enable the Wi-Fi relevant configurations CONFIG_WIFI=y CONFIG_WIFI_NRF700X=y CONFIG_WPA_SUPP=y # STEP 2 - Configure the Wi-Fi credentials CONFIG_WIFI_CREDENTIALS=y # STEP 12.1 - Diasble static Wi-Fi network configuration CONFIG_WIFI_CREDENTIALS_STATIC=y CONFIG_WIFI_CREDENTIALS_STATIC_SSID="WIFI_NINA" CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="TERRAPERAMERA!" # Networking Management API # STEP 1.2 Enable the Network Management relevant configurations CONFIG_NET_MGMT=y CONFIG_NET_MGMT_EVENT=y CONFIG_NET_MGMT_EVENT_INFO=y CONFIG_NET_MGMT_EVENT_STACK_SIZE=16384 CONFIG_NET_CONNECTION_MANAGER=y CONFIG_WIFI_MGMT_EXT=y # STEP 13 Enable support for shell commands # CONFIG_SHELL=y # CONFIG_WIFI_CREDENTIALS_SHELL=y # CONFIG_SHELL_STACK_SIZE=4400 # Logging CONFIG_LOG=y # DK library CONFIG_DK_LIBRARY=y # System settings CONFIG_NEWLIB_LIBC=y CONFIG_NEWLIB_LIBC_NANO=n # Networking CONFIG_NETWORKING=y CONFIG_NET_NATIVE=y CONFIG_NET_SOCKETS=y CONFIG_NET_L2_ETHERNET=y CONFIG_NET_IPV6=n CONFIG_NET_IPV4=y CONFIG_NET_DHCPV4=y CONFIG_NET_BUF_RX_COUNT=16 CONFIG_NET_BUF_TX_COUNT=16 CONFIG_NET_BUF_DATA_SIZE=128 CONFIG_NRF700X_RX_NUM_BUFS=16 CONFIG_NRF700X_MAX_TX_AGGREGATION=4 # nRF700x is main consumer: (16 + 8) * 1600 = ~40KB + ~40KB control path (experimental) CONFIG_NET_TC_TX_COUNT=1 # Memory CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 CONFIG_MAIN_STACK_SIZE=4096 CONFIG_HEAP_MEM_POOL_SIZE=80000 CONFIG_NET_TX_STACK_SIZE=4096 CONFIG_NET_RX_STACK_SIZE=4096 CONFIG_COMMON_LIBC_MALLOC=y CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=30000 CONFIG_WIFI_FIXED_MAC_ADDRESS="04:E8:B9:5C:E0:27"
my .conf of t91x :
# STEP 12.3 - Create a board-specific file for the secure build target CONFIG_WIFI_CREDENTIALS_BACKEND_SETTINGS=y CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_SETTINGS_NVS=y
Could you provide guidance or suggest a solution to resolve this issue?
Best regards,
Youssef