thermferm/mqtt.c

changeset 575
86496d2bc4bb
parent 571
6f8eda55ec2c
child 577
7a29f835e20a
equal deleted inserted replaced
574:362c4700937e 575:86496d2bc4bb
221 if (strcmp((char *)json_object_get_string(val), UNITSTAGE[i]) == 0) { 221 if (strcmp((char *)json_object_get_string(val), UNITSTAGE[i]) == 0) {
222 if (unit->stage != i) { 222 if (unit->stage != i) {
223 syslog(LOG_NOTICE, "DCMD change fermenter %s: stage to %s", message_alias, UNITSTAGE[i]); 223 syslog(LOG_NOTICE, "DCMD change fermenter %s: stage to %s", message_alias, UNITSTAGE[i]);
224 unit->mqtt_flag |= MQTT_FLAG_DATA; 224 unit->mqtt_flag |= MQTT_FLAG_DATA;
225 unit->stage = i; 225 unit->stage = i;
226 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg)
227 unit->event_msg = xstrcpy((char *)UNITSTAGE[i]);
226 } 228 }
227 break; 229 break;
228 } 230 }
229 } 231 }
230 } 232 }
248 break; 250 break;
249 } 251 }
250 } 252 }
251 syslog(LOG_NOTICE, "DCMD change fermenter %s: mode to %s", message_alias, UNITMODE[i]); 253 syslog(LOG_NOTICE, "DCMD change fermenter %s: mode to %s", message_alias, UNITMODE[i]);
252 unit->mode = i; 254 unit->mode = i;
255 if ((unit->mode != UNITMODE_OFF) && ! unit->event_msg)
256 unit->event_msg = xstrcpy((char *)UNITMODE[i]);
253 /* Allways turn everything off after a mode change */ 257 /* Allways turn everything off after a mode change */
254 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; 258 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
255 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; 259 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
256 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; 260 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
257 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 261 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
393 unit->prof_started = time(NULL); 397 unit->prof_started = time(NULL);
394 unit->prof_paused = unit->prof_primary_done = 0; 398 unit->prof_paused = unit->prof_primary_done = 0;
395 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; 399 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
396 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile start RUN", message_alias); 400 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile start RUN", message_alias);
397 unit->mqtt_flag |= MQTT_FLAG_DATA; 401 unit->mqtt_flag |= MQTT_FLAG_DATA;
402 if (! unit->event_msg)
403 unit->event_msg = xstrcpy((char *)"Profile start");
398 } 404 }
399 } else if (! strcmp(cmd, (char *)"abort")) { 405 } else if (! strcmp(cmd, (char *)"abort")) {
400 if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) { 406 if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
401 unit->prof_state = PROFILE_OFF; 407 unit->prof_state = PROFILE_OFF;
402 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0; 408 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
403 unit->prof_peak_abs = unit->prof_peak_rel = 0.0; 409 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
404 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile ABORT", message_alias); 410 syslog(LOG_NOTICE, "DCMD change fermenter `%s' profile ABORT", message_alias);
405 unit->mqtt_flag |= MQTT_FLAG_DATA; 411 unit->mqtt_flag |= MQTT_FLAG_DATA;
412 if (! unit->event_msg)
413 unit->event_msg = xstrcpy((char *)"Profile abort");
406 } 414 }
407 } else if (! strcmp(cmd, (char *)"done")) { 415 } else if (! strcmp(cmd, (char *)"done")) {
408 if (unit->prof_state == PROFILE_DONE) { 416 if (unit->prof_state == PROFILE_DONE) {
409 unit->prof_state = PROFILE_OFF; 417 unit->prof_state = PROFILE_OFF;
410 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0; 418 unit->prof_started = unit->prof_paused = unit->prof_primary_done = 0;
545 publishDData(unit); 553 publishDData(unit);
546 } 554 }
547 if (unit->mqtt_flag & MQTT_FLAG_DEATH) { 555 if (unit->mqtt_flag & MQTT_FLAG_DEATH) {
548 publishDDeath(unit); 556 publishDDeath(unit);
549 } 557 }
550 unit->mqtt_flag |= MQTT_FLAG_DLOG; // Something to log
551 } 558 }
552 } 559 }
553 return; 560 return;
554 } 561 }
555 syslog(LOG_NOTICE, "MQTT: %s payload not understood\n", (char *)message->payload); 562 syslog(LOG_NOTICE, "MQTT: %s payload not understood\n", (char *)message->payload);

mercurial