--- a/thermferm/units.c Fri Jul 11 22:53:33 2014 +0200 +++ b/thermferm/units.c Sat Jul 12 17:57:53 2014 +0200 @@ -64,6 +64,8 @@ if (rc != 1) { syslog(LOG_NOTICE, "sensor %s data parse error", address); rc = 3; + } else { + rc = 0; } } else { syslog(LOG_NOTICE, "sensor %s CRC error", address); @@ -90,7 +92,7 @@ #endif { units_list *unit; - int temp, deviation; + int rc, temp, deviation; /* * Initialize units for processing @@ -134,7 +136,8 @@ break; if (unit->air_address) { - if (read_w1_28(unit->air_address, &temp) == 0) { + rc = read_w1_28(unit->air_address, &temp); + if (rc == 0) { /* * It is possible to have read errors or extreme values. * This can happen with bad connections so we compare the @@ -144,32 +147,43 @@ * Maximum error is 20 degrees for now. */ deviation = 20000; - if ((unit->air_temp == 0) || - (unit->air_temp && (temp > (int)unit->air_temp - deviation) && (temp < ((int)unit->air_temp + deviation)))) { - unit->air_temp = temp; + if ((unit->air_temperature == 0) || + (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { + unit->air_temperature = temp; + unit->air_state = 0; } else { - syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temp, temp); + syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); if (debug) { - fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temp, temp); + fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); } } + } else if (rc == 2) { + unit->air_state = 1; + } else { + unit->air_state = 2; } } if (my_shutdown) break; if (unit->beer_address) { - if (read_w1_28(unit->beer_address, &temp) == 0) { + rc = read_w1_28(unit->beer_address, &temp); + if (rc == 0) { deviation = 20000; - if ((unit->beer_temp == 0) || - (unit->beer_temp && (temp > (int)unit->beer_temp - deviation) && (temp < ((int)unit->beer_temp + deviation)))) { - unit->beer_temp = temp; + if ((unit->beer_temperature == 0) || + (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { + unit->beer_temperature = temp; + unit->beer_state = 0; } else { - syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temp, temp); + syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); if (debug) { - fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temp, temp); + fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); } } + } else if (rc == 2) { + unit->beer_state = 1; + } else { + unit->beer_state = 2; } } if (my_shutdown)