thermferm/thermferm.c

changeset 510
2da3d3340403
parent 507
80344f433a78
child 515
7ab5cf2afc0c
--- a/thermferm/thermferm.c	Mon May 08 20:54:51 2017 +0200
+++ b/thermferm/thermferm.c	Fri May 19 16:34:21 2017 +0200
@@ -395,7 +395,7 @@
 	initlog(current_unit->name);
     syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
     current_unit->mode = mode;
-    current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_MODE);
+    current_unit->mqtt_flag |= MQTT_FLAG_DATA;
     /* Allways turn everything off after a mode change */
     current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0;
     current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE;
@@ -610,7 +610,7 @@
 			    if (temp_temp != current_unit->fridge_set) {
 				syslog(LOG_NOTICE, "Fridge temperature changed from %.1f to %.1f degrees from the panel", current_unit->fridge_set, temp_temp);
 				current_unit->fridge_set = temp_temp;
-				current_unit->mqtt_flag |= MQTT_FLAG_SP;
+				current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			    go_menu(MENU_MODE_FRIDGE);
 			}
@@ -651,7 +651,7 @@
 			    if (temp_temp != current_unit->beer_set) {
 				syslog(LOG_NOTICE, "Beer temperature changed from %.1f to %.1f degrees from the panel", current_unit->beer_set, temp_temp);
 				current_unit->beer_set = temp_temp;
-				current_unit->mqtt_flag |= MQTT_FLAG_SP;
+				current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			    go_menu(MENU_MODE_BEER);			    
 			}
@@ -733,7 +733,7 @@
 			    current_unit->prof_paused = current_unit->prof_primary_done = 0;
 			    current_unit->prof_peak_abs = current_unit->prof_peak_rel = 0.0;
 			    syslog(LOG_NOTICE, "Profile started from the panel");
-			    current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
+			    current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    go_menu(MENU_MODE_PROFILE);
 			}
 			break;
@@ -745,7 +745,7 @@
 			    go_menu(MENU_PROFILE_ABORT);
 			if (key == KEY_ENTER) {
 			    current_unit->prof_state = PROFILE_PAUSE;
-			    current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
+			    current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    syslog(LOG_NOTICE, "Profile pause from the panel");
 			    go_menu(MENU_MODE_PROFILE);
 			}
@@ -764,7 +764,7 @@
 			    current_unit->prof_state = PROFILE_OFF;
 			    current_unit->prof_started = 0;
 			    syslog(LOG_NOTICE, "Profile aborted from the panel");
-			    current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
+			    current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    go_menu(MENU_MODE_PROFILE);
 			}
 			break;
@@ -777,7 +777,7 @@
 			if (key == KEY_ENTER) {
 			    current_unit->prof_state = PROFILE_RUN;
 			    syslog(LOG_NOTICE, "Profile resume from the panel");
-			    current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
+			    current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    go_menu(MENU_MODE_PROFILE);
 			}
 			break;
@@ -788,7 +788,7 @@
 			if (key == KEY_ENTER) {
 			    if (current_unit->prof_state == PROFILE_DONE) {
 				current_unit->prof_state = PROFILE_OFF;
-				current_unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT);
+				current_unit->mqtt_flag |= MQTT_FLAG_DATA;
 				syslog(LOG_NOTICE, "Profile from done to off from the panel");
 			    }
 			}
@@ -1212,7 +1212,7 @@
 	    }
 	    row++;
 	    if (updateHT)
-		publishNData(false, MQTT_NODE_HT);
+		publishNData(false, 0);
 
 	    LCDunit = 0;
 	    for (unit = Config.units; unit; unit = unit->next) {
@@ -1234,7 +1234,7 @@
 			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_AIR;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    unit->air_temperature = temp;
 			    unit->air_state = 0;
 			} else {
@@ -1254,7 +1254,7 @@
 			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_BEER;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
     			    unit->beer_temperature = temp;
 			    unit->beer_state = 0;
 			} else {
@@ -1277,13 +1277,13 @@
 			    if (unit->door_state == 0) {
 			    	syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name);
 			    	unit->door_state = 1;
-				unit->mqtt_flag |= MQTT_FLAG_DOOR;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			} else {
 			    if (unit->door_state) {
 			    	syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name);
 			    	unit->door_state = 0;
-				unit->mqtt_flag |= MQTT_FLAG_DOOR;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			}
 		    } else {
@@ -1303,13 +1303,13 @@
 			    if (unit->psu_state == 0) {
 				syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name);
 				unit->psu_state = 1;
-				unit->mqtt_flag |= MQTT_FLAG_PSU;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			} else {
 			    if (unit->psu_state) {
 				syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name);
 				unit->psu_state = 0;
-				unit->mqtt_flag |= MQTT_FLAG_PSU;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    }
 			}
 		    } else {
@@ -1465,7 +1465,7 @@
 								profile->name, run_hours / 24, run_hours % 24, run_minutes % 60, current_step, 
 								unit->prof_percent, unit->prof_fridge_mode ? (char *)"air":(char *)"beer",
 								unit->prof_target_lo, unit->prof_target_hi);
