rszimm / sprinklers_pi

Sprinkling System Control Program for the Raspberry Pi
GNU General Public License v2.0
310 stars 100 forks source link

Fix weather adjustment with negative values. #104

Closed fedegiova closed 5 years ago

fedegiova commented 6 years ago

The Wunderground API returns ( at least for me ) precipin = -999 and precip_today_in = -999 in day without rain causing the adjustment factor to overflow the short int storage

fedegiova commented 6 years ago

Yes, I got it, but the code before was:

ret->precip_today = (atof(val) * 100.0);

with previp_today of type short. If Wunderground in a day without rain returns precipin = -999, then -999 * 100 < -65534 --> underflow

I've changed it to perform the check for negative values before the multiplication float v = str_to_float(val,0); if( v < 0) v = 0; ret->precip_today = v * 100;

nhorvath commented 5 years ago

obsolete since wunderground no longer functions