Skip to content

Commit

Permalink
fix DNS caching issue for weather query; change parallel stations to …
Browse files Browse the repository at this point in the history
…use staggered start time; refine RF station timing and cycle count for OS 2.x
  • Loading branch information
rayshobby committed Aug 6, 2015
1 parent 1d06c66 commit 4162c68
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
15 changes: 8 additions & 7 deletions OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,17 @@ void OpenSprinkler::apply_all_station_bits() {
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__)
if((hw_type==HW_TYPE_DC) && engage_booster) {
DEBUG_PRINTLN(F("engage booster"));
// boost voltage
// disable boost voltage output first
digitalWrite(PIN_BOOST_EN, LOW);
delay(10);
// enable power to boost converter
digitalWrite(PIN_BOOST, HIGH);
delay(250);
digitalWrite(PIN_BOOST, LOW);

// enable boosted voltage for a short period of time
digitalWrite(PIN_BOOST_EN, HIGH);
// enable boost voltage output
digitalWrite(PIN_SR_LATCH, HIGH);
delay(500);
digitalWrite(PIN_BOOST_EN, LOW);
digitalWrite(PIN_BOOST_EN, HIGH);
} else {
digitalWrite(PIN_SR_LATCH, HIGH);
}
Expand Down Expand Up @@ -783,7 +784,7 @@ void OpenSprinkler::update_rfstation_bits() {
void send_rfsignal(ulong code, ulong len) {
ulong len3 = len * 3;
ulong len31 = len * 31;
for(byte n=0;n<24;n++) {
for(byte n=0;n<15;n++) {
int i=23;
// send code
while(i>=0) {
Expand All @@ -803,7 +804,7 @@ void OpenSprinkler::send_rfstation_signal(byte sid, bool turnon) {
ulong on, off;
uint16_t length = get_station_name_rf(sid, &on, &off);
#if defined(ARDUINO)
length = (length>>1)+(length>>2); // due to internal call delay, scale time down to 75%
length = length - (length>>5); // due to internal call delay, scale time down to 97%
#else
length = (length>>2)+(length>>3); // on RPi and BBB, there is even more overhead, scale to 37.5%
#endif
Expand Down
2 changes: 1 addition & 1 deletion defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// if this number is different from the one stored in non-volatile memory
// a device reset will be automatically triggered

#define OS_FW_MINOR 1 // Firmware minor version
#define OS_FW_MINOR 2 // Firmware minor version

/** Hardware version base numbers */
#define OS_HW_VERSION_BASE 0x00
Expand Down
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ void schedule_all_stations(ulong curr_time) {
// concurrent scheduling
pd.scheduled_start_time[sid] = con_start_time;
pd.scheduled_stop_time[sid] = con_start_time + pd.scheduled_stop_time[sid];
con_start_time++; // stagger concurrent stations by 1 second
/*DEBUG_PRINT("[");
DEBUG_PRINT(sid);
DEBUG_PRINT(":");
Expand Down
33 changes: 14 additions & 19 deletions weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ static void getweather_callback(byte status, uint16_t off, uint16_t len) {
#if defined(ARDUINO) // for AVR
void GetWeather() {
// check if we've already done dns lookup
if(ether.hisip[0] == 0) {
ether.dnsLookup(website);
}

//bfill=ether.tcpOffset();
ether.dnsLookup(website);

char tmp[30];
read_from_file(wtopts_name, tmp, 30);
BufferFiller bf = (uint8_t*)tmp_buffer;
Expand Down Expand Up @@ -174,22 +171,20 @@ void GetWeather() {
EthernetClient client;

static struct hostent *server = NULL;
strcpy(tmp_buffer, WEATHER_SCRIPT_HOST);
server = gethostbyname(tmp_buffer);
if (!server) {
strcpy(tmp_buffer, WEATHER_SCRIPT_HOST);
server = gethostbyname(tmp_buffer);
if (!server) {
DEBUG_PRINTLN("can't resolve weather server");
return;
}
DEBUG_PRINT("weather server ip:");
DEBUG_PRINT(((uint8_t*)server->h_addr)[0]);
DEBUG_PRINT(":");
DEBUG_PRINT(((uint8_t*)server->h_addr)[1]);
DEBUG_PRINT(":");
DEBUG_PRINT(((uint8_t*)server->h_addr)[2]);
DEBUG_PRINT(":");
DEBUG_PRINTLN(((uint8_t*)server->h_addr)[3]);
DEBUG_PRINTLN("can't resolve weather server");
return;
}
DEBUG_PRINT("weather server ip:");
DEBUG_PRINT(((uint8_t*)server->h_addr)[0]);
DEBUG_PRINT(":");
DEBUG_PRINT(((uint8_t*)server->h_addr)[1]);
DEBUG_PRINT(":");
DEBUG_PRINT(((uint8_t*)server->h_addr)[2]);
DEBUG_PRINT(":");
DEBUG_PRINTLN(((uint8_t*)server->h_addr)[3]);

if (!client.connect((uint8_t*)server->h_addr, 80)) {
DEBUG_PRINTLN("failed to connect to weather server");
Expand Down

0 comments on commit 4162c68

Please sign in to comment.