pimoroni / enviro

MIT License
101 stars 79 forks source link

running two nodes = duplicate hostname/dns name on DHCP server #167

Closed ikonia closed 2 months ago

ikonia commented 1 year ago

I've got 2 enviro local on the same wlan, the dhcp see's them both ask for addresses and updates dns successfully, however both of them have the same default hostname that doesn't seem to be able to be changed eg: DHCPDISCOVER from 28:c1:05:02:9d (PYBD) via enp2s0 DHCPDISCOVER from 28:c1:05:22:82 (PYBD) via enp2s0

is there anyway to get them to identify themselves differently.

I'm also not sure if this is causing any problems in terms of wifi stability either due to conflicting FQDN as dhcp will also update DDNS with FQDN from dhcp requests.

ikonia commented 2 months ago

this is confirmed causing a problem, as DDNS is unable to handle duplicate hostnames and as such will refuse to offer an IP address if the forward map cannot be set.

Gadgetoid commented 2 months ago

Which part of the above is the hostname?

Looks like a fix is possible downstream- https://github.com/micropython/micropython/pull/10635

I guess we could change the hostname to include part of the Pico's UUID. Something like (note: :warning: test this in a REPL first I don't know what format UUID will be in!):

UUID = machine.unique_id()
machine.hostname(f"enviro{UUID[-4:]}")

You might be able to make this change early in your board's main.py and see if it accomplishes what we'd want it to.

edit: I guess this gives us a clue: https://github.com/pimoroni/enviro/blob/b5bff82f9001409c9683be43b9f2114e7da8b430/enviro/helpers.py#L27-L28

ikonia commented 2 months ago

the hostname being advertised by the network interface is "PYBD" so in essence 2 devices are called PYBD

I was looking to mirror the 'nickname' set in the setup interface into the hostname parameter, but on the current platform I couldn't see a possible way to do it.

Gadgetoid commented 2 months ago

the hostname being advertised by the network interface is "PYBD"

Weird, I thought ours was always configured to be PicoW but it could be broken or non-functional in an older build.

I was looking to mirror the 'nickname' set in the setup interface into the hostname parameter

I'd wondered, this should be doable but needs some changes and a good place to put the hostname wrangling. I added some basic disambiguation here - https://github.com/pimoroni/enviro/commit/33ab1a208317a6227f8e45e47c46ac5af5c249e9

Test builds for that change- and all the other networking fixes, and a much newer build of MicroPython - are available here: https://github.com/pimoroni/enviro/actions/runs/8803662645

sjefferson99 commented 2 months ago

@Gadgetoid As my board is misbehaving on my custom branch code, I've flashed it with this UF2 to properly test the new firmware and wifi updates. I can confirm that now I've taken my MAC reservation off the DHCP server I immediately get a hostname of EnviroW-7822.

Assuming you have picked the end of the UUID that is likely to change most (I have no idea how it's allocated to the flash chip), then this looks to be successful. Providing no one else finds they have the same suffix, this should be enough for the use case.

Gadgetoid commented 2 months ago

Assuming you have picked the end of the UUID that is likely to change most

I don't know for sure, but I think it's convention to have the bit that changes most on the right.

I think this is safer, and easier to implement without extensive testing, than taking user input as the hostname. Though the latter is still possible.