-							unit->mqtt_flag |= (MQTT_FLAG_PERCENT | MQTT_FLAG_PROFILE | MQTT_FLAG_SP);
+							unit->mqtt_flag |= MQTT_FLAG_DATA;
 						    }
 						} else {
 						    /*
@@ -1474,7 +1474,7 @@
 						    unit->prof_state = PROFILE_DONE;
 						    unit->prof_percent = 100;
 						    syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
-						    unit->mqtt_flag |= (MQTT_FLAG_PERCENT | MQTT_FLAG_PROFILE | MQTT_FLAG_SP);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
 						}
 						break;
 
@@ -1541,13 +1541,13 @@
 			} else {
 			    unit->light_state = 0;
 			    syslog(LOG_NOTICE, "Unit `%s' lights On => Off", unit->name);
-			    unit->mqtt_flag |= MQTT_FLAG_LIGHT;
+			    unit->mqtt_flag |= MQTT_FLAG_DATA;
 			}
 		    }
 		    if (!unit->door_state && !unit->light_state) {
 			unit->light_wait = unit->light_delay;   /* No delay to turn lights on   */
 			unit->light_state = 1;
-			unit->mqtt_flag |= MQTT_FLAG_LIGHT;
+			unit->mqtt_flag |= MQTT_FLAG_DATA;
 			syslog(LOG_NOTICE, "Unit `%s' lights Off => On", unit->name);
 		    }
 		    device_out(unit->light_address, unit->light_state);
@@ -1652,7 +1652,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power);
 				    unit->heater_state = power;
 				    if (unit->heater_address)
-					unit->mqtt_flag |= MQTT_FLAG_HEATER;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 			    }
 			} else {
@@ -1663,7 +1663,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
 				    unit->heater_state = 0;
 				    if (unit->heater_address)
-					unit->mqtt_flag |= MQTT_FLAG_HEATER;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 			    }
 			}
@@ -1683,7 +1683,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power);
 				    unit->cooler_state = power;
 				    if (unit->cooler_address)
-					unit->mqtt_flag |= MQTT_FLAG_COOLER;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 			    }
 			} else {
@@ -1694,7 +1694,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
 				    unit->cooler_state = 0;
 				    if (unit->cooler_address)
-					unit->mqtt_flag |= MQTT_FLAG_COOLER;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 			    }
 			}
@@ -1720,7 +1720,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name);
 				    unit->fan_state = 100;
 				    if (unit->fan_address)
-					unit->mqtt_flag |= MQTT_FLAG_FAN;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 			    	}
 			    }
 			} else {
@@ -1731,7 +1731,7 @@
 				    syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name);
 			    	    unit->fan_state = 0;
 				    if (unit->fan_address)
-					unit->mqtt_flag |= MQTT_FLAG_FAN;
+					unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 			    }
 			}
@@ -1772,7 +1772,7 @@
 		    }
 		}
 		if ((seconds == 60) && ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE))) {
-		    unit->mqtt_flag |= MQTT_FLAG_SP;
+		    unit->mqtt_flag |= MQTT_FLAG_DATA;
 		}
 #ifdef HAVE_WIRINGPI_H
 		piLock(LOCK_LCD);
@@ -1915,7 +1915,7 @@
 	device_out(unit->cooler_address, unit->cooler_state);
 	device_out(unit->fan_address, unit->fan_state);
 	device_out(unit->light_address, unit->light_state);
-	unit->mqtt_flag = MQTT_FLAG_HEATER | MQTT_FLAG_COOLER | MQTT_FLAG_FAN | MQTT_FLAG_LIGHT;
+	unit->mqtt_flag = MQTT_FLAG_DATA;
 	publishDData(unit);
 	syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]);
     }

mercurial