thermferm/thermferm.c

branch
stable
changeset 601
44d41db09466
parent 597
93667d842c9b
child 605
e00f8ff4de9a
--- a/thermferm/thermferm.c	Thu May 09 15:17:30 2019 +0200
+++ b/thermferm/thermferm.c	Sun Jul 07 13:55:03 2019 +0200
@@ -21,7 +21,6 @@
  *****************************************************************************/
 
 #include "lock.h"
-#include "logger.h"
 #include "rdconfig.h"
 #include "devices.h"
 #include "server.h"
@@ -405,7 +404,6 @@
 {
     current_unit->mqtt_flag |= MQTT_FLAG_DATA;
     if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) {
-	initlog(current_unit->product_code, current_unit->product_name);
 	current_unit->mqtt_flag |= MQTT_FLAG_BIRTH;
     } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) {
 	current_unit->mqtt_flag |= MQTT_FLAG_DEATH;
@@ -1001,6 +999,8 @@
 
     killconfig();
     syslog(LOG_NOTICE, "Finished, rc=%d", rc);
+    if (debug)
+        fprintf(stdout, "Finished, rc=%d\n", rc);
     return rc;
 }
 
@@ -1008,12 +1008,10 @@
 
 int server(void)
 {
-    char                buf[1024], *filename, target_lo[40], target_hi[40], heater[40], cooler[40], fan[40], door[40];
-    char		use_heater[40], use_cooler[40], use_fan[40], room_temp[40];
     time_t		now, last = (time_t)0, ndata = (time_t)0;;
     units_list		*unit;
     prof_step		*step;
-    int			row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation;
+    int			row, rc, run = 1, seconds = 0, minutes = 0, temp;
     int			run_seconds, run_minutes, run_hours, tot_minutes, key;
     struct tm		*tm;
 #ifndef HAVE_WIRINGPI_H
@@ -1122,17 +1120,8 @@
 	} else {
 	    syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->alias);
 	}
-
-	/*
-	 * Initialize logfile
-	 */
-	if (unit->mode != UNITMODE_OFF) {
-	    initlog(unit->product_code, unit->product_name);
-	}
     }
-    printf("Units started\n");
     publishDBirthAll();
