Skip to content

Commit

Permalink
samples: wifi: sta: Wait for Wi-Fi readiness
Browse files Browse the repository at this point in the history
Update the sample application to check the Wi-Fi readiness
status using the wifi_ready library.

Signed-off-by: Triveni Danda <[email protected]>
  • Loading branch information
D-Triveni committed Jun 4, 2024
1 parent b461e3b commit 5f6b9f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions samples/wifi/sta/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CONFIG_WIFI_NRF700X=y

# WPA supplicant
CONFIG_WPA_SUPP=y
CONFIG_WIFI_READY_EVENT_HANDLING=y

CONFIG_WIFI_MGMT_EXT=y
CONFIG_WIFI_CREDENTIALS=y
Expand Down
39 changes: 38 additions & 1 deletion samples/wifi/sta/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(sta, CONFIG_LOG_DEFAULT_LEVEL);
#include <zephyr/drivers/gpio.h>

#include <net/wifi_mgmt_ext.h>
#include <net/wifi_ready.h>

#include <qspi_if.h>

Expand Down Expand Up @@ -52,6 +53,9 @@ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
static struct net_mgmt_event_callback wifi_shell_mgmt_cb;
static struct net_mgmt_event_callback net_shell_mgmt_cb;

K_SEM_DEFINE(wifi_ready_sem, 0, 1);
static bool wifi_status = false;

Check failure on line 57 in samples/wifi/sta/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

INITIALISED_STATIC

samples/wifi/sta/src/main.c:57 do not initialise statics to false

static struct {
const struct shell *sh;
union {
Expand Down Expand Up @@ -247,7 +251,7 @@ int bytes_from_str(const char *str, uint8_t *bytes, size_t bytes_len)
return 0;
}

int main(void)
int start_app(void)
{
memset(&context, 0, sizeof(context));

Expand Down Expand Up @@ -317,3 +321,36 @@ int main(void)

return 0;
}

void wifi_ready_cb(bool wifi_ready)
{
if (wifi_ready) {
LOG_INF("Wi-Fi is ready");
} else {
LOG_ERR("Wi-Fi is not ready");
}

wifi_status = wifi_ready;
k_sem_give(&wifi_ready_sem);
}

int main(void)
{
app_callback_t callback = {
.is_wifi_ready = wifi_ready_cb,
};

register_supp_events(callback);

LOG_INF("Waiting for Wi-Fi to be ready");
if (k_sem_take(&wifi_ready_sem, K_FOREVER) == 0) {
if (wifi_status) {
start_app();
} else {
LOG_ERR("Wi-Fi is not ready, exiting the sample");
return -1;
}
}

return 0;
}

0 comments on commit 5f6b9f6

Please sign in to comment.