Added some MQTT publish clear functions. Version 0.5.8

Sat, 29 Apr 2017 17:07:36 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 29 Apr 2017 17:07:36 +0200
changeset 504
862de87f9f89
parent 503
003c20125212
child 505
727fe541a48d
child 506
cdcd07bbee30

Added some MQTT publish clear functions. Version 0.5.8

configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
thermferm/mqtt.c file | annotate | diff | comparison | revisions
thermferm/mqtt.h file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- a/configure	Thu May 12 21:43:07 2016 +0200
+++ b/configure	Sat Apr 29 17:07:36 2017 +0200
@@ -2035,9 +2035,9 @@
 
 
 PACKAGE="mbsePi-apps"
-VERSION="0.5.7"
-COPYRIGHT="Copyright (C) 2014-2016 Michiel Broek, All Rights Reserved"
-CYEARS="2014-2016"
+VERSION="0.5.8"
+COPYRIGHT="Copyright (C) 2014-2017 Michiel Broek, All Rights Reserved"
+CYEARS="2014-2017"
 
 
 
--- a/configure.ac	Thu May 12 21:43:07 2016 +0200
+++ b/configure.ac	Sat Apr 29 17:07:36 2017 +0200
@@ -8,9 +8,9 @@
 dnl General settings
 dnl After changeing the version number, run autoconf!
 PACKAGE="mbsePi-apps"
-VERSION="0.5.7"
-COPYRIGHT="Copyright (C) 2014-2016 Michiel Broek, All Rights Reserved"
-CYEARS="2014-2016"
+VERSION="0.5.8"
+COPYRIGHT="Copyright (C) 2014-2017 Michiel Broek, All Rights Reserved"
+CYEARS="2014-2017"
 AC_SUBST(PACKAGE)
 AC_SUBST(VERSION)
 AC_SUBST(COPYRIGHT)
--- a/thermferm/mqtt.c	Thu May 12 21:43:07 2016 +0200
+++ b/thermferm/mqtt.c	Sat Apr 29 17:07:36 2017 +0200
@@ -194,10 +194,12 @@
     if (mqtt_use) {
         /*
          * Final publish 0 to clients/<hostname>/thermferm/state
+	 * After that, remove the retained topic.
          */
         syslog(LOG_NOTICE, "MQTT disconnecting");
         sprintf(buf, "0");
         mosquitto_publish(mosq, &mqtt_mid_sent, state, strlen(buf), buf, mqtt_qos, true);
+	mosquitto_publish(mosq, &mqtt_mid_sent, state, 0, NULL, mqtt_qos, true);
         mqtt_last_mid = mqtt_mid_sent;
         mqtt_status = STATUS_WAITING;
 	mqtt_my_shutdown = TRUE;
@@ -268,3 +270,17 @@
 #endif
 }
 
+
+
+void mqtt_publish_clear(char *uuid, char *tail)
+{
+#ifdef HAVE_MOSQUITTO_H
+    char        topic[1024];
+
+    if (mqtt_use) {
+	snprintf(topic, 1023, "bmsd/%s/%s/%s", my_hostname, uuid, tail);
+	mosquitto_publish(mosq, &mqtt_mid_sent, topic, 0, NULL, mqtt_qos, 1);
+    }
+#endif
+}
+
--- a/thermferm/mqtt.h	Thu May 12 21:43:07 2016 +0200
+++ b/thermferm/mqtt.h	Sat Apr 29 17:07:36 2017 +0200
@@ -17,5 +17,6 @@
 void mqtt_publish_int(char *, char *, int);
 void mqtt_publish_float(char *, char *, float, int);
 void mqtt_publish_str(char *, char *, char *);
+void mqtt_publish_clear(char *, char *);
 
 #endif
--- a/thermferm/server.c	Thu May 12 21:43:07 2016 +0200
+++ b/thermferm/server.c	Sat Apr 29 17:07:36 2017 +0200
@@ -2394,10 +2394,16 @@
 					}
 					if (unit->heater_address)
 					    mqtt_publish_int(unit->alias, (char *)"heater", 0);
+					else
+					    mqtt_publish_clear(unit->alias, (char *)"heater");
 					if (unit->cooler_address)
 					    mqtt_publish_int(unit->alias, (char *)"cooler", 0);
+					else
+					    mqtt_publish_clear(unit->alias, (char *)"cooler");
 					if (unit->fan_address)
 					    mqtt_publish_int(unit->alias, (char *)"fan", 0);
