8000 network.hostname() seems useless... does mDNS work? · Issue #11450 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

network.hostname() seems useless... does mDNS work? #11450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
massimosala opened this issue May 9, 2023 · 11 comments
Open

network.hostname() seems useless... does mDNS work? #11450

massimosala opened this issue May 9, 2023 · 11 comments
Labels

Comments

@massimosala
Copy link

Current target: esp8266

On the official docs:
https://docs.micropython.org/en/latest/library/network.html

network.hostname([name])
Get or set the hostname that will identify this device on the network. It is applied to all interfaces.
This hostname is used for:
Sending to the DHCP server in the client request. (If using DHCP)
Broadcasting via mDNS. (If enabled)

It seems to me that there are no references in the esp8266 pages regarding this function:
https://docs.micropython.org/en/latest/esp8266/quickref.html

I tried to use network.hostname() both before and after the wifi initialization (AF_STA mode), but it doesn't seem to work.

With a packet sniffer, enabled in promiscuous mode on the wifi interface, I see the packets (also broadcast and multicast) of other devices but not the packets that esp8266 should send to publish its hostname.

I'm specifically interested in mDNS.

I am available for any test and feedback.

@massimosala massimosala added the bug label May 9, 2023
@jimmo
Copy link
Member
jimmo commented May 10, 2023

I'm specifically interested in mDNS.

The ESP8266 port does not support mDNS. In this port, network.hostname only sets the name passed in the DHCP client request.

@massimosala
Copy link
Author

@jimmo Thanks for your clarification.

Two considerations:

  • Why does someone take this decision?
    It have to write a mDNS client and it works, also on esp8266, so there aren't technical barriers.

  • It is not documented. This is the worst part.
    Anyone who runs into this problem will wonder about the possible causes.
    How can we solve this lack of documentation?

I don't know if the lead developers will take notice or should I raise this issue...how?

@massimosala
Copy link
Author

Addendum: I open a documentation issue.

@jimmo
Copy link
Member
jimmo commented May 19, 2023

Why does someone take this decision?

It's just a matter of doing the work. We would welcome a PR to add mDNS to the ESP8266 port.

It is not documented. This is the worst part.

https://docs.micropython.org/en/latest/library/network.html#network.hostname

I guess the "(If enabled)" is doing some heavy lifting here and it would be good to list the ports that do and don't support mDNS.

In #11545 you suggested that it should return NotImplemented and that it's useless. This is not true -- on all ports, including ESP8266, it sets the hostname that is sent with the DHCP client request. (Or at least it's supposed to, if you're seeing otherwise please let us know).

@massimosala
Copy link
Author

Mmh please read also
https://github.com/orgs/micropython/discussions/11548

We would welcome a PR to add mDNS to the ESP8266 port.

I wrote it in Python and it's a few lines of code; they're just UDP socket calls, nothing low-level, specific to the ESP8266.
I think the mDNS code for other micros is easily ported to ESP8266.
Please let me know how to open a PR.

@hagenbuch
Copy link
hagenbuch commented Jun 14, 2023

Addition: For target ESP32 (I am using an Olimex ESP32-POE Rev. B) I am able to set my own hostname:

network.hostname("myhostname")

This hostname will be sent with the DHCP request when using Wifi (network.WLAN) but it will be ignored when using Ethernet (network.LAN - in that case the hostname used by DHCP is always "ESP32-POE" - which would be the name of the Olimex device.

I'm sorry I have no idea who does the porting etc. Olimex only seems to offer Arduino code if I am not mistaken.

@robert-hh
Copy link
Contributor

There are daily builds available for the Olimex ESP32-POE boards. I can look into the hostname part.

@hagenbuch
Copy link

Oh wow that would be awesome! Many thanks!

@massimosala
Copy link
Author
massimosala commented Jun 27, 2023

Hi folks!
@hagenbuch @robert-hh @jimmo

I confirm the problem on esp8266.

The first time I get the Wifi credentials from user input (on a web page) and I enable the STA_IF:

		nic = WLAN(STA_IF)
		nic.active(True)
	        nic.enable_STA(my_hostname, str_SSID, str_SSID_pwd)
 		nic.config(dhcp_hostname = my_hostname)

On the cell-phone (hotspot) or on the router I can see the micro listed with my hostname.
For security, I don't store WiFi credentials.

After resetting the esp8266, it reconnects by itself to the AP (I see the WiFi credentials are stored in flash) but the hostname was the default ESP_xxxxx (derived from the machine unique id).

I am using this code:

                network.hostname(my_hostname)
		nic = WLAN(STA_IF)
		nic.active(True)
		nic.config(dhcp_hostname = my_hostname)

This doesn't work, the hostname is ESP_xxxxx.

Reading old posts about issues with the background LWIP tasks, I also tried inserting calls to time.sleep_ms(20) and machine.idle() between every micropython instructions.

Please can you help me to troubleshoot this issue?

Best regards, Massimo

@massimosala
Copy link
Author
massimosala commented Jun 17, 2024

Hi @hagenbuch @robert-hh

Did you discover something about hostname on wired boards?

In the last weeks I got a wiznet 5500.

I have the two spare parts (rp2 and w5500) and I wired them exactly as W5500_EVB_PICO
and I flash the rp2 with the EVB_PICO firmware.

The firmware is working... except hostname

@hagenbuch Andreas, which network chip does your olimex board use?

@hagenbuch
Copy link

When I use it with Tasmota, it reads: ESP32-D0WDQ6 v1.0. Flash size: 4 MB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
0