diff --git a/EtherCard.h b/EtherCard.h index 5a3cca8c..a69682a1 100644 --- a/EtherCard.h +++ b/EtherCard.h @@ -254,7 +254,7 @@ class EtherCard : public Ethernet { * @param dlen Size of the HTTP (TCP) payload * @param flags TCP flags */ - static void httpServerReply_with_flags (uint16_t dlen, uint8_t flags, uint8_t dup=0); + static void httpServerReply_with_flags (uint16_t dlen, uint8_t flags); /** @brief Acknowledge TCP message * @todo Is this / should this be private? diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index ba01516f..08e2c0f0 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -47,7 +47,6 @@ ulong OpenSprinkler::ntpsync_lasttime; ulong OpenSprinkler::checkwt_lasttime; ulong OpenSprinkler::checkwt_success_lasttime; ulong OpenSprinkler::network_lasttime; -ulong OpenSprinkler::dhcpnew_lasttime; ulong OpenSprinkler::external_ip; byte OpenSprinkler::water_percent_avg; @@ -261,7 +260,6 @@ byte OpenSprinkler::start_network() { lcd_print_line_clear_pgm(PSTR("Connecting..."), 1); network_lasttime = now(); - dhcpnew_lasttime = now(); // new from 2.2: read hardware MAC if(!read_hardware_mac()) diff --git a/OpenSprinkler.h b/OpenSprinkler.h index d026e7f8..12a8cb7b 100644 --- a/OpenSprinkler.h +++ b/OpenSprinkler.h @@ -115,7 +115,6 @@ class OpenSprinkler { static ulong checkwt_lasttime; // time when weather was checked static ulong checkwt_success_lasttime; // time when weather check was successful static ulong network_lasttime; // time when network was checked - static ulong dhcpnew_lasttime; // time when dhcp renew was performed static ulong external_ip; // external ip address static byte water_percent_avg; // average water percentage over a day diff --git a/dhcp.cpp b/dhcp.cpp index cb8d73c7..2e6cc792 100644 --- a/dhcp.cpp +++ b/dhcp.cpp @@ -17,6 +17,7 @@ #include "EtherCard.h" #include "net.h" +uint32_t now(); #define gPB ether.buffer #define DHCP_BOOTREQUEST 1 @@ -237,7 +238,8 @@ static void process_dhcp_offer (uint16_t len) { case 58: leaseTime = 0; // option 58 = Renewal Time, 51 = Lease Time for (byte i = 0; i<4; i++) leaseTime = (leaseTime << 8) + ptr[i]; - leaseTime *= 1000; // milliseconds + //leaseTime *= 1000; // milliseconds // ray: use seconds and not millis + if (leaseTime > 86400L) leaseTime = 86400L; break; case 54: EtherCard::copyIp(EtherCard::dhcpip, ptr); break; @@ -332,8 +334,8 @@ void EtherCard::DhcpStateMachine (uint16_t len) { switch (dhcpState) { case DHCP_STATE_BOUND: - //!@todo Due to millis() 49 day wrap-around, DHCP renewal may not work as expected - if (millis() >= leaseStart + leaseTime) { + //if (millis() >= leaseStart + leaseTime) { // ray: fix millis() 49-day wrap around issue + if (now() > leaseStart + leaseTime) { send_dhcp_message(); dhcpState = DHCP_STATE_RENEWING; stateTimer = millis(); @@ -366,7 +368,8 @@ void EtherCard::DhcpStateMachine (uint16_t len) { case DHCP_STATE_RENEWING: if (dhcp_received_message_type(len, DHCP_ACK)) { disableBroadcast(true); //Disable broadcast after temporary enable - leaseStart = millis(); + //leaseStart = millis(); + leaseStart = now(); // ray: use seconds and not millis() if (gwip[0] != 0) setGwIp(gwip); // why is this? because it initiates an arp request dhcpState = DHCP_STATE_BOUND; } else { diff --git a/main.cpp b/main.cpp index 926fd3ee..a148583a 100644 --- a/main.cpp +++ b/main.cpp @@ -52,7 +52,6 @@ EthernetClient *m_client = 0; #define NTP_SYNC_TIMEOUT 86403L // NYP sync timeout, 24 hrs #define RTC_SYNC_INTERVAL 60 // RTC sync interval, 60 secs #define CHECK_NETWORK_TIMEOUT 59 // Network checking timeout, 59 secs -#define DHCP_RENEW_TIMEOUT 86417L // DHCP renewal timeout: 24 hrs #define STAT_UPDATE_TIMEOUT 900 // Statistics update timeout: 15 mins #define CHECK_WEATHER_TIMEOUT 1801 // Weather check interval: 30 minutes #define CHECK_WEATHER_SUCCESS_TIMEOUT 86433L // Weather check success interval: 24 hrs @@ -985,8 +984,8 @@ void check_network() { if (os.status.network_fails>=6) { // mark for safe restart os.status.safe_reboot = 1; - } else if (os.status.network_fails>2 || (now() > os.dhcpnew_lasttime + DHCP_RENEW_TIMEOUT)) { - // if failed more than twice, reconnect + } else if (os.status.network_fails>2) { + // if failed more than twice, try to reconnect if (os.start_network()) os.status.network_fails=0; } diff --git a/server.cpp b/server.cpp index acf785dc..1ce931f1 100644 --- a/server.cpp +++ b/server.cpp @@ -187,7 +187,7 @@ void send_packet(bool final=false) { if(final) { ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V|TCP_FLAGS_FIN_V); } else { - ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V, 3); + ether.httpServerReply_with_flags(bfill.position(), TCP_FLAGS_ACK_V); bfill=ether.tcpOffset(); } } diff --git a/tcpip.cpp b/tcpip.cpp index b332e375..b10e1d19 100644 --- a/tcpip.cpp +++ b/tcpip.cpp @@ -277,22 +277,22 @@ void EtherCard::httpServerReplyAck () { get_seq(); //get the sequence number of packets after an ack from GET } -void EtherCard::httpServerReply_with_flags (uint16_t dlen, uint8_t flags, uint8_t dup) { +/*void EtherCard::httpServerReply_with_flags (uint16_t dlen, uint8_t flags, uint8_t dup) { for(byte i=0;i<=dup;i++) { set_seq(); gPB[TCP_FLAGS_P] = flags; // final packet make_tcp_ack_with_data_noflags(dlen); // send data } SEQ=SEQ+dlen; -} -/* +}*/ + void EtherCard::httpServerReply_with_flags (uint16_t dlen , uint8_t flags) { set_seq(); gPB[TCP_FLAGS_P] = flags; // final packet make_tcp_ack_with_data_noflags(dlen); // send data SEQ=SEQ+dlen; } -*/ + void EtherCard::clientIcmpRequest(const uint8_t *destip) { setMACandIPs(gwmacaddr, destip); gPB[ETH_TYPE_H_P] = ETHTYPE_IP_H_V;