Cornell University ECE4760
Symmetric UDP send/receive from PicoW to PIcoW
Pi Pico RP2040
UDP on direct Wifi link from PicoW to PicoW
The Picow has a WIFI module that can be used to connect to the internet, using the LWIP package running on the rp2040. This project uses the UDP protocol to send/receive data between two picoW's on their own subnet. One picoW is configured as a WIFI access point to which the other picoW attaches. Both run the same program. The selection of WIFI access point (AP) versus WIFI station is determined by connecting gpio2 to Vdd to select the AP function. The main function selects AP vs station, then assigns addresses so that each knows the IP address of the other. As soon as the threaders are started, the code running on each picoW is the same. Either AP or station prompts for a string to send, then sends it, followed by another packet containing the time and a shared packet count. The receive ISR is required for async packet arrival by LWIP. The threads and ISRs are segregated onto two cores, with core-0 doing all the network work, and core-1 running the serial thread and blinky thread. Since we have complete control of the network, IP addresses are assigned statically. Weirdly, the LWIP library appears to require that an access point assign IP addresses using DHCP, so that feature is used, but the IP address assigned by DHCP is overidden. A serial connection from each picoW to a laptop is used to control the programs. The AP has to boot up before the station end tries to join the network.
UDP send/recv code is slightly modified to run in Protothreads and is from :
-- Pico examples https://github.com/raspberrypi/pico-examples/tree/master/pico_w/wifi/udp_beacon
--
lwip contrib apps: https://github.com/lwip-tcpip/lwip/tree/master/contrib/apps
The structure of the program is built around Protothreads, with a thread to send a packet, and a thread to process a received packet, but note that the actual low level packet receive is performed by an ISR required by LWIP. The ISR is a short as possible and just copies the receive buffer, then signals a semaphore to run the receive thread. The receive thread detects whether the packet is a number or an array, then prints the results.
The image below shows a short set of transactions, with the AP in the top panel and
station in the bottom panel. After the boot messages from LWIP, each sends and receives
one message. First the station sends to the AP, then AP to station. Be sure to set local echo off
in PuTTY (Terminal tab).
Copyright Cornell University November 23, 2023