Skip to content

httpd example need a little time sleep before connecting WIFI #726

@FengChendian

Description

@FengChendian
  • Board: pico 2w board

In original httpd example, sleep_ms doesn't exist, and cyw43_arch_wifi_connect_timeout_ms will always return code -7.
If I add some time sleep like sleep_ms(200), it's worked (see "Connected" message with UART Printf). I think maybe cyw43_arch_enable_sta_mode need some time to init hardware.

/////////
    cyw43_arch_enable_sta_mode();

    char hostname[sizeof(CYW43_HOST_NAME) + 4];
    memcpy(&hostname[0], CYW43_HOST_NAME, sizeof(CYW43_HOST_NAME) - 1);
    get_mac_ascii(CYW43_HAL_MAC_WLAN0, 8, 4, &hostname[sizeof(CYW43_HOST_NAME) - 1]);
    hostname[sizeof(hostname) - 1] = '\0';
    netif_set_hostname(&cyw43_state.netif[CYW43_ITF_STA], hostname);


    // sleep
    sleep_ms(200);


    printf("Connecting to WiFi...\n");
    if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000)) {
        printf("failed to connect. error code %d\n", err);
        exit(1);
    } else {
        printf("Connected.\n");
    }
///////

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions