Skip to content

Commit

Permalink
change weather check interval to every 30 minutes even if the last ca…
Browse files Browse the repository at this point in the history
…ll has failed, to avoid exceeding wunderground limit; change etherport read timeout per pull request (rszimm/sprinklers_pi#38)
  • Loading branch information
rayshobby committed May 1, 2015
1 parent bd3eb0f commit fa1d26e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion etherport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int EthernetClient::read(uint8_t *buf, size_t size)
FD_ZERO(&sock_set);
FD_SET(m_sock, &sock_set);
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_sec = 3;
timeout.tv_usec = 0;

select(m_sock + 1, &sock_set, NULL, NULL, &timeout);
Expand Down
4 changes: 1 addition & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,13 @@ void check_weather() {
// do not check weather if the Use Weather option is disabled, or if network is not available, or if a program is running
if (os.status.network_fails>0 || os.status.program_busy) return;

uint16_t inv = 191; // recheck every 191 seconds if didn't receive anything last time
if (os.status.wt_received) inv = CHECK_WEATHER_INTERVAL;
ulong ntz = os.now_tz();
if (os.checkwt_success_lasttime && (ntz - os.checkwt_success_lasttime > CHECK_WEATHER_SUCCESS_INTERVAL)) {
// if weather check has failed to return for too long, restart network
os.network_lasttime = 0;
return;
}
if (!os.checkwt_lasttime || ((ntz - os.checkwt_lasttime) > inv)) {
if (!os.checkwt_lasttime || ((ntz - os.checkwt_lasttime) > CHECK_WEATHER_INTERVAL)) {
os.checkwt_lasttime = os.now_tz();
GetWeather();
}
Expand Down
3 changes: 0 additions & 3 deletions weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ static void getweather_callback(byte status, uint16_t off, uint16_t len) {
if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("eip"), true)) {
os.external_ip = atol(tmp_buffer);
}
os.status.wt_received = 1;
os.checkwt_success_lasttime = os.now_tz();
}

Expand Down Expand Up @@ -132,7 +131,6 @@ void GetWeather() {
};
*dst = *src;

os.status.wt_received = 0;
uint16_t _port = ether.hisport; // save current port number
ether.hisport = 80;
ether.browseUrl(PSTR("/weather"), dst, website, getweather_callback);
Expand Down Expand Up @@ -231,7 +229,6 @@ void GetWeather() {
bzero(tmp_buffer, TMP_BUFFER_SIZE);

time_t timeout = os.now_tz() + 5; // 5 seconds timeout
os.status.wt_received = 0;
while(os.now_tz() < timeout) {
int len=client.read((uint8_t *)ether_buffer, ETHER_BUFFER_SIZE);
if (len<=0) {
Expand Down

0 comments on commit fa1d26e

Please sign in to comment.