diff -r 4903b4da9d40 -r 602d9968960f thermferm/server.c --- a/thermferm/server.c Sat Apr 30 21:25:10 2016 +0200 +++ b/thermferm/server.c Mon May 02 16:15:37 2016 +0200 @@ -27,6 +27,7 @@ #include "server.h" #include "lcd-buffer.h" #include "xutil.h" +#include "mqtt.h" extern int my_shutdown; @@ -2175,8 +2176,10 @@ */ if (val && (strcmp(kwd, (char *)"NAME") == 0)) { if (unit->name) { - if (strcmp(unit->name, val)) + if (strcmp(unit->name, val)) { syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val); + mqtt_publish_str(unit->uuid, (char *)"name", val); + } free(unit->name); } unit->name = xstrcpy(val); @@ -2356,6 +2359,7 @@ initlog(unit->name); syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); unit->mode = i; + unit->mqtt_flag |= (MQTT_FLAG_MODE | MQTT_FLAG_SP); /* Allways turn everything off after a mode change */ unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; @@ -2372,7 +2376,17 @@ */ unit->prof_target_lo = unit->prof_target_hi = 20.0; unit->prof_fridge_mode = 0; + if (unit->profile) { + unit->mqtt_flag |= MQTT_FLAG_PROFILE; + unit->mqtt_flag |= MQTT_FLAG_SP; + } } + if (unit->heater_address) + mqtt_publish_int(unit->uuid, (char *)"heater", 0); + if (unit->cooler_address) + mqtt_publish_int(unit->uuid, (char *)"cooler", 0); + if (unit->fan_address) + mqtt_publish_int(unit->uuid, (char *)"fan", 0); break; } } @@ -2382,6 +2396,7 @@ if (unit->fridge_set != fval) syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval); unit->fridge_set = fval; + unit->mqtt_flag |= MQTT_FLAG_SP; } } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) { @@ -2389,6 +2404,7 @@ if (unit->beer_set != fval) syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval); unit->beer_set = fval; + unit->mqtt_flag |= MQTT_FLAG_SP; } } else if (val && (strcmp(kwd, (char *)"PIDC_IMAX") == 0)) { @@ -2486,6 +2502,13 @@ device_out(unit->cooler_address, unit->cooler_state); device_out(unit->fan_address, unit->fan_state); device_out(unit->light_address, unit->light_state); + if (unit->heater_address) + mqtt_publish_int(unit->uuid, (char *)"heater", 0); + if (unit->cooler_address) + mqtt_publish_int(unit->uuid, (char *)"cooler", 0); + if (unit->fan_address) + mqtt_publish_int(unit->uuid, (char *)"fan", 0); + unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP); } } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { @@ -2495,14 +2518,17 @@ case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) { unit->prof_state = PROFILE_OFF; syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid); + mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); } break; case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) { unit->prof_state = PROFILE_PAUSE; syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid); + mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); } else if (unit->prof_state == PROFILE_PAUSE) { unit->prof_state = PROFILE_RUN; syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid); + mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[PROFILE_RUN]); } break; case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) { @@ -2511,6 +2537,7 @@ unit->prof_paused = unit->prof_primary_done = 0; unit->prof_peak_abs = unit->prof_peak_rel = 0.0; syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid); + mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); } break; case PROFILE_DONE: break; /* Command is illegal */ @@ -2518,9 +2545,11 @@ unit->prof_state = PROFILE_OFF; unit->prof_started = 0; syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid); + mqtt_publish_str(unit->uuid, (char *)"profile/state", (char *)PROFSTATE[i]); } break; } + unit->mqtt_flag |= (MQTT_FLAG_SP | MQTT_FLAG_PROFILE | MQTT_FLAG_PERCENT); break; } }