--- a/thermferm/thermferm.c Wed Jul 18 13:26:37 2018 +0200 +++ b/thermferm/thermferm.c Thu Jul 19 12:47:52 2018 +0200 @@ -995,8 +995,9 @@ syslog(LOG_NOTICE, "Can't lock"); return 1; } - +#ifdef HAVE_MOSQUITTO_H mqtt_connect(); +#endif if ((rc = devices_detect())) { syslog(LOG_NOTICE, "Detected %d new devices", rc); @@ -1163,12 +1164,12 @@ #ifdef HAVE_WIRINGPI_H piUnlock(LOCK_LCD); #endif - bool updateHT = false; + int updateHT = 0; if (Config.temp_address) { rc = device_in(Config.temp_address, &temp); if (rc == DEVPRESENT_YES) { if (Config.temp_value != temp) - updateHT = true; + updateHT = 1; Config.temp_value = temp; Config.temp_state = 0; #ifdef HAVE_WIRINGPI_H @@ -1198,7 +1199,7 @@ rc = device_in(Config.hum_address, &temp); if (rc == DEVPRESENT_YES) { if (Config.hum_value != temp) - updateHT = true; + updateHT = 1; Config.hum_value = temp; Config.hum_state = 0; #ifdef HAVE_WIRINGPI_H @@ -1220,7 +1221,9 @@ * update, send the NDATA message. */ if (updateHT || (now > (ndata + 300))) { +#ifdef HAVE_MOSQUITTO_H publishNData(false, 0); +#endif ndata = now; } @@ -1244,10 +1247,12 @@ deviation = 40000; if ((unit->air_temperature == 0) || (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { +#ifdef HAVE_MOSQUITTO_H if (unit->air_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; pub_domoticz_temp(unit->air_idx, temp); } +#endif unit->air_temperature = temp; unit->air_state = 0; } else { @@ -1266,10 +1271,12 @@ deviation = 40000; if ((unit->beer_temperature == 0) || (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { +#ifdef HAVE_MOSQUITTO_H if (unit->beer_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; pub_domoticz_temp(unit->beer_idx, temp); } +#endif unit->beer_temperature = temp; unit->beer_state = 0; } else { @@ -1288,10 +1295,12 @@ deviation = 40000; if ((unit->chiller_temperature == 0) || (unit->chiller_temperature && (temp > (int)unit->chiller_temperature - deviation) && (temp < ((int)unit->chiller_temperature + deviation)))) { +#ifdef HAVE_MOSQUITTO_H if (unit->chiller_temperature != temp) { unit->mqtt_flag |= MQTT_FLAG_DATA; pub_domoticz_temp(unit->chiller_idx, temp); } +#endif unit->chiller_temperature = temp; unit->chiller_state = 0; } else { @@ -1314,15 +1323,19 @@ if (unit->door_state == 0) { syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name); unit->door_state = 1; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->door_idx, unit->door_state); unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } else { if (unit->door_state) { syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); unit->door_state = 0; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->door_idx, unit->door_state); unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } /* * If unit is active and the door is open @@ -1348,15 +1361,19 @@ if (unit->psu_state == 0) { syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name); unit->psu_state = 1; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->psu_idx, unit->psu_state); unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } else { if (unit->psu_state) { syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name); unit->psu_state = 0; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->psu_idx, unit->psu_state); unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } unit->alarm_flag |= ALARM_FLAG_PSU; } @@ -1711,9 +1728,11 @@ if (unit->heater_state != power) { syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power); unit->heater_state = power; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->heater_idx, unit->heater_state); if (unit->heater_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } else { @@ -1723,9 +1742,11 @@ if (unit->heater_state) { syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name); unit->heater_state = 0; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->heater_idx, unit->heater_state); if (unit->heater_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } @@ -1745,9 +1766,11 @@ if (unit->cooler_state != power) { syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power); unit->cooler_state = power; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->cooler_idx, unit->cooler_state); if (unit->cooler_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } else { @@ -1757,9 +1780,11 @@ if (unit->cooler_state) { syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name); unit->cooler_state = 0; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->cooler_idx, unit->cooler_state); if (unit->cooler_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } @@ -1786,9 +1811,11 @@ if (! unit->fan_state) { syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); unit->fan_state = 100; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->fan_idx, unit->fan_state); if (unit->fan_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } else { @@ -1798,9 +1825,11 @@ if (unit->fan_state) { syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name); unit->fan_state = 0; +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->fan_idx, unit->fan_state); if (unit->fan_address) unit->mqtt_flag |= MQTT_FLAG_DATA; +#endif } } } @@ -1860,6 +1889,7 @@ /* * Publish MQTT messages set in flag */ +#ifdef HAVE_MOSQUITTO_H if (unit->mqtt_flag) { if (unit->mqtt_flag & MQTT_FLAG_BIRTH) { publishDBirth(unit); @@ -1873,6 +1903,7 @@ unit->mqtt_flag &= ~MQTT_FLAG_DEATH; } } +#endif /* * Handle changed alarms @@ -2000,12 +2031,19 @@ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0; unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; device_out(unit->heater_address, unit->heater_state); +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->heater_idx, unit->heater_state); +#endif device_out(unit->cooler_address, unit->cooler_state); +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->cooler_idx, unit->cooler_state); +#endif device_out(unit->fan_address, unit->fan_state); +#ifdef HAVE_MOSQUITTO_H pub_domoticz_output(unit->fan_idx, unit->fan_state); +#endif device_out(unit->light_address, unit->light_state); +#ifdef HAVE_MOSQUITTO_H if (unit->mode != UNITMODE_OFF) { /* * If unit ia active, publish we are dying. @@ -2014,11 +2052,14 @@ publishDData(unit); publishDDeath(unit); } +#endif syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]); } usleep(100000); +#ifdef HAVE_MOSQUITTO_H mqtt_disconnect(); +#endif syslog(LOG_NOTICE, "Out of loop"); if (debug)