-    printf("Birth all done\n");
 
     for (unit = Config.units; unit; unit = unit->next) {
 	if (unit->mode != UNITMODE_OFF) {
@@ -1282,26 +1271,12 @@
 		if (unit->air_address) {
 		    rc = device_in(unit->air_address, &temp);
 		    if (rc == DEVPRESENT_YES) {
-			/*
-			 * It is possible to have read errors or extreme values.
-			 * This can happen with bad connections so we compare the
-			 * value with the previous one. If the difference is too
-			 * much, we don't send that value. That also means that if
-			 * the next value is ok again, it will be marked invalid too.
-			 * Maximum error is 40 degrees for now.
-			 */
-			deviation = 40000;
-			if ((unit->air_temperature == 0) ||
-			    (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
-			    if (unit->air_temperature != temp) {
-				unit->mqtt_flag |= MQTT_FLAG_DATA;
-				pub_domoticz_temp(unit->air_idx, temp);
-			    }
-			    unit->air_temperature = temp;
-			    unit->air_state = 0;
-			} else {
-			    syslog(LOG_NOTICE, "deviation error air deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
+			if (unit->air_temperature != temp) {
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			    pub_domoticz_temp(unit->air_idx, temp);
 			}
+			unit->air_temperature = temp;
+			unit->air_state = 0;
 		    } else if (rc == DEVPRESENT_ERROR) {
 			unit->air_state = 1;
 		    } else {
@@ -1312,18 +1287,12 @@
 		if (unit->beer_address) {
 		    rc = device_in(unit->beer_address, &temp);
 		    if (rc == DEVPRESENT_YES) {
-			deviation = 40000;
-			if ((unit->beer_temperature == 0) ||
-			    (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
-			    if (unit->beer_temperature != temp) {
-				unit->mqtt_flag |= MQTT_FLAG_DATA;
-				pub_domoticz_temp(unit->beer_idx, temp);
-			    }
-    			    unit->beer_temperature = temp;
-			    unit->beer_state = 0;
-			} else {
-			    syslog(LOG_NOTICE, "deviation error beer deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
+			if (unit->beer_temperature != temp) {
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			    pub_domoticz_temp(unit->beer_idx, temp);
 			}
+    			unit->beer_temperature = temp;
+			unit->beer_state = 0;
 		    } else if (rc == DEVPRESENT_ERROR) {
 			unit->beer_state = 1;
 		    } else {
@@ -1334,18 +1303,12 @@
 		if (unit->chiller_address) {
 		    rc = device_in(unit->chiller_address, &temp);
 		    if (rc == DEVPRESENT_YES) {
-			deviation = 40000;
-			if ((unit->chiller_temperature == 0) ||
-			    (unit->chiller_temperature && (temp > (int)unit->chiller_temperature - deviation) && (temp < ((int)unit->chiller_temperature + deviation)))) {
-			    if (unit->chiller_temperature != temp) {
-				unit->mqtt_flag |= MQTT_FLAG_DATA;
-				pub_domoticz_temp(unit->chiller_idx, temp);
-			    }
-			    unit->chiller_temperature = temp;
-			    unit->chiller_state = 0;
-			} else {
-			    syslog(LOG_NOTICE, "deviation error chiller deviation=%d, old=%d new=%d", deviation, unit->chiller_temperature, temp);
+			if (unit->chiller_temperature != temp) {
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
+			    pub_domoticz_temp(unit->chiller_idx, temp);
 			}
+			unit->chiller_temperature = temp;
+			unit->chiller_state = 0;
 		    } else if (rc == DEVPRESENT_ERROR) {
 			unit->chiller_state = 1;
 		    } else {
@@ -1524,10 +1487,6 @@
 						 * This is our current step
 						 */
 						valid_step = TRUE;
-			//			if (debug)
-			//			    fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ", 
-			//					    current_step, run_hours - time_until_now,
-			//					    step->steptime, step->resttime, step->target_lo, step->target_hi);
 						if ((run_hours - time_until_now) < step->steptime) {
 						    unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo));
 						    unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi));
@@ -1541,18 +1500,10 @@
 						    if (debug)
 							fprintf(stdout, "prof_fridge_mode=%d run_minutes=%d steptime=%d time_until_now=%d\n",
 									unit->prof_fridge_mode, run_minutes, step->steptime, time_until_now);
-			//			    if (debug)
-			//				fprintf(stdout, "tempshift=%.1f..%.1f  minutes=%d duration=%d temp_move=%.3f..%.3f ", 
-			//						step->target_lo - previous_target_lo,
-			//						step->target_hi - previous_target_hi,
-			//						run_minutes - (time_until_now * 60), 
-			//						step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi);
 						} else {
 						    unit->prof_target_lo = step->target_lo;
 						    unit->prof_target_hi = step->target_hi;
 						    unit->prof_fridge_mode = step->fridge_mode;
-			//			    if (debug)
-			//			    	fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi);
 						}
 						break;
 					    }
@@ -1561,8 +1512,6 @@
 					    previous_target_hi = step->target_hi;
 					    previous_fridge_mode = step->fridge_mode;
 					}
-			//		if (debug)
-			//		    fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds);
 
 					if (valid_step == TRUE) {
 					    unit->prof_percent = (100 * run_minutes) / tot_minutes;
@@ -1688,9 +1637,6 @@
 			 */
 			usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) +
 			          ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0;
-			if (debug)
-			    fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode,
-					    unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp);
 			unit->PID_cool->Input = unit->PID_heat->Input = usetemp;
 			unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
 		    }
@@ -1963,60 +1909,10 @@
 		seconds = 0;
 
 		/*
-		 * Log temperature and status every minute if unit is active.
+		 * Publish data every minute if unit is active.
 		 */
 		for (unit = Config.units; unit; unit = unit->next) {
 		    if (unit->mode != UNITMODE_OFF) {
-
-			snprintf(target_lo, 39, "NA");
-			snprintf(target_hi, 39, "NA");
-			snprintf(heater, 39, "NA");
-			snprintf(cooler, 39, "NA");
-			snprintf(fan, 39, "NA");
-			snprintf(door, 39, "NA");
-			snprintf(use_heater, 39, "NA");
-			snprintf(use_cooler, 39, "NA");
-			snprintf(use_fan, 39, "NA");
-			snprintf(room_temp, 39, "NA");
-
-			if ((unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_PROFILE)) {
-			    snprintf(target_lo, 39, "%.1f", unit->PID_heat->SetP);
-			    snprintf(target_hi, 39, "%.1f", unit->PID_cool->SetP);
-			}
-
-			if (unit->heater_address) {
-			    snprintf(heater, 39, "%d", unit->heater_state);
-			    snprintf(use_heater, 39, "%d", unit->heater_usage);
-			}
-			if (unit->cooler_address) {
-			    snprintf(cooler, 39, "%d", unit->cooler_state);
-			    snprintf(use_cooler, 39, "%d", unit->cooler_usage);
-			}
-			if (unit->fan_address) {
-			    snprintf(fan, 39, "%d", unit->fan_state);
-			    snprintf(use_fan, 39, "%d", unit->fan_usage);
-			}
-			if (unit->door_address) {
-			    snprintf(door, 39, "%d", unit->door_state);
-			}
-			if (Config.temp_address) {
-			    snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0);
-			}
-
-			snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.3f,%s",
-					UNITMODE[unit->mode], unit->air_temperature / 1000.0,
-					unit->beer_temperature / 1000.0,
-					target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi,
-					unit->chiller_temperature / 1000.0,
-					(unit->event_msg) ? unit->event_msg : (char *)"");
-			filename = xstrcpy(unit->product_code);
-			filename = xstrcat(filename, (char *)" ");
-			filename = xstrcat(filename, unit->product_name);
-			filename = xstrcat(filename, (char *)".log");
-			logger(filename, buf);
-			free(filename);
-			filename = NULL;
-
 			publishDLog(unit);
 			if (unit->event_msg)
 			    free(unit->event_msg);

mercurial