energia / tivac-core

7 stars 17 forks source link

Creating the function setStaticIP #15

Open joaquinbvw opened 7 years ago

joaquinbvw commented 7 years ago

I am currently working on a project and needed a function to change the network configuration while the Tiva was active and because of local requeriments we can't use a DHCP server, so I checked the lwiplib library and found the lwIPNetworkConfigChange function and decide to add that functionality to my local Ethernet library. I think this could be a useful function, I saw some people on the internet asking for such functionality.

robertinant commented 7 years ago

There is are Ethernet.begin() member functions that allows you to configure a static IP address.

void begin(IPAddress local_ip, IPAddress dns_server) { begin(0, local_ip, dns_server); };
void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway) { begin(0, local_ip, dns_server, gateway); };
void begin(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) { begin(0, local_ip, dns_server, gateway, subnet); };
robertinant commented 7 years ago

I just read the comment again and if I understand correctly, you need to change to static after you detect that a DHCP address is not provided indicating to switch to static?

robertinant commented 7 years ago

In reviewing the pull request, I noticed that the DNS server is missing in the proposed API's. Is there a reason for not including DNS server(s) in the configuration?

robertinant commented 7 years ago

I think this is a great addition if we could have it follow:

setStaticIP(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)

joaquinbvw commented 7 years ago

Hello robertinant. Yes, this feature is only for those cases that don't have a DHCP server (and I saw on the internet that I'm not the only one with this particular setting). On the other hand, I'm not sure if there is a way to detect the presence of a DHCP server from the Tiva itself, do you mean that is better to include the detection of the DHCP server inside this function? I think this detection should be made outside, since the only job for the function is to change the network configuration.

Also you're right, I forgot to include the DNS address. I will do this and post the changes after that.

Thank you for your feedback.