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

Add support for DHCP hostname #921

Closed
wants to merge 5 commits into from

Conversation

Channel59
Copy link
Contributor

@Channel59 Channel59 commented Jul 9, 2024

Recently someone pointed me to this PR on the mbed-os repo: ARMmbed/mbed-os#15506.
The patches to make these changes are included in this pull request and so the credits for these patches full go to https://github.com/guilhermerc.

It enables the use of a hostname when DHCP is used to obtain an IP address.

Subsequently, the Ethernet.cpp and Ethernet.h are adjusted to allow the hostname to be set:

Either using Ethernet.begin("desired-hostname");

or using a somewhat more Arduino-like api:

Ethernet.setHostname("desired-hostname");
Ethernet.begin();

Before this compiles, libmbed.a should be recompiled on https://github.com/ARMmbed/mbed-os/tree/latest which will also patch some of the header files that are required to compile the arduino program.

The code seems to work correctly with the opta. Any testing / refinements are more than welcome.

I do not have a wifi enabled device, so I cannot test it, but with these patches applied, a small change to Wifi.h and Wifi.cpp could add support for Wifi as well.

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2024

CLA assistant check
All committers have signed the CLA.

@Channel59
Copy link
Contributor Author

Channel59 commented Jul 9, 2024

The compiler errors arise from the fact that a call to Ethernet.begin(nullptr) is ambiguous now:

 /home/runner/work/ArduinoCore-mbed/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino:143:29: error: call of overloaded 'begin(std::nullptr_t)' is ambiguous
     if (Ethernet.begin(nullptr) == 0) {
                               ^
  In file included from /home/runner/.arduino15/packages/arduino/hardware/mbed/3.3.0/libraries/Ethernet/src/PortentaEthernet.h:3:0,
                   from /home/runner/work/ArduinoCore-mbed/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino:22:
  /home/runner/.arduino15/packages/arduino/hardware/mbed/3.3.0/libraries/Ethernet/src/Ethernet.h:65:7: note: candidate: int arduino::EthernetClass::begin(uint8_t*, long unsigned int, long unsigned int)
     int begin(uint8_t *mac = nullptr, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
         ^~~~~
  /home/runner/.arduino15/packages/arduino/hardware/mbed/3.3.0/libraries/Ethernet/src/Ethernet.h:66:7: note: candidate: int arduino::EthernetClass::begin(const char*)
     int begin(const char* hostname);
         ^~~~~

I suppose to make sure no code is broken the Ethernet.begin("desired-hostname"); api should be removed and only the setHostname should be used.

If someone has a more elegant solution please let me know.

@pennam
Copy link
Contributor

pennam commented Oct 3, 2024

Hi @Channel59 thank you so much for your contribution!
I took your commits and squashed a bit, also fixed patch numbers and added support for wifi. If everithing works and you are ok with this i will close this PR and merge this #969

@Channel59
Copy link
Contributor Author

Hi @pennam, The addition of the wifi support is great! I suppose this PR can be closed and #969 should be merged instead.

@Channel59 Channel59 closed this Oct 3, 2024
@Channel59 Channel59 deleted the dhcp-hostname-support branch November 12, 2024 20:01
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.

3 participants