The setup function given in the previous section is good while you are debugging, but it would be good to have visual feedback using the onboard LED. To do this we need to use the asynchronous version of the connection function and we need to check the status to modify the speed of flashing of the LED:
int setup(uint32_t country, const char *ssid, const char *pass, uint32_t auth) { if (cyw43_arch_init_with_country(country)) { return 1; } cyw43_arch_enable_sta_mode(); if (cyw43_arch_wifi_connect_async(ssid, pass, auth)) { return 2; } int flashrate = 1000; int status = CYW43_LINK_UP + 1; while (status >= 0 && status != CYW43_LINK_UP) { int new_status = cyw43_tcpip_link_status( &cyw43_state, CYW43_ITF_STA); if (new_status != status) { status = new_status; flashrate = flashrate / (status + 1); printf("connect status: %d %d\n", status, flashrate); } cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); sleep_ms(flashrate); cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); sleep_ms(flashrate); } if (status < 0) { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); } else { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); } return status; }
If you use this extended setup function the onboard LED starts to flash slowly and speeds up with each stage of connection. If the function ends without an error, a negative status, the LED is left on, otherwise it is turned off. You can modify the function to give more information by using different flash rates.
If you are puzzled by the way the status is handled the reason for the initial int status = CYW43_LINK_UP + 1 is that the status isn’t updated until the first change of status and so you have to initialize it to a value that cannot be returned as a valid status code. After this you can detect changes in the status and react accordingly.
In chapter but not in this extract
LwIP NETIF
A Web Client
A Web Server
A Custom Web Site
A Dynamic Web Page – Server Side Includes
Listing
Where Next
Summary
The Pico W’s new WiFi hardware is connected via an SPI bus and this makes use of several GPIO lines that are used in the Pico for different things. In particular, GP25 is no longer used to control the internal LED. The internal LED is now controlled by a GPIO line on the WiFi chip.
The new WiFi software has two components – a low-level driver and the LwIP library which provides higher-level networking making use of the driver.
The WiFi system works in two modes, polling or background mode.
Connecting to a WiFi access point is easy, but providing feedback on the current state to the user is more difficult.
Creating a web client can be done using low-level TCP functions, but it is simpler to use the supplied HTTP client app.
Similarly a web server can be built using TCP functions, but the supplied HTTP server is easier to use.
To use the server you need to build and apply the htmlgen/makefsdata to convert the web site into a single C file which can be included in your project.
To create a dynamic web site you need to include SSI (Server Side Include) tags and a suitable SSI handling function.
The driver and the LwIP library provide a huge range of poorly documented possibilities.
The offspring of that partnership is pg_duckdb, an extension that embeds the DuckDB engine into the PostgreSQL database, allowing it to handle analytical workloads.