27 extern sys_config Config; |
27 extern sys_config Config; |
28 extern int debug; |
28 extern int debug; |
29 extern int my_shutdown; |
29 extern int my_shutdown; |
30 extern int my_reboot; |
30 extern int my_reboot; |
31 extern const char UNITMODE[5][8]; |
31 extern const char UNITMODE[5][8]; |
|
32 extern const char UNITSTAGE[3][10]; |
32 extern const char PROFSTATE[5][6]; |
33 extern const char PROFSTATE[5][6]; |
33 extern const char TEMPSTATE[3][8]; |
34 extern const char TEMPSTATE[3][8]; |
34 |
35 |
35 int Sequence = 0; |
36 int Sequence = 0; |
36 |
37 |
303 if ((unit->product_name && strlen(unit->product_name)) || |
304 if ((unit->product_name && strlen(unit->product_name)) || |
304 (unit->product_code && strlen(unit->product_code)) || |
305 (unit->product_code && strlen(unit->product_code)) || |
305 (unit->product_uuid && strlen(unit->product_uuid))) { |
306 (unit->product_uuid && strlen(unit->product_uuid))) { |
306 comma = false; |
307 comma = false; |
307 payload = xstrcat(payload, (char *)"\"product\":{"); |
308 payload = xstrcat(payload, (char *)"\"product\":{"); |
308 if (unit->product_uuid && strlen(unit->product_uuid)) { |
309 if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) { |
309 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
310 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
310 payload = xstrcat(payload, unit->product_uuid); |
311 payload = xstrcat(payload, unit->product_uuid); |
311 payload = xstrcat(payload, (char *)"\""); |
312 payload = xstrcat(payload, (char *)"\""); |
312 comma = true; |
313 comma = true; |
313 } |
314 } |
474 } |
475 } |
475 |
476 |
476 /* |
477 /* |
477 * Working mode and setpoints |
478 * Working mode and setpoints |
478 */ |
479 */ |
479 payload = xstrcat(payload, (char *)",\"mode\":\""); |
480 payload = xstrcat(payload, (char *)",\"stage\":\""); |
|
481 payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]); |
|
482 payload = xstrcat(payload, (char *)"\",\"mode\":\""); |
480 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); |
483 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); |
481 payload = xstrcat(payload, (char *)"\",\"setpoint\":{\"low\":"); |
484 payload = xstrcat(payload, (char *)"\",\"setpoint\":{\"low\":"); |
482 sprintf(buf, "%.1f", unit->PID_heat->SetP); |
485 sprintf(buf, "%.1f", unit->PID_heat->SetP); |
483 payload = xstrcat(payload, buf); |
486 payload = xstrcat(payload, buf); |
484 payload = xstrcat(payload, (char *)",\"high\":"); |
487 payload = xstrcat(payload, (char *)",\"high\":"); |
666 if ((unit->product_name && strlen(unit->product_name)) || |
669 if ((unit->product_name && strlen(unit->product_name)) || |
667 (unit->product_code && strlen(unit->product_code)) || |
670 (unit->product_code && strlen(unit->product_code)) || |
668 (unit->product_uuid && strlen(unit->product_uuid))) { |
671 (unit->product_uuid && strlen(unit->product_uuid))) { |
669 comma = false; |
672 comma = false; |
670 payload = xstrcat(payload, (char *)"\"product\":{"); |
673 payload = xstrcat(payload, (char *)"\"product\":{"); |
671 if (unit->product_uuid && strlen(unit->product_uuid)) { |
674 if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) { |
672 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
675 payload = xstrcat(payload, (char *)"\"uuid\":\""); |
673 payload = xstrcat(payload, unit->product_uuid); |
676 payload = xstrcat(payload, unit->product_uuid); |
674 payload = xstrcat(payload, (char *)"\""); |
677 payload = xstrcat(payload, (char *)"\""); |
675 comma = true; |
678 comma = true; |
676 } |
679 } |
693 comma = true; |
696 comma = true; |
694 } |
697 } |
695 |
698 |
696 if (comma) |
699 if (comma) |
697 payload = xstrcat(payload, (char *)","); |
700 payload = xstrcat(payload, (char *)","); |
698 payload = xstrcat(payload, (char *)"\"stage\":\"PRIMARY\",\"mode\":\""); |
701 payload = xstrcat(payload, (char *)"\"stage\":\""); |
|
702 payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]); |
|
703 payload = xstrcat(payload, (char *)"\",\"mode\":\""); |
699 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); |
704 payload = xstrcat(payload, (char *)UNITMODE[unit->mode]); |
700 payload = xstrcat(payload, (char *)"\",\"temperature\":{"); |
705 payload = xstrcat(payload, (char *)"\",\"temperature\":{"); |
701 comma = false; |
706 comma = false; |
702 if (unit->air_address) { |
707 if (unit->air_address) { |
703 payload = xstrcat(payload, (char *)"\"air\":"); |
708 payload = xstrcat(payload, (char *)"\"air\":"); |
773 payload = xstrcat(payload, (char *)"\"}}"); |
778 payload = xstrcat(payload, (char *)"\"}}"); |
774 |
779 |
775 topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/"); |
780 topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/"); |
776 topic = xstrcat(topic, unit->alias); |
781 topic = xstrcat(topic, unit->alias); |
777 publisher(mosq, topic, payload, true); |
782 publisher(mosq, topic, payload, true); |
778 printf("%s\n", payload); |
|
779 free(payload); |
783 free(payload); |
780 payload = NULL; |
784 payload = NULL; |
781 free(topic); |
785 free(topic); |
782 topic = NULL; |
786 topic = NULL; |
783 } |
787 } |
1043 mqtt_status = STATUS_WAITING; |
1047 mqtt_status = STATUS_WAITING; |
1044 mqtt_my_shutdown = TRUE; |
1048 mqtt_my_shutdown = TRUE; |
1045 |
1049 |
1046 do { |
1050 do { |
1047 if (mqtt_status == STATUS_WAITING) { |
1051 if (mqtt_status == STATUS_WAITING) { |
1048 if (debug) |
|
1049 fprintf(stdout, (char *)"Waiting\n"); |
|
1050 if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) { |
1052 if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) { |
1051 mosquitto_disconnect(mosq); |
1053 mosquitto_disconnect(mosq); |
1052 mqtt_disconnect_sent = TRUE; |
1054 mqtt_disconnect_sent = TRUE; |
1053 } |
1055 } |
1054 usleep(100000); |
1056 usleep(100000); |