thermferm/server.c

changeset 513
a2732027afb3
parent 510
2da3d3340403
child 518
fd36bedab944
--- a/thermferm/server.c	Wed May 31 16:29:52 2017 +0200
+++ b/thermferm/server.c	Wed Jun 07 23:06:47 2017 +0200
@@ -1003,6 +1003,7 @@
 	srv_send((char *)"HUM_ADDRESS,%s", Config.hum_address);
 	srv_send((char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]);
 	srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0);
+	srv_send((char *)"TEMP_HUM_IDX,%d", Config.temp_hum_idx);
 	srv_send((char *)"LCD_COLS,%d", Config.lcd_cols);
 	srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows);
 	srv_send((char *)"NEXT_UNIT,%d", Config.next_unit);
@@ -1078,6 +1079,13 @@
 			} else
 			    Config.hum_address = NULL;
 
+		    } else if (val && (strcmp(kwd, (char *)"TEMP_HUM_IDX") == 0)) {
+			if (sscanf(val, "%d", &ival) == 1) {
+			    if (Config.temp_hum_idx != ival)
+				syslog(LOG_NOTICE, "Global Temp/Humidity idx %d to %d", Config.temp_hum_idx, ival);
+			    Config.temp_hum_idx = ival;
+			}
+
 		    } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) {
 			if (sscanf(val, "%d", &ival) == 1) {
 			    if (Config.lcd_cols != ival)
@@ -2004,6 +2012,8 @@
 	unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \
 			    unit->fan_address = unit->door_address = unit->light_address = \
 			    unit->psu_address = unit->profile = NULL;
+	unit->air_idx = unit->beer_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
+			unit->door_idx = unit->light_idx = unit->psu_idx = 0;
 	unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
 	unit->air_state = unit->beer_state = 1;
 	unit->air_temperature = unit->beer_temperature = 20000;
@@ -2087,13 +2097,16 @@
 		srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
 		srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
 		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_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);
 		srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address);
 		srv_send((char *)"HEATER_STATE,%d", unit->heater_state);
 		srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay);
 		srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage);
+		srv_send((char *)"HEATER_IDX,%d", unit->heater_idx);
 		if (unit->PID_heat) {
 		    srv_send((char *)"PIDH_IMAX,%.1f", unit->PID_heat->iMax);
 		    srv_send((char *)"PIDH_IDLERANGE,%.2f", unit->PID_heat->idleRange);
@@ -2106,6 +2119,7 @@
 		srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
 		srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay);
 		srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage);
+		srv_send((char *)"COOLER_IDX,%d", unit->cooler_idx);
 		if (unit->PID_cool) {
 		    srv_send((char *)"PIDC_IMAX,%.1f", unit->PID_cool->iMax);
 		    srv_send((char *)"PIDC_IDLERANGE,%.2f", unit->PID_cool->idleRange);
@@ -2118,14 +2132,18 @@
 		srv_send((char *)"FAN_STATE,%d", unit->fan_state);
 		srv_send((char *)"FAN_DELAY,%d", unit->fan_delay);
 		srv_send((char *)"FAN_USAGE,%d", unit->fan_usage);
+		srv_send((char *)"FAN_IDX,%d", unit->fan_idx);
 		srv_send((char *)"LIGHT_ADDRESS,%s", unit->light_address);
 		srv_send((char *)"LIGHT_STATE,%d", unit->light_state);
 		srv_send((char *)"LIGHT_DELAY,%d", unit->light_delay);
 		srv_send((char *)"LIGHT_USAGE,%d", unit->light_usage);
+		srv_send((char *)"LIGHT_IDX,%d", unit->light_idx);
 		srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address);
 		srv_send((char *)"DOOR_STATE,%d", unit->door_state);
+		srv_send((char *)"DOOR_IDX,%d", unit->door_idx);
 		srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address);
 		srv_send((char *)"PSU_STATE,%d", unit->psu_state);
+		srv_send((char *)"PSU_IDX,%d", unit->psu_idx);
 		srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
 		srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
 		srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
@@ -2218,6 +2236,13 @@
 				    unit->air_address  = NULL;
 				unit->mqtt_flag |= MQTT_FLAG_DATA;
 
+			    } else if (val && (strcmp(kwd, (char *)"AIR_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->air_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s air idx %d to %d", unit->uuid, unit->air_idx, ival);
+				    unit->air_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) {
 				if (val && unit->beer_address && (strcmp(val, unit->beer_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val);
@@ -2232,6 +2257,13 @@
 				    unit->beer_address = 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)
+					syslog(LOG_NOTICE, "Fermenter unit %s beer idx %d to %d", unit->uuid, unit->beer_idx, ival);
+				    unit->beer_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
 				if (val && unit->heater_address && (strcmp(val, unit->heater_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val);
@@ -2254,6 +2286,13 @@
 				    unit->mqtt_flag |= MQTT_FLAG_DATA;
 				}
 
+			    } else if (val && (strcmp(kwd, (char *)"HEATER_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->heater_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s heater idx %d to %d", unit->uuid, unit->heater_idx, ival);
+				    unit->heater_idx = ival;
+				}
+
 			    } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) {
 				if (sscanf(val, "%d", &ival) == 1) {
 				    if (unit->heater_delay != ival)
@@ -2290,6 +2329,13 @@
 				    unit->cooler_delay = ival;
 				}
 
+			    } else if (val && (strcmp(kwd, (char *)"COOLER_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->cooler_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s cooler idx %d to %d", unit->uuid, unit->cooler_idx, ival);
+				    unit->cooler_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) {
 				if (val && unit->fan_address && (strcmp(val, unit->fan_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s fan address `%s' to `%s'", unit->uuid, unit->fan_address, val);
@@ -2319,6 +2365,13 @@
 				    unit->fan_delay = ival;
 				}
 
+			    } else if (val && (strcmp(kwd, (char *)"FAN_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->fan_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s fan idx %d to %d", unit->uuid, unit->fan_idx, ival);
+				    unit->fan_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"LIGHT_ADDRESS") == 0) {
 				if (val && unit->light_address && (strcmp(val, unit->light_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s light address `%s' to `%s'", unit->uuid, unit->light_address, val);
@@ -2348,6 +2401,13 @@
 				    unit->light_delay = ival;
 				}
 
+			    } else if (val && (strcmp(kwd, (char *)"LIGHT_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->light_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s light idx %d to %d", unit->uuid, unit->light_idx, ival);
+				    unit->light_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) {
 				if (val && unit->door_address && (strcmp(val, unit->door_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val);
@@ -2361,6 +2421,13 @@
 				} else
 				    unit->door_address = NULL;
 
+			    } else if (val && (strcmp(kwd, (char *)"DOOR_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->door_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s door idx %d to %d", unit->uuid, unit->door_idx, ival);
+				    unit->door_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"PSU_ADDRESS") == 0) {
 				if (val && unit->psu_address && (strcmp(val, unit->psu_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s psu address `%s' to `%s'", unit->uuid, unit->psu_address, val);
@@ -2375,6 +2442,13 @@
 				    unit->psu_address = NULL;
 				unit->mqtt_flag |= MQTT_FLAG_DATA;
 
+			    } else if (val && (strcmp(kwd, (char *)"PSU_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->psu_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s psu idx %d to %d", unit->uuid, unit->psu_idx, ival);
+				    unit->psu_idx = ival;
+				}
+
 			    } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) {
 				for (i = 0; i < 5; i++) {
 				    if (strcmp(val, UNITMODE[i]) == 0) {

mercurial