aboutsummaryrefslogtreecommitdiff
path: root/libraries/Ethernet/Ethernet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Ethernet/Ethernet.cpp')
-rw-r--r--libraries/Ethernet/Ethernet.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/libraries/Ethernet/Ethernet.cpp b/libraries/Ethernet/Ethernet.cpp
index c298f3d..5d28f71 100644
--- a/libraries/Ethernet/Ethernet.cpp
+++ b/libraries/Ethernet/Ethernet.cpp
@@ -10,7 +10,8 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
int EthernetClass::begin(uint8_t *mac_address)
{
- DhcpClass dhcp;
+ _dhcp = new DhcpClass();
+
// Initialise the basic info
W5100.init();
@@ -18,15 +19,15 @@ int EthernetClass::begin(uint8_t *mac_address)
W5100.setIPAddress(IPAddress(0,0,0,0).raw_address());
// Now try to get our config info from a DHCP server
- int ret = dhcp.beginWithDHCP(mac_address);
+ int ret = _dhcp->beginWithDHCP(mac_address);
if(ret == 1)
{
// We've successfully found a DHCP server and got our configuration info, so set things
// accordingly
- W5100.setIPAddress(dhcp.getLocalIp().raw_address());
- W5100.setGatewayIp(dhcp.getGatewayIp().raw_address());
- W5100.setSubnetMask(dhcp.getSubnetMask().raw_address());
- _dnsServerAddress = dhcp.getDnsServerIp();
+ W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
+ W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
+ W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
+ _dnsServerAddress = _dhcp->getDnsServerIp();
}
return ret;
@@ -66,6 +67,31 @@ void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server
_dnsServerAddress = dns_server;
}
+int EthernetClass::maintain(){
+ int rc = DHCP_CHECK_NONE;
+ if(_dhcp != NULL){
+ //we have a pointer to dhcp, use it
+ rc = _dhcp->checkLease();
+ switch ( rc ){
+ case DHCP_CHECK_NONE:
+ //nothing done
+ break;
+ case DHCP_CHECK_RENEW_OK:
+ case DHCP_CHECK_REBIND_OK:
+ //we might have got a new IP.
+ W5100.setIPAddress(_dhcp->getLocalIp().raw_address());
+ W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address());
+ W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address());
+ _dnsServerAddress = _dhcp->getDnsServerIp();
+ break;
+ default:
+ //this is actually a error, it will retry though
+ break;
+ }
+ }
+ return rc;
+}
+
IPAddress EthernetClass::localIP()
{
IPAddress ret;