Page 1 of 1

Default gw and subnet mask

PostPosted: Wed Oct 16, 2013 3:41 am
by siksak
How can I configure default gateway and subnet mask in mydooropener?

Re: Default gw and subnet mask

PostPosted: Wed Oct 16, 2013 10:05 pm
by support
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,

Re: Default gw and subnet mask

PostPosted: Fri Aug 19, 2016 5:37 pm
by slime
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.

Re: Default gw and subnet mask

PostPosted: Sat Aug 27, 2016 11:54 pm
by support
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.