453 if (unit->mode != i) { |
453 if (unit->mode != i) { |
454 unit->mqtt_flag |= MQTT_FLAG_DATA; |
454 unit->mqtt_flag |= MQTT_FLAG_DATA; |
455 /* Initialize log if the unit is turned on */ |
455 /* Initialize log if the unit is turned on */ |
456 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { |
456 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF)) { |
457 unit->mqtt_flag |= MQTT_FLAG_BIRTH; |
457 unit->mqtt_flag |= MQTT_FLAG_BIRTH; |
458 } else if ((unit->mode != UNITMODE_OFF) && (i == UNITMODE_OFF)) { |
|
459 unit->mqtt_flag |= MQTT_FLAG_DEATH; |
|
460 } |
458 } |
461 if (i == UNITMODE_PROFILE) { |
459 if (i == UNITMODE_PROFILE) { |
462 /* Do some checks and refuse profile mode cannot be set */ |
460 /* Do some checks and refuse profile mode cannot be set */ |
463 if (unit->profile_uuid == NULL) { |
461 if (unit->profile_uuid == NULL) { |
464 syslog(LOG_NOTICE, "Fermenter unit %s refuse profile, not loaded", message_alias); |
462 syslog(LOG_NOTICE, "Fermenter unit %s refuse profile, not loaded", message_alias); |
596 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_lo to `%.1f'", message_alias, unit->yeast_lo); |
594 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_lo to `%.1f'", message_alias, unit->yeast_lo); |
597 } |
595 } |
598 if (json_object_object_get_ex(setpoint, "yeast_hi", &val)) { |
596 if (json_object_object_get_ex(setpoint, "yeast_hi", &val)) { |
599 unit->yeast_hi = json_object_get_double(val); |
597 unit->yeast_hi = json_object_get_double(val); |
600 unit->mqtt_flag |= MQTT_FLAG_DATA; |
598 unit->mqtt_flag |= MQTT_FLAG_DATA; |
601 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_lo to `%.1f'", message_alias, unit->yeast_hi); |
599 syslog(LOG_NOTICE, "DCMD change fermenter %s: yeast_hi to `%.1f'", message_alias, unit->yeast_hi); |
602 } |
600 } |
603 } |
601 } |
604 |
602 |
605 if (json_object_object_get_ex(metric, "profile", &profile)) { |
603 if (json_object_object_get_ex(metric, "profile", &profile)) { |
606 if (json_object_object_get_ex(profile, "command", &profile1)) { |
604 if (json_object_object_get_ex(profile, "command", &profile1)) { |
1160 int comma = FALSE; |
1158 int comma = FALSE; |
1161 |
1159 |
1162 payload = payload_header(); |
1160 payload = payload_header(); |
1163 payload = xstrcat(payload, (char *)"{\"units\":["); |
1161 payload = xstrcat(payload, (char *)"{\"units\":["); |
1164 for (unit = Config.units; unit; unit = unit->next) { |
1162 for (unit = Config.units; unit; unit = unit->next) { |
1165 if (unit->mode != UNITMODE_OFF) { |
1163 // if (unit->mode != UNITMODE_OFF) { |
1166 if (comma) |
1164 if (comma) |
1167 payload = xstrcat(payload, (char *)","); |
1165 payload = xstrcat(payload, (char *)","); |
1168 payloadu = unit_data(unit, true); |
1166 payloadu = unit_data(unit, true); |
1169 payload = xstrcat(payload, payloadu); |
1167 payload = xstrcat(payload, payloadu); |
1170 comma = TRUE; |
1168 comma = TRUE; |
1171 free(payloadu); |
1169 free(payloadu); |
1172 payloadu = NULL; |
1170 payloadu = NULL; |
1173 } |
1171 // } |
1174 } |
1172 } |
1175 if (comma) { // Only publish if there is at least one unit active. |
1173 if (comma) { // Only publish if there is at least one unit active. |
1176 payload = xstrcat(payload, (char *)"]}}"); |
1174 payload = xstrcat(payload, (char *)"]}}"); |
1177 topic = topic_base((char *)"DBIRTH"); |
1175 topic = topic_base((char *)"DBIRTH"); |
1178 publisher(mosq, topic, payload, true); |
1176 publisher(mosq, topic, payload, true); |