thermferm/mqtt.c

changeset 564
3fc61dd28656
parent 563
ca2fafcf3294
child 566
776a605befa5
--- a/thermferm/mqtt.c	Fri Aug 03 21:58:30 2018 +0200
+++ b/thermferm/mqtt.c	Sat Aug 04 16:29:12 2018 +0200
@@ -29,6 +29,7 @@
 extern int		my_shutdown;
 extern int		my_reboot;
 extern const char	UNITMODE[5][8];
+extern const char	UNITSTAGE[3][10];
 extern const char	PROFSTATE[5][6];
 extern const char	TEMPSTATE[3][8];
 
@@ -305,7 +306,7 @@
 	(unit->product_uuid && strlen(unit->product_uuid))) { 
 	comma = false;
     	payload = xstrcat(payload, (char *)"\"product\":{");
-	if (unit->product_uuid && strlen(unit->product_uuid)) {
+	if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) {
 	    payload = xstrcat(payload, (char *)"\"uuid\":\"");
 	    payload = xstrcat(payload, unit->product_uuid);
 	    payload = xstrcat(payload, (char *)"\"");
@@ -476,7 +477,9 @@
     /*
      * Working mode and setpoints
      */
-    payload = xstrcat(payload, (char *)",\"mode\":\"");
+    payload = xstrcat(payload, (char *)",\"stage\":\"");
+    payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]);
+    payload = xstrcat(payload, (char *)"\",\"mode\":\"");
     payload = xstrcat(payload, (char *)UNITMODE[unit->mode]);
     payload = xstrcat(payload, (char *)"\",\"setpoint\":{\"low\":");
     sprintf(buf, "%.1f", unit->PID_heat->SetP);
@@ -668,7 +671,7 @@
 	    (unit->product_uuid && strlen(unit->product_uuid))) {
 	    comma = false;
 	    payload = xstrcat(payload, (char *)"\"product\":{");
-	    if (unit->product_uuid && strlen(unit->product_uuid)) {
+	    if (unit->product_uuid && strlen(unit->product_uuid) && strcmp((char *)"(null)", unit->product_uuid)) {
 		payload = xstrcat(payload, (char *)"\"uuid\":\"");
 		payload = xstrcat(payload, unit->product_uuid);
 		payload = xstrcat(payload, (char *)"\"");
@@ -695,7 +698,9 @@
 
 	if (comma)
 	    payload = xstrcat(payload, (char *)",");
-	payload = xstrcat(payload, (char *)"\"stage\":\"PRIMARY\",\"mode\":\"");
+	payload = xstrcat(payload, (char *)"\"stage\":\"");
+	payload = xstrcat(payload, (char *)UNITSTAGE[unit->stage]);
+	payload = xstrcat(payload, (char *)"\",\"mode\":\"");
 	payload = xstrcat(payload, (char *)UNITMODE[unit->mode]);
 	payload = xstrcat(payload, (char *)"\",\"temperature\":{");
 	comma = false;
@@ -775,7 +780,6 @@
 	topic = xstrcat(topic_base((char *)"DLOG"), (char *)"/");
 	topic = xstrcat(topic, unit->alias);
 	publisher(mosq, topic, payload, true);
-printf("%s\n", payload);
 	free(payload);
 	payload = NULL;
 	free(topic);
@@ -1045,8 +1049,6 @@
 
         do {
             if (mqtt_status == STATUS_WAITING) {
-                if (debug)
-                    fprintf(stdout, (char *)"Waiting\n");
                 if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) {
                     mosquitto_disconnect(mosq);
                     mqtt_disconnect_sent = TRUE;

mercurial