ArduinoCore-mbed
ArduinoCore-mbed copied to clipboard
Add support for DHCP hostname
Recently someone pointed me to this PR on the mbed-os repo: https://github.com/ARMmbed/mbed-os/pull/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.
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.
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 https://github.com/arduino/ArduinoCore-mbed/pull/969
Hi @pennam, The addition of the wifi support is great! I suppose this PR can be closed and #969 should be merged instead.