Fixed compiling whithout mqtt support.

Thu, 19 Jul 2018 12:47:52 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 19 Jul 2018 12:47:52 +0200
changeset 545
c382a6c58c20
parent 544
e2889b17f48c
child 546
d2e8626e7118

Fixed compiling whithout mqtt support.

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/thermferm/mqtt.c	Wed Jul 18 13:26:37 2018 +0200
+++ b/thermferm/mqtt.c	Thu Jul 19 12:47:52 2018 +0200
@@ -447,13 +447,10 @@
     payload = NULL;
 }
 
-#endif
 
 
 void publishDData(units_list *unit)
 {
-#ifdef HAVE_MOSQUITTO_H
-
     char	*payload = NULL, *topic = NULL;
 
     if (mqtt_use) {
@@ -468,15 +465,12 @@
 	free(topic);
 	topic = NULL;
     }
-#endif
 }
 
 
 
 void publishDBirth(units_list *unit)
 {
-#ifdef HAVE_MOSQUITTO_H
-
     char        *payload = NULL, *topic = NULL;
 
     if (mqtt_use) {
@@ -491,15 +485,12 @@
 	free(topic);
 	topic = NULL;
     }
-#endif
 }
 
 
 
 void publishDDeath(units_list *unit)
 {
-#ifdef HAVE_MOSQUITTO_H
-
     char        *topic = NULL;
 
     if (mqtt_use) {
@@ -515,14 +506,12 @@
 	free(topic);
 	topic = NULL;
     }
-#endif
 }
 
 
 
 void publishNData(bool birth, int flag)
 {
-#ifdef HAVE_MOSQUITTO_H
     char		*payload = NULL, sidx[10], buf[64];
     struct utsname	ubuf;
     bool		comma = false;
@@ -602,14 +591,12 @@
 	free(payload);
 	payload = NULL;
     }
-#endif
 }
 
 
 
 void mqtt_connect(void)
 {
-#ifdef HAVE_MOSQUITTO_H
     char	*id = NULL;
     char	err[1024];
     int		rc;
@@ -681,14 +668,12 @@
 	publishNData(true, 0);
 	publishDBirthAll();
     }
-#endif
 }
 
 
 
 void mqtt_disconnect(void)
 {
-#ifdef HAVE_MOSQUITTO_H
     int		rc;
 
     if (mqtt_use) {
@@ -732,8 +717,7 @@
 	mqtt_my_shutdown = FALSE;
 	syslog(LOG_NOTICE, "MQTT disconnected");
     }
-#endif
 }
 
 
-
+#endif
--- a/thermferm/mqtt.h	Wed Jul 18 13:26:37 2018 +0200
+++ b/thermferm/mqtt.h	Thu Jul 19 12:47:52 2018 +0200
@@ -7,7 +7,6 @@
 #define STATUS_CONNACK_RECVD 1
 #define STATUS_WAITING 2
 
-#endif
 
 /*
  * Public functions
@@ -43,3 +42,5 @@
 void publishNData(bool birth, int flag);
 
 #endif
+
+#endif
--- a/thermferm/server.c	Wed Jul 18 13:26:37 2018 +0200
+++ b/thermferm/server.c	Thu Jul 19 12:47:52 2018 +0200
@@ -1018,7 +1018,7 @@
     }
 
     if (strcmp(opt, (char *)"PUT") == 0) {
-	bool mqtt_reconnect = false;
+	int mqtt_reconnect = 0;
 	while (1) {
 	    rlen = srv_recv(ibuf);
 	    if (rlen == -1) {
@@ -1027,8 +1027,10 @@
 	    if (strlen(ibuf)) {
 		if (strcmp(ibuf, (char *)".") == 0) {
 		    srv_send((char *)"219 Accepted Global record");
+#ifdef HAVE_MOSQUITTO_H
 		    if (mqtt_reconnect)
 			mqtt_connect();
+#endif
 		    return 1;
 		}
 		kwd = strtok(ibuf, ",\0");
@@ -1108,8 +1110,10 @@
 		    } else if (strcmp(kwd, (char *)"MQTT_HOST") == 0) {
 			if (val && Config.mqtt_host && (strcmp(val, Config.mqtt_host)))
 			    syslog(LOG_NOTICE, "Global MQTT host `%s' to `%s'", Config.mqtt_host, val);
+#ifdef HAVE_MOSQUITTO_H
 			mqtt_disconnect();
-			mqtt_reconnect = true;
+#endif
+			mqtt_reconnect = 1;
 			if (Config.mqtt_host)
 			    free(Config.mqtt_host);
 			if (val)
@@ -1121,8 +1125,10 @@
 			if (sscanf(val, "%d", &ival) == 1) {
 			    if (Config.mqtt_port != ival) {
 				syslog(LOG_NOTICE, "Global MQTT port %d to %d", Config.mqtt_port, ival);
+#ifdef HAVE_MOSQUITTO_H
 				mqtt_disconnect();
-				mqtt_reconnect = true;
+#endif
+				mqtt_reconnect = 1;
 			        Config.mqtt_port = ival;
 			    }
 			}
@@ -1130,8 +1136,10 @@
 		    } else if (strcmp(kwd, (char *)"MQTT_USER") == 0) {
 			if (val && Config.mqtt_username && (strcmp(val, Config.mqtt_username)))
 			    syslog(LOG_NOTICE, "Global MQTT username `%s' to `%s'", Config.mqtt_username, val);
+#ifdef HAVE_MOSQUITTO_H
 			mqtt_disconnect();
-			mqtt_reconnect = true;
+#endif
+			mqtt_reconnect = 1;
 			if (Config.mqtt_username)
 			    free(Config.mqtt_username);
 			if (val)
@@ -1142,8 +1150,10 @@
 		    } else if (strcmp(kwd, (char *)"MQTT_PASS") == 0) {
 			if (val && Config.mqtt_password && (strcmp(val, Config.mqtt_password)))
 			    syslog(LOG_NOTICE, "Global MQTT password `%s' to `%s'", Config.mqtt_password, val);
+#ifdef HAVE_MOSQUITTO_H
 			mqtt_disconnect();
-			mqtt_reconnect = true;
+#endif
+			mqtt_reconnect = 1;
 			if (Config.mqtt_password)
 			    free(Config.mqtt_password);
 			if (val)
@@ -2611,6 +2621,7 @@
 				}
 
 			    }
+#ifdef HAVE_MOSQUITTO_H
 			    if (unit->mqtt_flag) {
 				    if (debug)
 					    fprintf(stdout, "flag value %d\n", unit->mqtt_flag);
@@ -2623,6 +2634,7 @@
 				    publishDDeath(unit);
 				}
 			    }
+#endif
 			}
 		    }
 		}
--- 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)

mercurial