extern OpenSprinkler os; // OpenSprinkler object extern char tmp_buffer[]; byte findKeyVal (const char *str,char *strbuf, uint8_t maxlen,const char *key,bool key_in_pgm=false,uint8_t *keyfound=NULL); // The weather function calls getweather.py on remote server to retrieve weather data // the default script is WEATHER_SCRIPT_HOST/weather?.py static char website[] PROGMEM = WEATHER_SCRIPT_HOST ; static void getweather_callback(byte status, uint16_t off, uint16_t len) { #if defined(ARDUINO) char *p = (char*)Ethernet::buffer + off; #else char *p = ether_buffer; #endif // RAH variables added to calculate watering percentage int maxh, minh, hf, tf, rf = -1; float pre, prec = -1; int meant = -500; /* scan the buffer until the first & symbol */ while(*p && *p!='&') { p++; } if (*p != '&') return; int v; if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunrise"), true)) { v = atoi(tmp_buffer); if (v>=0 && v<=1440) { os.nvdata.sunrise_time = v; } } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("sunset"), true)) { v = atoi(tmp_buffer); if (v>=0 && v<=1440) { os.nvdata.sunset_time = v; } } os.nvdata_save(); // save non-volatile memory //////////////////////////////////////////// // RAH calculate watering water percentage based on weather //////////////////////////////////////////// if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("meant"), true)) { meant = atoi(tmp_buffer); } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("pre"), true)) { pre = atof(tmp_buffer); } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("prec"), true)) { prec = atof(tmp_buffer); } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("maxh"), true)) { maxh = atoi(tmp_buffer); } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("minh"), true)) { minh = atoi(tmp_buffer); } hf = 0; if ((maxh>=0) and (minh>=0)) {hf = 40-(maxh+minh)/2;} tf = 0; if (meant>-100) {tf = (meant - 70)*2;} rf = 0; if (pre>=0) {rf -= pre*200;} if (prec>=0) {rf -= prec*200;} v = (int) (100 + hf + tf + rf); if (v>=0 && v<=250) { os.options[OPTION_WATER_PERCENTAGE].value = v; os.options_save(); } //////////////////////////////////////////// //////////////////////////////////////////// if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("tz"), true)) { v = atoi(tmp_buffer); if (v>=0 && v<= 96) { if (v != os.options[OPTION_TIMEZONE].value) { // if timezone changed, save change and force ntp sync os.options[OPTION_TIMEZONE].value = v; os.ntpsync_lasttime = 0; os.options_save(); } } } if (findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("eip"), true)) { os.external_ip = atol(tmp_buffer); } os.status.wt_received = 1; }