Pico 2W wifi help

Hi All,
I am new to the world of Embassy programming. I have done previous work with Micro python.

I have an Rpi Pico 2 W. I had a look at the Embassy examples and I can only find wifi examples for the Pico W, not the Pico 2 W. Does anyone know of a good working example of Wifi on a Pico 2 W?

There is an example in the embassy repo

1 Like

That example only shows how to blink the LED that is attached to the Wifi chip. I was hoping to find an example showing how to connect to Wifi

I don't have a 2W board to test it myself, but from my understanding, they are using the same cyw43 wifi chip, and embassy's cyw43 driver works for both boards, so you should be able to compile the same code for Pico 2 W, just make sure to use the correct project template, specifically, the memory.x and .cargo/config.toml should be configured for rp2350 instead of rp2040.

for example, you can try to copy the wifi_tcp_server.rs from examples/rp to examples/rp235x, and run it from the rp235x.

Just to add to what nerditation wrote, the key part is to use all configuration inside rp235x, e.g. Cargo.toml, .cargo\config.toml, memory.x. The point of an OS like Embassy (that besides including a HAL for many chips/boards, it also provides timing and network libraries), is that once you have declared what hardware you are using, you can reuse non-hardware specific code with no (or only minimal) changes. For example, you could use the file rp235x/src/bin/blinky_wifi.rs as starting point and add the relevant Wi-Fi/network parts from rp/src/bin/wifi_tcp_server.rs.

Good news: I got it working by using the rp2040 folder as an example. I copied the below file into the rp235x folder.

Question:

How do I set the name of the device? According to my Wifi router the "Device Name" is unknown.

Here is the example I am following: Link

it depends on what protocol the router uses. for common brand home routers, most likely, dhcp option 12 and mDNS are supported.

first, you can try to add the option 12 (HOSTNAME) to the dhcp request. the embassy-net is a tcpip stack based on smoltcp, option 12 is supported via the DhcpConfig::hostname setting, just make sure the dhcpv4-hostname feature is enabled.

in the webrequest example, you just need to change this line:

into something like this:

let config = Config::dhcpv4(DhcpConfig {
    hostname: Some("my device".try_into().unwrap()),
    ..Default::default,
});

don't forget to update Cargo.toml to enable the optional feature flag:

# Cargo.toml
embassy-net = { features = ["dhcpv4-hostname", ...], ... }

if your router does not support dhcp option 12, you can try an mDNS responder library. however, I don't know have any experience of any mDNS library with smoltcp, so you'll have to do your own research.

I got it working but I had to modify your suggestion slightly.

    let mut dhcp_config = DhcpConfig::default();
    dhcp_config.hostname = Some("pico_rust".try_into().unwrap());

    let config = Config::dhcpv4(dhcp_config);

Thanks again for your help!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.