# HG changeset patch # User Michiel Broek # Date 1493478456 -7200 # Node ID 862de87f9f89d61bfff36360ab7273f15f21d339 # Parent 003c201252126bf80aed263d1214303cc0d1953d Added some MQTT publish clear functions. Version 0.5.8 diff -r 003c20125212 -r 862de87f9f89 configure --- 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" diff -r 003c20125212 -r 862de87f9f89 configure.ac --- 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) diff -r 003c20125212 -r 862de87f9f89 thermferm/mqtt.c --- 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//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 +} + diff -r 003c20125212 -r 862de87f9f89 thermferm/mqtt.h --- 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 diff -r 003c20125212 -r 862de87f9f89 thermferm/server.c --- 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); } diff -r 003c20125212 -r 862de87f9f89 thermferm/thermferm.c --- 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