Setting hostname on Pico W

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Setting hostname on Pico W

Post by scruss » Wed Jul 13, 2022 9:30 pm

Can the hostname be set on cyw43-based boards? My Raspberry Pi Pico W's all want to appear as PYBD, which seems to be the hard-coded hostname in the driver:

netif_set_hostname(n, "PYBD");

WLAN.config(dhcp_hostname="...") or WLAN.config(hostname="...") are not supported as parameters, either.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Setting hostname on Pico W

Post by jimmo » Thu Jul 14, 2022 12:42 am

scruss wrote:
Wed Jul 13, 2022 9:30 pm
Can the hostname be set on cyw43-based boards?
Not at the moment. Same issue (unsurprisingly) on the pybd.

It's quite a simple fix - just need to wire up the plumbing to ultimately call netif_set_hostname like you say. It's been on my TODO list for a while because I have a project with several pyboards on the same network... but just haven't got to it yet.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Setting hostname on Pico W

Post by scruss » Thu Jul 14, 2022 2:52 pm

Thanks, Jim. This is a nice to have enhancement rather than an i-can't-connect issue.

I've put a feature request here: Set hostname on cyw43-based boards - Issue #8910 - micropython/micropython. Sorry I can't contribute code or sponsorship, and cakes don't travel well.

zeit0dn1
Posts: 1
Joined: Thu Jul 21, 2022 10:04 pm

Re: Setting hostname on Pico W

Post by zeit0dn1 » Thu Jul 21, 2022 10:07 pm

+1 needing this.

I have a project where I will have at least 2 pico W's on the same network, probably many more once I get more familiar with them.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Setting hostname on Pico W

Post by scruss » Fri Jul 22, 2022 9:16 pm

There's a PR, but it hasn't been accepted yet: CYW43: Allow setting hostname. #8918

and of course, despite searching, my issue was a duplicate. Here's the live issue: Can't set hostname in AP mode

cubbieco
Posts: 4
Joined: Sat Sep 11, 2021 1:46 pm

Re: Setting hostname on Pico W

Post by cubbieco » Fri Aug 05, 2022 11:56 pm

The pull request has been closed which I think means it is merged in. I downloaded the latest build v1.19.1-240-g9dfabcd6d (2022-08-05) .uf2 and I've tried setting the hostname:

Code: Select all

sta_if.config("hostname")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unknown config param
So now I don't know if the parameter "hostname" is wrong or if it just isn't in the latest build yet. Any ideas?

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Setting hostname on Pico W

Post by scruss » Sun Aug 07, 2022 5:08 pm

I don't think it's in the nightlies yet. I just tried the same uf2 as you did, and the only known config parameters are channel, mac, security, ssid and txpower:

Code: Select all

# check WLAN config values
# table from
# https://docs.micropython.org/en/latest/library/network.WLAN.html

import network
sta_if = network.WLAN(network.STA_IF)

for i in ("channel", "hidden", "hostname", "key", "mac",
          "reconnects", "security", "ssid", "txpower"):
    try:
        cfg=sta_if.config(i)
    except:
        cfg="unknown config parameter"
    print(i, ":", cfg)


emjellema
Posts: 1
Joined: Mon Mar 28, 2022 2:37 pm

Re: Setting hostname on Pico W

Post by emjellema » Mon Aug 08, 2022 7:17 pm

Hi, just tried build rp2-pico-w-20220808-unstable-v1.19.1-241-g6baeded32.uf2

But unfortunately no success.

Anyone any clues?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Setting hostname on Pico W

Post by Roberthh » Mon Aug 08, 2022 7:54 pm

Looking into the sources, there are two variants of the CYW43 driver, one in lib/cyw43-drivers, one in drivers/cyw43. And there is a compile switch controlling which of both is used. Only the driver in drivers/cyw43 supports setting the hostname, but the standard compile uses the other driver.
Trying to build the other variant fails. Looks messy!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Setting hostname on Pico W

Post by jimmo » Thu Aug 11, 2022 1:25 am

The drivers/cyw43 driver will be merged into the one in lib soon, hopefully for the 1.20 release.

Post Reply