# HG changeset patch # User Michiel Broek # Date 1533392952 -7200 # Node ID 3fc61dd286563e95217f6431b5a66baad596927b # Parent ca2fafcf3294856a349fb4650c3da5dff0b9df96 Versie 0.8.8 Fermentation stage implemented in units. diff -r ca2fafcf3294 -r 3fc61dd28656 configure --- a/configure Fri Aug 03 21:58:30 2018 +0200 +++ b/configure Sat Aug 04 16:29:12 2018 +0200 @@ -2035,7 +2035,7 @@ PACKAGE="mbsePi-apps" -VERSION="0.8.7" +VERSION="0.8.8" COPYRIGHT="Copyright (C) 2014-2018 Michiel Broek, All Rights Reserved" CYEARS="2014-2018" diff -r ca2fafcf3294 -r 3fc61dd28656 configure.ac --- a/configure.ac Fri Aug 03 21:58:30 2018 +0200 +++ b/configure.ac Sat Aug 04 16:29:12 2018 +0200 @@ -8,7 +8,7 @@ dnl General settings dnl After changeing the version number, run autoconf! PACKAGE="mbsePi-apps" -VERSION="0.8.7" +VERSION="0.8.8" COPYRIGHT="Copyright (C) 2014-2018 Michiel Broek, All Rights Reserved" CYEARS="2014-2018" AC_SUBST(PACKAGE) diff -r ca2fafcf3294 -r 3fc61dd28656 thermferm/mqtt.c --- a/thermferm/mqtt.c Fri Aug 03 21:58:30 2018 +0200 +++ b/thermferm/mqtt.c Sat Aug 04 16:29:12 2018 +0200 @@ -29,6 +29,7 @@ extern int my_shutdown; extern int my_reboot; extern const char UNITMODE[5][8]; +extern const char UNITSTAGE[3][10]; extern const char PROFSTATE[5][6]; extern const char TEMPSTATE[3][8]; @@ -305,7 +306,7 @@ (unit->product_uuid && strlen(unit->product_uuid))) { comma = false; payload = xstrcat(payload, (char *)"\"product\":{"); - if (unit->product_uuid && strlen(unit->product_uuid)) { + if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) { payload = xstrcat(payload, (char *)"\"uuid\":\""); payload = xstrcat(payload, unit->product_uuid); payload = xstrcat(payload, (char *)"\""); @@ -476,7 +477,9 @@ /* * Working mode and setpoints */ - payload = xstrcat(payload, (char *)",\"mode\":\""); + payload = xstrcat(payload, (char *)",\"stage\":\""); + payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]); + payload = xstrcat(payload, (char *)"\",\"mode\":\""); payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); payload = xstrcat(payload, (char *)"\",\"setpoint\":{\"low\":"); sprintf(buf, "%.1f", unit->PID_heat->SetP); @@ -668,7 +671,7 @@ (unit->product_uuid && strlen(unit->product_uuid))) { comma = false; payload = xstrcat(payload, (char *)"\"product\":{"); - if (unit->product_uuid && strlen(unit->product_uuid)) { + if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) { payload = xstrcat(payload, (char *)"\"uuid\":\""); payload = xstrcat(payload, unit->product_uuid); payload = xstrcat(payload, (char *)"\""); @@ -695,7 +698,9 @@ if (comma) payload = xstrcat(payload, (char *)","); - payload = xstrcat(payload, (char *)"\"stage\":\"PRIMARY\",\"mode\":\""); + payload = xstrcat(payload, (char *)"\"stage\":\""); + payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]); + payload = xstrcat(payload, (char *)"\",\"mode\":\""); payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); payload = xstrcat(payload, (char *)"\",\"temperature\":{"); comma = false; @@ -775,7 +780,6 @@ topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/"); topic = xstrcat(topic, unit->alias); publisher(mosq, topic, payload, true); -printf("%s\n", payload); free(payload); payload = NULL; free(topic); @@ -1045,8 +1049,6 @@ do { if (mqtt_status == STATUS_WAITING) { - if (debug) - fprintf(stdout, (char *)"Waiting\n"); if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) { mosquitto_disconnect(mosq); mqtt_disconnect_sent = TRUE; diff -r ca2fafcf3294 -r 3fc61dd28656 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Fri Aug 03 21:58:30 2018 +0200 +++ b/thermferm/rdconfig.c Sat Aug 04 16:29:12 2018 +0200 @@ -33,6 +33,7 @@ const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; +const char UNITSTAGE[3][10] = { "PRIMARY", "SECONDARY", "TERTIARY" }; const char PROFSTATE[5][6] = { "OFF", "PAUSE", "RUN", "DONE", "ABORT" }; const char DEVTYPE[8][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI", "SIM" }; const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; @@ -563,6 +564,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STAGE", "%s", UNITSTAGE[tmp3->stage] )) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", tmp3->beer_set)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; @@ -1145,7 +1150,7 @@ unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = unit->beer_set = unit->fridge_set = 20.0; unit->air_state = unit->beer_state = unit->chiller_state = 1; // missing unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \ - unit->light_state = unit->psu_state = unit->mode = unit->prof_state = 0; + unit->light_state = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0; unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ unit->door_idx = unit->light_idx = unit->psu_idx = 0; unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ @@ -1381,6 +1386,16 @@ } xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"STAGE"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + for (i = 0; i < 3; i++) { + if (! xmlStrcmp(key, (const xmlChar *)UNITSTAGE[i])) { + unit->stage = i; + break; + } + } + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_SET"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%f", &val) == 1) diff -r ca2fafcf3294 -r 3fc61dd28656 thermferm/server.c --- a/thermferm/server.c Fri Aug 03 21:58:30 2018 +0200 +++ b/thermferm/server.c Sat Aug 04 16:29:12 2018 +0200 @@ -36,6 +36,7 @@ extern int run_hold; extern sys_config Config; extern const char UNITMODE[5][8]; +extern const char UNITSTAGE[3][10]; extern const char TEMPSTATE[3][8]; extern const char DEVTYPE[8][6]; extern const char DEVPRESENT[4][6]; @@ -1985,7 +1986,7 @@ unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = 20000; unit->beer_set = unit->fridge_set = 20.0; unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \ - unit->light_state = unit->psu_state = unit->prof_state = 0; + unit->light_state = unit->psu_state = unit->prof_state = unit->stage = 0; unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ unit->light_delay = 1; /* 15 seconds delay */ unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; @@ -2061,6 +2062,7 @@ srv_send((char *)"PRODUCT_NAME,%s", unit->product_name); srv_send((char *)"PRODUCT_CODE,%s", unit->product_code); srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); + srv_send((char *)"STAGE,%s", UNITSTAGE[unit->stage]); srv_send((char *)"VOLUME,%2f", unit->volume); srv_send((char *)"AIR_ADDRESS,%s", unit->air_address); srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]); @@ -2452,6 +2454,18 @@ unit->psu_idx = ival; } + } else if (val && (strcmp(kwd, (char *)"STAGE") == 0)) { + for (i = 0; i < 3; i++) { + if (strcmp(val, UNITSTAGE[i]) == 0) { + if (i != unit->stage) { + syslog(LOG_NOTICE, "Fermenter unit %s stage %s to %s", unit->uuid, UNITSTAGE[unit->stage], UNITSTAGE[i]); + unit->mqtt_flag |= MQTT_FLAG_DATA; + } + unit->stage = i; + break; + } + } + } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { for (i = 0; i < 5; i++) { if (strcmp(val, UNITMODE[i]) == 0) { diff -r ca2fafcf3294 -r 3fc61dd28656 thermferm/thermferm.h --- a/thermferm/thermferm.h Fri Aug 03 21:58:30 2018 +0200 +++ b/thermferm/thermferm.h Sat Aug 04 16:29:12 2018 +0200 @@ -199,6 +199,7 @@ char *event_msg; /* Event message to log */ int alarm_flag; /* Alarm flag */ int alarm_last; /* Last alarm state */ + int stage; /* Fermentation stage */ } units_list; #define UNITMODE_OFF 0 /* Unit turned off */ @@ -207,6 +208,10 @@ #define UNITMODE_BEER 3 /* Unit acts as beer cooler */ #define UNITMODE_PROFILE 4 /* Unit runs in profile mode */ +#define UNITSTAGE_PRIMARY 0 /* Fermentation primary stage */ +#define UNITSTAGE_SECONDARY 1 /* Fermentation secondary stage */ +#define UNITSTAGE_TERTIARY 2 /* Fermentation tertiary stage */ + #define MQTT_FLAG_DATA 0x0001 /* Show updated data values */ #define MQTT_FLAG_BIRTH 0x0002 /* Show birth instead of data */ #define MQTT_FLAG_DEATH 0x0004 /* Show death of a unit */ diff -r ca2fafcf3294 -r 3fc61dd28656 www-thermferm/units.php --- a/www-thermferm/units.php Fri Aug 03 21:58:30 2018 +0200 +++ b/www-thermferm/units.php Sat Aug 04 16:29:12 2018 +0200 @@ -92,6 +92,7 @@ $cmd[] = "PRODUCT_CODE,".$_POST['ProductCode']; $cmd[] = "PRODUCT_NAME,".$_POST['ProductName']; $cmd[] = "VOLUME,".$_POST['Volume']; + $cmd[] = "STAGE,".$_POST['Stage']; $cmd[] = "AIR_ADDRESS,".$_POST['AirAddress']; $cmd[] = "AIR_IDX,".$_POST['AirIdx']; $cmd[] = "BEER_ADDRESS,".$_POST['BeerAddress']; @@ -134,6 +135,7 @@ unset($_POST['ProductName']); unset($_POST['ProductCode']); unset($_POST['Volume']); + Unset($_POST['Stage']); unset($_POST['key']); unset($_POST['command']); unset($_POST['AirAddress']); @@ -211,7 +213,7 @@ isset($_POST['PIDH_pGain']) && isset($_POST['PIDH_iGain']) && isset($_POST['PIDH_dGain']) && isset($_POST['PIDH_idleRange']) && isset($_POST['PIDC_iMax']) && isset($_POST['PIDH_iMax']) && isset($_POST['AirIdx']) && isset($_POST['BeerIdx']) && isset($_POST['HeaterIdx']) && isset($_POST['CoolerIdx']) && isset($_POST['LightIdx']) && isset($_POST['DoorIdx']) && - isset($_POST['PSUIdx']) && isset($_POST['FanIdx']) && isset($_POST['ChillerIdx']) && + isset($_POST['PSUIdx']) && isset($_POST['FanIdx']) && isset($_POST['ChillerIdx']) && isset($_POST['Stage']) && isset($_POST['FanDelay']) && isset($_POST['key']) && isset($_POST['command'])) { if ($_POST['key'] == 'Cancel') @@ -377,10 +379,22 @@ $outstr .= ' '.PHP_EOL; } + if ($f[0] == "STAGE") { + $outstr .= ' '.PHP_EOL; + $outstr .= ' Fermentation'.PHP_EOL; + $outstr .= ' '.PHP_EOL; + } + if ($f[0] == "VOLUME") { - $outstr .= ' '.PHP_EOL; $outstr .= ' Unit Volume'.PHP_EOL; - $outstr .= ' '.PHP_EOL; + $outstr .= ' '.PHP_EOL; $outstr .= ' '.PHP_EOL; } @@ -804,6 +818,7 @@ $outstr .= ' '.PHP_EOL; $outstr .= ''; $outstr .= ''; + $outstr .= ''; $outstr .= ''; $outstr .= ''; $outstr .= '';