Quantcast
Viewing all articles
Browse latest Browse all 4899

SDK • Cannot connect to WiFi every second time

When I am connecting a Pico W with the example from VSCode Raspberry Pi project (polled lwIP or backgroud lwIP):

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "pico/cyw43_arch.h"int main(){    stdio_init_all();    // Initialise the Wi-Fi chip    if (cyw43_arch_init()) {        printf("Wi-Fi init failed\n");        return -1;    }    // Enable wifi station    cyw43_arch_enable_sta_mode();    printf("Connecting to Wi-Fi...\n");    if (cyw43_arch_wifi_connect_timeout_ms("SSID", "Password", CYW43_AUTH_WPA2_AES_PSK, 30000)) {        printf("failed to connect.\n");        return 1;    } else {        printf("Connected.\n");        // Read the ip address in a human readable way        uint8_t *ip_address = (uint8_t*)&(cyw43_state.netif[0].ip_addr.addr);        printf("IP address %d.%d.%d.%d\n", ip_address[0], ip_address[1], ip_address[2], ip_address[3]);    }    while (true) {        printf("Hello, world!\n");        sleep_ms(1000);    }}
it succeeds only every second time. "WiFi init failed" in the other times. This "WiFi init failed" appears only some seconds after the connection was started, not after the 30s timeout. I assume, that the connection process starts and there is no internet number supplied by the Fritz-Box (AVM DSL-Router). If I try cyw43_arch_wifi_connect_async instead of cyw43_arch_wifi_connect_timeout_ms it connects every time without error, but every second time the IP-number is 0.0.0.0.

When I am using Micro-Python with this Pico W and my Fritz-Box, the example task from connecting-to-the-internet-with-pico-w:

Code:

import networkimport timewlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect('SSID', 'Password')while not wlan.isconnected() and wlan.status() >= 0:    print("Waiting to connect:")    time.sleep(1)print(wlan.ifconfig())
works without any problems and seems to be very quick.

Statistics: Posted by art51go — Wed Nov 06, 2024 5:08 pm



Viewing all articles
Browse latest Browse all 4899

Trending Articles