Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.

Sat, 19 Jan 2019 11:38:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 19 Jan 2019 11:38:09 +0100
changeset 571
6f8eda55ec2c
parent 570
1e0192b295b9
child 572
0df7fcb36b76

Version 0.9.1. Added fermentation profiles via MQTT. Added uuid field for loaded product. Removed some debug messages in the simulator. Removed dead code and debug messages from the lcd driver.

configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
thermferm/mqtt.c file | annotate | diff | comparison | revisions
thermferm/simulator.c file | annotate | diff | comparison | revisions
thermferm/slcd.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- a/configure	Mon Jan 14 22:46:27 2019 +0100
+++ b/configure	Sat Jan 19 11:38:09 2019 +0100
@@ -2035,7 +2035,7 @@
 
 
 PACKAGE="mbsePi-apps"
-VERSION="0.9.0"
+VERSION="0.9.1"
 COPYRIGHT="Copyright (C) 2014-2019 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2019"
 
--- a/configure.ac	Mon Jan 14 22:46:27 2019 +0100
+++ b/configure.ac	Sat Jan 19 11:38:09 2019 +0100
@@ -8,7 +8,7 @@
 dnl General settings
 dnl After changeing the version number, run autoconf!
 PACKAGE="mbsePi-apps"
-VERSION="0.9.0"
+VERSION="0.9.1"
 COPYRIGHT="Copyright (C) 2014-2019 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2019"
 AC_SUBST(PACKAGE)
--- a/thermferm/mqtt.c	Mon Jan 14 22:46:27 2019 +0100
+++ b/thermferm/mqtt.c	Sat Jan 19 11:38:09 2019 +0100
@@ -230,10 +230,9 @@
 			    	}
 
 				if (json_object_object_get_ex(metric, "mode", &val)) {
-				    for (int i = 0; i < 4; i++) {
+				    for (int i = 0; i < 5; i++) {
 					if (strcmp((char *)json_object_get_string(val), UNITMODE[i]) == 0) {
 					    if (unit->mode != i) {
-						syslog(LOG_NOTICE, "DCMD change fermenter %s: mode to %s", message_alias, UNITMODE[i]);
 						unit->mqtt_flag |= MQTT_FLAG_DATA;
 						/* Initialize log if the unit is turned on */
 						if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) {
@@ -242,7 +241,14 @@
 						} else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) {
 						    unit->mqtt_flag |= MQTT_FLAG_DEATH;
 						}
-						syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]);
+						if (i == UNITMODE_PROFILE) {
+						    /* Do some checks and refuse profile mode cannot be set */
+						    if (unit->profile_uuid == NULL) {
+							syslog(LOG_NOTICE, "Fermenter unit %s refuse profile, not loaded", message_alias);
+							break;
+						    }
+						}
+						syslog(LOG_NOTICE, "DCMD change fermenter %s: mode to %s", message_alias, UNITMODE[i]);
 						unit->mode = i;
 						/* Allways turn everything off after a mode change */
 						unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
@@ -258,11 +264,12 @@
 						     * Set a sane default until it will be overruled by the
 						     * main processing loop.
 						     */
-						    unit->prof_target_lo = unit->prof_target_hi = 20.0;
+						    unit->prof_target_lo = unit->profile_inittemp_lo;
+						    unit->prof_target_hi = unit->profile_inittemp_hi;;
 						    unit->prof_fridge_mode = 0;
-						    if (unit->profile_uuid) {
-							unit->mqtt_flag |= MQTT_FLAG_DATA;
-						    }
+						    unit->prof_state = PROFILE_OFF;
+						    unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
+						    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
 						}
 					    }
 					    break;
@@ -349,12 +356,66 @@
 					    syslog(LOG_NOTICE, "DCMD change fermenter %s: product_name to `%s'", message_alias, unit->product_name);
 					}
 				    }
