thermferm/server.c

changeset 614
389097dc665d
parent 606
798dd0c4fd00
child 645
49eb753a958b
--- a/thermferm/server.c	Fri May 28 14:25:56 2021 +0200
+++ b/thermferm/server.c	Sun Jul 10 14:33:13 2022 +0200
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2008-2020
+ * Copyright (C) 2008-2022
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -1210,6 +1210,9 @@
 		if (current->beer_address)
 		    free(current->beer_address);
 		current->beer_address = NULL;
+		if (current->beer_address2)
+                    free(current->beer_address2);
+                current->beer_address2 = NULL;
 		if (current->chiller_address)
 		    free(current->chiller_address);
 		current->chiller_address = NULL;
@@ -1270,6 +1273,9 @@
 		if (current->beer_address)
 		    free(current->beer_address);
 		current->beer_address = NULL;
+		if (current->beer_address2)
+                    free(current->beer_address2);
+                current->beer_address2 = NULL;
 		if (current->chiller_address)
 		    free(current->chiller_address);
 		current->chiller_address = NULL;
@@ -1393,7 +1399,7 @@
 	unit->product_code = xstrcpy((char *)"FAKE0000");
 	unit->product_name = xstrcpy(param);
 	unit->alias = xstrcpy(an);
-	unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = unit->cooler_address = \
+	unit->air_address = unit->beer_address = unit->beer_address2 = unit->chiller_address = unit->heater_address = unit->cooler_address = \
 			    unit->fan_address = unit->door_address = unit->light_address = \
 			    unit->psu_address = unit->profile_uuid = unit->profile_name = NULL;
 	unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
@@ -1488,6 +1494,7 @@
 		srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0);
 		srv_send((char *)"AIR_IDX,%d", unit->air_idx);
 		srv_send((char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address));
+		srv_send((char *)"BEER_ADDRESS2,%s", MBSE_SS(unit->beer_address2));
 		srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]);
 		srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0);
 		srv_send((char *)"BEER_IDX,%d", unit->beer_idx);
@@ -1670,6 +1677,20 @@
 				    unit->beer_address = NULL;
 				unit->mqtt_flag |= MQTT_FLAG_DATA;
 
+			    } else if (strcmp(kwd, (char *)"BEER_ADDRESS2") == 0) {
+                                if (val && unit->beer_address2 && (strcmp(val, unit->beer_address2)))
+                                    syslog(LOG_NOTICE, "Fermenter unit %s beer address alt `%s' to `%s'", unit->uuid, unit->beer_address2, val);
+                                if (unit->beer_address2) {
+                                    device_count(FALSE, unit->beer_address2);
+                                    free(unit->beer_address2);
+                                }
+                                if (val) {
+                                    unit->beer_address2 = xstrcpy(val);
+                                    device_count(TRUE, unit->beer_address2);
+                                } else
+                                    unit->beer_address2 = NULL;
+                                unit->mqtt_flag |= MQTT_FLAG_DATA;
+
 			    } else if (val && (strcmp(kwd, (char *)"BEER_IDX") == 0)) {
 				if (sscanf(val, "%d", &ival) == 1) {
 				    if (unit->beer_idx != ival)

mercurial