Default gw and subnet mask

General support questions and discussions.

Default gw and subnet mask

Postby siksak » Wed Oct 16, 2013 3:41 am

How can I configure default gateway and subnet mask in mydooropener?
siksak
 
Posts: 1
Joined: Wed Oct 16, 2013 3:40 am

Re: Default gw and subnet mask

Postby support » Wed Oct 16, 2013 10:05 pm

Hi,

Near line #824, you'll find the following line of code:

Code: Select all
Ethernet.begin(mac, ip);

If you must specify your gateway and subnet, you would change that line
to use one of the alternate Ethernet.begin() method signatures, as follows:

Code: Select all
Ethernet.begin(mac);
Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, dns);
Ethernet.begin(mac, ip, dns, gateway);
Ethernet.begin(mac, ip, dns, gateway, subnet);

Obviously, you would also need to define variables/constants (similar to mac and ip) to hold your dns,
gateway and subnet values. For more details see http://arduino.cc/en/Reference/EthernetBegin.

Hope this answers your question ... By the way, why did you want to specify a gateway and subnet?

Best regards,
support
Site Admin
 
Posts: 384
Joined: Thu Aug 22, 2013 7:30 pm

Re: Default gw and subnet mask

Postby slime » Fri Aug 19, 2016 5:37 pm

Hi,

I've just re-iped my home network as I was almost running out of 254 addresses!! Well - maybe not quite but it was a mess. So I now use a supernet and have 4 ranges - 192.168.16.x, 17.x, 18.x and 19.x for others.

Anyway, my door opener was 192.168.0.8.

Searching for subnet mask on the forum I came to this post - useful - thanks - I may need to add mask and gateway in. But in your link above, it says that v1.0 of the libarary it now supports DHCP.

The garage door opener was the only device on my network with a hardcoded IP. All my other devices are DHCP, but reserved addresses (static) in my router.

Anyone tried DHCP? It says we need to call ethernet.maintain to ensure the DHCP lease hasn't run out.

With version 1.0, the library supports DHCP. Using Ethernet.begin(mac) with the proper network setup, the Ethernet shield will automatically obtain an IP address. This increases the sketch size significantly. To make sure the DHCP lease is properly renewed when needed, be sure to call Ethernet.maintain() regularly.

Returns
The DHCP version of this function, Ethernet.begin(mac), returns an int: 1 on a successful DHCP connection, 0 on failure. The other versions don't return anything.

Any help or advice?

I'm thinking we can do something like
if Ethernet.begin(mac) == 0 {
Ethernet.begin(mac, fallbackip, fallbackdns, fallbackgateway, fallbacksubnet)
}

:
code
:
:

then near the end
we need to see if we are DHCP somehow and if so call Ethernet.maintain()

Thanks,
Si.
slime
 
Posts: 5
Joined: Tue Jun 09, 2015 10:13 am

Re: Default gw and subnet mask

Postby support » Sat Aug 27, 2016 11:54 pm

I strongly advise against using DHCP (non static) for your Arduino as if you do, you might end up
with different IP addresses and would then have invalid NAT forwarding rules.
support
Site Admin
 
Posts: 384
Joined: Thu Aug 22, 2013 7:30 pm


Return to Support



cron