+				    if (json_object_object_get_ex(setpoint, "uuid", &val)) {
+					if (strcmp((char *)json_object_get_string(val), unit->product_uuid)) {
+					    free(unit->product_uuid);
+					    unit->product_uuid = xstrcpy((char *)json_object_get_string(val));
+					    unit->mqtt_flag |= MQTT_FLAG_DATA;
+					    syslog(LOG_NOTICE, "DCMD change fermenter %s: product_uuid to `%s'", message_alias, unit->product_uuid);
+					}
+				    }
 				}
 
 				if (json_object_object_get_ex(metric, "profile", &profile)) {
 				    if (json_object_object_get_ex(profile, "command", &profile1)) {
 					syslog(LOG_NOTICE, "profile command");
-
+					if (unit->mode == UNITMODE_PROFILE) {
+					    char *cmd = xstrcpy((char *)json_object_get_string(profile1));
+					    if (! strcmp(cmd, (char *)"off")) {
+						if (unit->prof_state == PROFILE_DONE) {
+						    unit->prof_state = PROFILE_OFF;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile to OFF", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+						}
+					    } else if (! strcmp(cmd, (char *)"pause")) {
+					    	if (unit->prof_state == PROFILE_RUN) {
+						    unit->prof_state = PROFILE_PAUSE;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile to PAUSE", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+					    	} else if (unit->prof_state == PROFILE_PAUSE) {
+						    unit->prof_state = PROFILE_RUN;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile resume RUN", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+					    	}
+				    	    } else if (! strcmp(cmd, (char *)"start")) {
+						if (unit->prof_state == PROFILE_OFF) {
+						    unit->prof_state = PROFILE_RUN;
+						    unit->prof_started = time(NULL);
+						    unit->prof_paused = unit->prof_primary_done = 0;
+						    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile start RUN", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+						}
+				            } else if (! strcmp(cmd, (char *)"abort")) {
+						if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
+						    unit->prof_state = PROFILE_OFF;
+						    unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
+						    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile ABORT", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+						}
+					    } else if (! strcmp(cmd, (char *)"done")) {
+						if (unit->prof_state == PROFILE_DONE) {
+						    unit->prof_state = PROFILE_OFF;
+						    unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
+						    unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
+						    syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile OFF", message_alias);
+						    unit->mqtt_flag |= MQTT_FLAG_DATA;
+						}
+					    }
+					    free(cmd);
+					    cmd = NULL;
+					}
 				    } else if (json_object_object_get_ex(profile, "uuid", &profile1)) {
 //					syslog(LOG_NOTICE, "profile new profile");
 					if ((unit->prof_state == PROFILE_OFF) || (unit->prof_state == PROFILE_DONE) || (unit->prof_state == PROFILE_ABORT)) {
--- a/thermferm/simulator.c	Mon Jan 14 22:46:27 2019 +0100
+++ b/thermferm/simulator.c	Sat Jan 19 11:38:09 2019 +0100
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2008-2018
+ * Copyright (C) 2014-2019
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -48,8 +48,6 @@
     double		air_change, vhc_air = 0.00121;
 
     syslog(LOG_NOTICE, "Thread my_simulator_loop started");
-    if (debug)
-	fprintf(stdout, "Thread my_simulator_loop started\n");
 
     for (simulator = Config.simulators; simulator; simulator = simulator->next) {
 	/*
@@ -128,9 +126,9 @@
 		simulator->air_temperature += ((simulator->beer_temperature - simulator->air_temperature) / 2500.0);
 		simulator->chiller_temperature = simulator->cooler_temp;	// Libk these
 
-		if ((seconds % 15) == 0)
-		    syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature,
-				simulator->s_heat_temp, simulator->s_cool_temp);
+//		if ((seconds % 15) == 0)
+//		    syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature,
+//				simulator->s_heat_temp, simulator->s_cool_temp);
 
 //		if (debug)
 //		    fprintf(stdout, "sqm_room_air=%f air=%f air_heat_transfer=%f air_change=%f beer=%f\n",
@@ -142,8 +140,6 @@
     }
 
     syslog(LOG_NOTICE, "Thread my_simulator_loop stopped");
-    if (debug)
-	fprintf(stdout, "Thread my_simulator_loop stopped\n");
     return 0;
 }
 
--- a/thermferm/slcd.c	Mon Jan 14 22:46:27 2019 +0100
+++ b/thermferm/slcd.c	Sat Jan 19 11:38:09 2019 +0100
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2015
+ * Copyright (C) 2015-2019
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -33,7 +33,6 @@
 uint16_t		leds = 0x0400;	/* LED's, buzzer, LCD backlight	*/
 uint16_t		oleds = 0x0400;
 
-extern int		debug;
 
 
 void putLCDsocket(int fd, uint16_t data)
@@ -59,12 +58,7 @@
 	    sock = -1;
 	} else {
 	    if ((rdat & SLCD_MKEYS) == SLCD_KEYS) {
-		if (((rdat & 0x00ff) != keys) && debug)
-		    fprintf(stdout, "received keys %04x was %04x\n", rdat & 0x00ff, keys);
 		keys = rdat & 0x00ff;
-	    } else {
-	        if (debug)
-		    fprintf(stdout, "received %04x\n", rdat);
 	    }
 
 	}
@@ -88,11 +82,6 @@
 }
 
 
-//void slcdHome(int fd)
-//{
-//}
-
-
 
 void slcdClear(int fd)
 {
@@ -102,30 +91,6 @@
 
 
 
-//void slcdDisplay(int fd, int state)
-//{
-//}
-
-
-
-//void slcdCursor(int fd, int state)
-//{
-//}
-
-
-
-//void slcdCursorBlink(int fd, int state)
-//{
-//}
-
-
-
-//void slcdSendCommand(int fd, unsigned char command)
-//{
-//}
-
-
-
 void slcdPosition(int fd, int x, int y)
 {
     uint16_t	data = SLCD_DGRAM;
@@ -165,12 +130,6 @@
 
 
 
-//void slcdPrintf(int fd, const char *message, ...)
-//{
-//}
-
-
-
 /*
  * Try to setup a udp connection to 127.0.0.1 so we duplicate the panel
  * display and keys of the real panel. This should fail on a production
--- a/thermferm/thermferm.c	Mon Jan 14 22:46:27 2019 +0100
+++ b/thermferm/thermferm.c	Sat Jan 19 11:38:09 2019 +0100
@@ -1484,10 +1484,9 @@
 					if (valid_step == TRUE) {
 					    unit->prof_percent = (100 * run_minutes) / tot_minutes;
 					    if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) {
-					    	syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %s %.3f..%.3f degrees", 
+					    	syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, fridge/beer %d%% %.3f..%.3f degrees", 
 							unit->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->prof_percent, unit->prof_fridge_mode, unit->prof_target_lo, unit->prof_target_hi);
 						unit->mqtt_flag |= MQTT_FLAG_DATA;
 					    }
 					} else {

mercurial