91 lines
2 KiB
C
91 lines
2 KiB
C
#include "pico/cyw43_arch.h"
|
|
#include "pico/stdlib.h"
|
|
#include <hardware/watchdog.h>
|
|
#include <pico/time.h>
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* Simple WiFi Connection Test
|
|
* Just connect to WiFi and poll every 5 seconds to check connection status
|
|
*/
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
watchdog_enable(120000, 1); // 120 second watchdog
|
|
|
|
printf("\n=== WiFi Connection Test ===\n");
|
|
printf("Initializing board...\n");
|
|
sleep_ms(2000);
|
|
|
|
printf("Initializing CYW43...\n");
|
|
if (cyw43_arch_init()) {
|
|
printf("FATAL: Failed to initialize CYW43\n");
|
|
while (1) {
|
|
watchdog_update();
|
|
sleep_ms(1000);
|
|
}
|
|
}
|
|
|
|
printf("Enabling WiFi station mode...\n");
|
|
cyw43_arch_enable_sta_mode();
|
|
sleep_ms(1000);
|
|
|
|
printf("Connecting to WiFi '%s'...\n", WIFI_SSID);
|
|
watchdog_update();
|
|
|
|
int result = cyw43_arch_wifi_connect_timeout_ms(
|
|
WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 60000);
|
|
|
|
watchdog_update();
|
|
|
|
if (result != 0) {
|
|
printf("FATAL: WiFi connection failed with result=%d\n", result);
|
|
while (1) {
|
|
watchdog_update();
|
|
sleep_ms(1000);
|
|
}
|
|
}
|
|
|
|
printf("WiFi connected!\n");
|
|
|
|
// Poll every 5 seconds
|
|
absolute_time_t last_check = get_absolute_time();
|
|
|
|
while (1) {
|
|
watchdog_update();
|
|
cyw43_arch_poll();
|
|
|
|
absolute_time_t now = get_absolute_time();
|
|
if (absolute_time_diff_us(last_check, now) >= 5000000) {
|
|
last_check = now;
|
|
|
|
// Check connection status
|
|
int link_status = cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA);
|
|
|
|
printf("[WiFi Status Check]\n");
|
|
printf(" Link Status: ");
|
|
switch (link_status) {
|
|
case CYW43_LINK_DOWN:
|
|
printf("DOWN\n");
|
|
break;
|
|
case CYW43_LINK_JOIN:
|
|
printf("JOINING\n");
|
|
break;
|
|
case CYW43_LINK_NOIP:
|
|
printf("NO IP\n");
|
|
break;
|
|
case CYW43_LINK_UP:
|
|
printf("UP\n");
|
|
break;
|
|
default:
|
|
printf("UNKNOWN (%d)\n", link_status);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
sleep_ms(100);
|
|
}
|
|
|
|
return 0;
|
|
}
|