Skip to content
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

Added config option to set dhcp_hostname #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

msinn
Copy link

@msinn msinn commented Oct 13, 2019

As a standard the WLAN object in network registers ESP32 micro-controller with the hostname 'espressif' when getting an ip adress from the dhcp server.

This commit adds the attribute 'hostname' to the config dict. When 'hostname' is configured, it is handed as 'dchp_hostname' to the sta_if configuration. This way, each ESP32 microcontroller can set it's individual dns entry.

As a standard the WLAN object in network registers ESP32 micro-controller with the hostname 'espressif' when getting an ip adress from the dhcp server.

This commit adds the attribute 'hostname' to the config dict. When 'hostname' is configured, it is handed as 'dchp_hostname' to the sta_if configuration. This way, each ESP32 microcontroller can set it's individual dns entry.
Copy link
Owner

@peterhinch peterhinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bear in mind that arguments to config are platform-specific. For example the Pyboard D does not support the dhcp_hostname config arg - this code will throw an exception on this platform.

I think the solution should be generalised. I suggest that the config dict should have an optional config_args entry which is a dict of arguments for config. Thus in your case the dict would have

   'config_args' : {'dhcp_hostname':'my_hostname'},

and the MQTT_base constructor would have

    if 'config_args' in config:
        self._sta_if.config(**config_args)

This allows for future platform-specific arguments. Please could you try and test something along those lines and re-submit the PR. If you don't want to do this please let me know and I will implement it.

@msinn
Copy link
Author

msinn commented Oct 17, 2019

I wil implement the changes/extension you propose. I'll look into it probably on the weekend.

@peterhinch
Copy link
Owner

As a matter of interest does setting the hostname have any effect in station mode? I can't see any difference here, but perhaps that's my router/dhcp server being uninformative.

I look forward to your updated PR in due course.

@kevinkk525
Copy link
Contributor

Setting the hostname in station mode works well. Your router might need a while to recognize the new hostname.
I use this feature often lately so the hostname matches ubinascii.hexlify(machine.unique_id()).

@bobveringa bobveringa mentioned this pull request Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants