thermferm/thermferm.c

changeset 596
e3d3cde32847
parent 594
1904badedf8f
child 597
93667d842c9b
equal deleted inserted replaced
595:d7342a8e7f4d 596:e3d3cde32847
1007 int server(void) 1007 int server(void)
1008 { 1008 {
1009 time_t now, last = (time_t)0, ndata = (time_t)0;; 1009 time_t now, last = (time_t)0, ndata = (time_t)0;;
1010 units_list *unit; 1010 units_list *unit;
1011 prof_step *step; 1011 prof_step *step;
1012 int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation; 1012 int row, rc, run = 1, seconds = 0, minutes = 0, temp;
1013 int run_seconds, run_minutes, run_hours, tot_minutes, key; 1013 int run_seconds, run_minutes, run_hours, tot_minutes, key;
1014 struct tm *tm; 1014 struct tm *tm;
1015 #ifndef HAVE_WIRINGPI_H 1015 #ifndef HAVE_WIRINGPI_H
1016 long t = 0; 1016 long t = 0;
1017 #endif 1017 #endif
1269 unit->alarm_flag = 0; 1269 unit->alarm_flag = 0;
1270 1270
1271 if (unit->air_address) { 1271 if (unit->air_address) {
1272 rc = device_in(unit->air_address, &temp); 1272 rc = device_in(unit->air_address, &temp);
1273 if (rc == DEVPRESENT_YES) { 1273 if (rc == DEVPRESENT_YES) {
1274 /* 1274 if (unit->air_temperature != temp) {
1275 * It is possible to have read errors or extreme values. 1275 unit->mqtt_flag |= MQTT_FLAG_DATA;
1276 * This can happen with bad connections so we compare the 1276 pub_domoticz_temp(unit->air_idx, temp);
1277 * value with the previous one. If the difference is too 1277 }
1278 * much, we don't send that value. That also means that if 1278 unit->air_temperature = temp;
1279 * the next value is ok again, it will be marked invalid too. 1279 unit->air_state = 0;
1280 * Maximum error is 40 degrees for now.
1281 */
1282 deviation = 40000;
1283 if ((unit->air_temperature == 0) ||
1284 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
1285 if (unit->air_temperature != temp) {
1286 unit->mqtt_flag |= MQTT_FLAG_DATA;
1287 pub_domoticz_temp(unit->air_idx, temp);
1288 }
1289 unit->air_temperature = temp;
1290 unit->air_state = 0;
1291 } else {
1292 syslog(LOG_NOTICE, "deviation error air deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
1293 }
1294 } else if (rc == DEVPRESENT_ERROR) { 1280 } else if (rc == DEVPRESENT_ERROR) {
1295 unit->air_state = 1; 1281 unit->air_state = 1;
1296 } else { 1282 } else {
1297 unit->air_state = 2; 1283 unit->air_state = 2;
1298 } 1284 }
1299 } 1285 }
1300 1286
1301 if (unit->beer_address) { 1287 if (unit->beer_address) {
1302 rc = device_in(unit->beer_address, &temp); 1288 rc = device_in(unit->beer_address, &temp);
1303 if (rc == DEVPRESENT_YES) { 1289 if (rc == DEVPRESENT_YES) {
1304 deviation = 40000; 1290 if (unit->beer_temperature != temp) {
1305 if ((unit->beer_temperature == 0) || 1291 unit->mqtt_flag |= MQTT_FLAG_DATA;
1306 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { 1292 pub_domoticz_temp(unit->beer_idx, temp);
1307 if (unit->beer_temperature != temp) { 1293 }
1308 unit->mqtt_flag |= MQTT_FLAG_DATA; 1294 unit->beer_temperature = temp;
1309 pub_domoticz_temp(unit->beer_idx, temp); 1295 unit->beer_state = 0;
1310 }
1311 unit->beer_temperature = temp;
1312 unit->beer_state = 0;
1313 } else {
1314 syslog(LOG_NOTICE, "deviation error beer deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
1315 }
1316 } else if (rc == DEVPRESENT_ERROR) { 1296 } else if (rc == DEVPRESENT_ERROR) {
1317 unit->beer_state = 1; 1297 unit->beer_state = 1;
1318 } else { 1298 } else {
1319 unit->beer_state = 2; 1299 unit->beer_state = 2;
1320 } 1300 }
1321 } 1301 }
1322 1302
1323 if (unit->chiller_address) { 1303 if (unit->chiller_address) {
1324 rc = device_in(unit->chiller_address, &temp); 1304 rc = device_in(unit->chiller_address, &temp);
1325 if (rc == DEVPRESENT_YES) { 1305 if (rc == DEVPRESENT_YES) {
1326 deviation = 40000; 1306 if (unit->chiller_temperature != temp) {
1327 if ((unit->chiller_temperature == 0) || 1307 unit->mqtt_flag |= MQTT_FLAG_DATA;
1328 (unit->chiller_temperature && (temp > (int)unit->chiller_temperature - deviation) && (temp < ((int)unit->chiller_temperature + deviation)))) { 1308 pub_domoticz_temp(unit->chiller_idx, temp);
1329 if (unit->chiller_temperature != temp) { 1309 }
1330 unit->mqtt_flag |= MQTT_FLAG_DATA; 1310 unit->chiller_temperature = temp;
1331 pub_domoticz_temp(unit->chiller_idx, temp); 1311 unit->chiller_state = 0;
1332 }
1333 unit->chiller_temperature = temp;
1334 unit->chiller_state = 0;
1335 } else {
1336 syslog(LOG_NOTICE, "deviation error chiller deviation=%d, old=%d new=%d", deviation, unit->chiller_temperature, temp);
1337 }
1338 } else if (rc == DEVPRESENT_ERROR) { 1312 } else if (rc == DEVPRESENT_ERROR) {
1339 unit->chiller_state = 1; 1313 unit->chiller_state = 1;
1340 } else { 1314 } else {
1341 unit->chiller_state = 2; 1315 unit->chiller_state = 2;
1342 } 1316 }

mercurial