+					else
+					    mqtt_publish_clear(unit->alias, (char *)"fan");
 					break;
 				    }
 				}
@@ -2515,10 +2521,16 @@
 				    device_out(unit->light_address, unit->light_state);
 				    if (unit->heater_address)
 					mqtt_publish_int(unit->alias, (char *)"heater", 0);
+				    else
+					mqtt_publish_clear(unit->alias, (char *)"heater");
 				    if (unit->cooler_address)
 					mqtt_publish_int(unit->alias, (char *)"cooler", 0);
+				    else
+					mqtt_publish_clear(unit->alias, (char *)"cooler");
 				    if (unit->fan_address)
 					mqtt_publish_int(unit->alias, (char *)"fan", 0);
+				    else
+					mqtt_publish_clear(unit->alias, (char *)"fan");
 				    unit->mqtt_flag |= (MQTT_FLAG_PROFILE | MQTT_FLAG_SP);
 				}
 
--- a/thermferm/thermferm.c	Thu May 12 21:43:07 2016 +0200
+++ b/thermferm/thermferm.c	Sat Apr 29 17:07:36 2017 +0200
@@ -1071,12 +1071,20 @@
 	mqtt_publish_int(unit->alias, (char *)"state", (unit->mode != UNITMODE_OFF) ? 1 : 0);
 	if (unit->name)
 	    mqtt_publish_str(unit->alias, (char *)"name", unit->name);
+	else
+	    mqtt_publish_clear(unit->alias, (char *)"name");
 	if (unit->heater_address)
 	    mqtt_publish_int(unit->alias, (char *)"heater", 0);
+	else
+	    mqtt_publish_clear(unit->alias, (char *)"heater");
 	if (unit->cooler_address)
 	    mqtt_publish_int(unit->alias, (char *)"cooler", 0);
+	else
+	    mqtt_publish_clear(unit->alias, (char *)"cooler");
 	if (unit->fan_address)
 	    mqtt_publish_int(unit->alias, (char *)"fan", 0);
+	else
+	    mqtt_publish_clear(unit->alias, (char *)"fan");
 	if (unit->air_address)
 	    unit->mqtt_flag |= MQTT_FLAG_AIR;
 	if (unit->beer_address)
@@ -1942,14 +1950,37 @@
     for (unit = Config.units; unit; unit = unit->next) {
 
         if (unit->mode != UNITMODE_OFF) {
-	    if (unit->heater_address)
+	    if (unit->heater_address) {
 		mqtt_publish_int(unit->alias, (char *)"heater", 0);
-	    if (unit->cooler_address)
+		mqtt_publish_clear(unit->alias, (char *)"heater");
+	    }
+	    if (unit->cooler_address) {
 		mqtt_publish_int(unit->alias, (char *)"cooler", 0);
-	    if (unit->fan_address)
+		mqtt_publish_clear(unit->alias, (char *)"cooler");
+	    }
+	    if (unit->fan_address) {
 		mqtt_publish_int(unit->alias, (char *)"fan", 0);
+		mqtt_publish_clear(unit->alias, (char *)"fan");
+	    }
 	    mqtt_publish_int(unit->alias, (char *)"state", 0);
+	    mqtt_publish_clear(unit->alias, (char *)"state");
 	}
+	mqtt_publish_clear(unit->alias, (char *)"air/temperature");
+	mqtt_publish_clear(unit->alias, (char *)"air");
+	mqtt_publish_clear(unit->alias, (char *)"beer/temperature");
+	mqtt_publish_clear(unit->alias, (char *)"beer");
+	mqtt_publish_clear(unit->alias, (char *)"setpoint/high");
+	mqtt_publish_clear(unit->alias, (char *)"setpoint/low");
+	mqtt_publish_clear(unit->alias, (char *)"setpoint");
+	mqtt_publish_clear(unit->alias, (char *)"door");
+	mqtt_publish_clear(unit->alias, (char *)"name");
+	mqtt_publish_clear(unit->alias, (char *)"mode");
+	mqtt_publish_clear(unit->alias, (char *)"12volt");
+	mqtt_publish_clear(unit->alias, (char *)"profile/uuid");
+	mqtt_publish_clear(unit->alias, (char *)"profile/state");
+	mqtt_publish_clear(unit->alias, (char *)"profile/name");
+	mqtt_publish_clear(unit->alias, (char *)"profile/fridgemode");
+	mqtt_publish_clear(unit->alias, (char *)"profile/percent");
 
 	/*
 	 * Turn everything off

mercurial