298 payload = xstrcat(payload, (char *)"\","); |
298 payload = xstrcat(payload, (char *)"\","); |
299 } |
299 } |
300 |
300 |
301 /* |
301 /* |
302 * Product (beer) loaded information. |
302 * Product (beer) loaded information. |
303 * TODO: extend with uuid and product code. |
303 */ |
304 */ |
304 if ((unit->product_name && strlen(unit->product_name)) || |
305 if (unit->name || strlen(unit->name)) { |
305 (unit->product_code && strlen(unit->product_code)) || |
306 payload = xstrcat(payload, (char *)"\"product\":{\"code\":null,\"name\":\""); |
306 (unit->product_uuid && strlen(unit->product_uuid))) { |
307 payload = xstrcat(payload, unit->name); |
307 comma = false; |
308 payload = xstrcat(payload, (char *)"\"}"); |
308 payload = xstrcat(payload, (char *)"\"product\":{"); |
309 } else { |
309 if (unit->product_uuid && strlen(unit->product_uuid)) { |
310 payload = xstrcat(payload, (char *)"\"product\":null"); |
310 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
|
311 payload = xstrcat(payload, unit->product_uuid); |
|
312 payload = xstrcat(payload, (char *)"\""); |
|
313 comma = true; |
|
314 } |
|
315 if (unit->product_code && strlen(unit->product_code)) { |
|
316 if (comma) |
|
317 payload = xstrcat(payload, (char *)","); |
|
318 payload = xstrcat(payload, (char *)"\"code\":\""); |
|
319 payload = xstrcat(payload, unit->product_code); |
|
320 payload = xstrcat(payload, (char *)"\""); |
|
321 comma = true; |
|
322 } |
|
323 if (unit->product_name && strlen(unit->product_name)) { |
|
324 if (comma) |
|
325 payload = xstrcat(payload, (char *)","); |
|
326 payload = xstrcat(payload, (char *)"\"name\":\""); |
|
327 payload = xstrcat(payload, unit->product_name); |
|
328 payload = xstrcat(payload, (char *)"\""); |
|
329 } |
|
330 payload = xstrcat(payload, (char *)"}"); |
311 } |
331 } |
312 |
332 |
313 /* |
333 /* |
314 * Air temperature sensor |
334 * Air temperature sensor |
315 */ |
335 */ |
624 } |
644 } |
625 } |
645 } |
626 |
646 |
627 |
647 |
628 |
648 |
|
649 void publishDLog(units_list *unit) |
|
650 { |
|
651 char buf[32], *payload = NULL, *topic = NULL; |
|
652 bool comma = false; |
|
653 |
|
654 if (mqtt_use) { |
|
655 payload = payload_header(); |
|
656 payload = xstrcat(payload, (char *)"{"); |
|
657 |
|
658 if ((unit->product_name && strlen(unit->product_name)) || |
|
659 (unit->product_code && strlen(unit->product_code)) || |
|
660 (unit->product_uuid && strlen(unit->product_uuid))) { |
|
661 comma = false; |
|
662 payload = xstrcat(payload, (char *)"\"product\":{"); |
|
663 if (unit->product_uuid && strlen(unit->product_uuid)) { |
|
664 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
|
665 payload = xstrcat(payload, unit->product_uuid); |
|
666 payload = xstrcat(payload, (char *)"\""); |
|
667 comma = true; |
|
668 } |
|
669 if (unit->product_code && strlen(unit->product_code)) { |
|
670 if (comma) |
|
671 payload = xstrcat(payload, (char *)","); |
|
672 payload = xstrcat(payload, (char *)"\"code\":\""); |
|
673 payload = xstrcat(payload, unit->product_code); |
|
674 payload = xstrcat(payload, (char *)"\""); |
|
675 comma = true; |
|
676 } |
|
677 if (unit->product_name && strlen(unit->product_name)) { |
|
678 if (comma) |
|
679 payload = xstrcat(payload, (char *)","); |
|
680 payload = xstrcat(payload, (char *)"\"name\":\""); |
|
681 payload = xstrcat(payload, unit->product_name); |
|
682 payload = xstrcat(payload, (char *)"\""); |
|
683 } |
|
684 payload = xstrcat(payload, (char *)"}"); |
|
685 comma = true; |
|
686 } |
|
687 |
|
688 if (comma) |
|
689 payload = xstrcat(payload, (char *)","); |
|
690 payload = xstrcat(payload, (char *)"\"stage\":\"PRIMARY\",\"mode\":\""); |
|
691 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); |
|
692 payload = xstrcat(payload, (char *)"\",\"temperature\":{"); |
|
693 comma = false; |
|
694 if (unit->air_address) { |
|
695 payload = xstrcat(payload, (char *)"\"air\":"); |
|
696 sprintf(buf, "%.3f", unit->air_temperature / 1000.0); |
|
697 payload = xstrcat(payload, buf); |
|
698 comma = true; |
|
699 } |
|
700 if (unit->beer_address) { |
|
701 if (comma) |
|
702 payload = xstrcat(payload, (char *)","); |
|
703 payload = xstrcat(payload, (char *)"\"beer\":"); |
|
704 sprintf(buf, "%.3f", unit->beer_temperature / 1000.0); |
|
705 payload = xstrcat(payload, buf); |
|
706 comma = true; |
|
707 } |
|
708 if (unit->chiller_address) { |
|
709 if (comma) |
|
710 payload = xstrcat(payload, (char *)","); |
|
711 payload = xstrcat(payload, (char *)"\"chiller\":"); |
|
712 sprintf(buf, "%.3f", unit->chiller_temperature / 1000.0); |
|
713 payload = xstrcat(payload, buf); |
|
714 comma = true; |
|
715 } |
|
716 if (Config.temp_address) { |
|
717 if (comma) |
|
718 payload = xstrcat(payload, (char *)","); |
|
719 payload = xstrcat(payload, (char *)"\"room\":"); |
|
720 sprintf(buf, "%.1f", Config.temp_value / 1000.0); |
|
721 payload = xstrcat(payload, buf); |
|
722 } |
|
723 payload = xstrcat(payload, (char *)"},\"setpoint\":{\"low\":"); |
|
724 sprintf(buf, "%.1f", unit->PID_heat->SetP); |
|
725 payload = xstrcat(payload, buf); |
|
726 payload = xstrcat(payload, (char *)",\"high\":"); |
|
727 sprintf(buf, "%.1f", unit->PID_cool->SetP); |
|
728 payload = xstrcat(payload, buf); |
|
729 payload = xstrcat(payload, (char *)"}"); |
|
730 if (unit->heater_address) { |
|
731 payload = xstrcat(payload, (char *)",\"heater\":{\"power\":"); |
|
732 sprintf(buf, "%d", unit->heater_state); |
|
733 payload = xstrcat(payload, buf); |
|
734 payload = xstrcat(payload, (char *)",\"usage\":"); |
|
735 sprintf(buf, "%d", unit->heater_usage); |
|
736 payload = xstrcat(payload, buf); |
|
737 payload = xstrcat(payload, (char *)"}"); |
|
738 } |
|
739 if (unit->cooler_address) { |
|
740 payload = xstrcat(payload, (char *)",\"cooler\":{\"power\":"); |
|
741 sprintf(buf, "%d", unit->cooler_state); |
|
742 payload = xstrcat(payload, buf); |
|
743 payload = xstrcat(payload, (char *)",\"usage\":"); |
|
744 sprintf(buf, "%d", unit->cooler_usage); |
|
745 payload = xstrcat(payload, buf); |
|
746 payload = xstrcat(payload, (char *)"}"); |
|
747 } |
|
748 if (unit->fan_address) { |
|
749 payload = xstrcat(payload, (char *)",\"fan\":{\"power\":"); |
|
750 sprintf(buf, "%d", unit->fan_state); |
|
751 payload = xstrcat(payload, buf); |
|
752 payload = xstrcat(payload, (char *)",\"usage\":"); |
|
753 sprintf(buf, "%d", unit->fan_usage); |
|
754 payload = xstrcat(payload, buf); |
|
755 payload = xstrcat(payload, (char *)"}"); |
|
756 } |
|
757 // sg |
|
758 if (unit->event_msg) { |
|
759 payload = xstrcat(payload, (char *)",\"event\":\""); |
|
760 payload = xstrcat(payload, unit->event_msg); |
|
761 payload = xstrcat(payload, (char *)"\""); |
|
762 } |
|
763 payload = xstrcat(payload, (char *)"}}"); |
|
764 |
|
765 topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/"); |
|
766 topic = xstrcat(topic, unit->alias); |
|
767 publisher(mosq, topic, payload, true); |
|
768 printf("%s\n", payload); |
|
769 free(payload); |
|
770 payload = NULL; |
|
771 free(topic); |
|
772 topic = NULL; |
|
773 } |
|
774 } |
|
775 |
|
776 |
|
777 |
629 void publishNData(bool birth, int flag) |
778 void publishNData(bool birth, int flag) |
630 { |
779 { |
631 char *payload = NULL, sidx[10], buf[64]; |
780 char *payload = NULL, sidx[10], buf[64]; |
632 struct utsname ubuf; |
781 struct utsname ubuf; |
633 bool comma = false; |
782 bool comma = false; |