diff --git a/homeassistant.c b/homeassistant.c index 4875a18..eb18a3f 100644 --- a/homeassistant.c +++ b/homeassistant.c @@ -1,4 +1,3 @@ -#include "tic2mqtt.h" #include "homeassistant.h" #include "mqtt.h" #include "logger.h" @@ -50,7 +49,7 @@ static void unescape_str(const char *str) *d = '\0'; } -void ha_config_init() +void ha_config_init(const char *tic_name, struct mosquitto *mosq_tic) { ha_config_desc *desc; // char payload[512]; @@ -90,8 +89,7 @@ void ha_config_init() const char *payload = json_object_to_json_string(obj); unescape_str(payload); - if (verbose) - printf("%s\n%s\n", topic, payload); + log_info("%s\n%s\n", topic, payload); if (mosq_tic) { int res = mqtt_publish(mosq_tic, topic, NULL, payload, TIC_QOS); diff --git a/homeassistant.h b/homeassistant.h index 5e186fe..7f91f56 100644 --- a/homeassistant.h +++ b/homeassistant.h @@ -1,6 +1,8 @@ #ifndef __HOME_ASSISTANT_H__ #define __HOME_ASSISTANT_H__ -extern void ha_config_init(); +#include "mosquitto.h" + +extern void ha_config_init(const char *tic_name, struct mosquitto *mosq_tic); #endif diff --git a/mqtt.c b/mqtt.c index e013626..06c1228 100644 --- a/mqtt.c +++ b/mqtt.c @@ -1,4 +1,3 @@ -#include "tic2mqtt.h" #include "mqtt.h" #include "logger.h" diff --git a/mqtt.h b/mqtt.h index 8524d29..6f189e1 100644 --- a/mqtt.h +++ b/mqtt.h @@ -1,6 +1,8 @@ #ifndef __MQTT_H__ #define __MQTT_H__ +#include + #define TOPIC_MAXLEN 255 #define TIC_QOS 0 diff --git a/tic2mqtt.c b/tic2mqtt.c index fc24f54..56db2f2 100644 --- a/tic2mqtt.c +++ b/tic2mqtt.c @@ -1,4 +1,3 @@ -#include "tic2mqtt.h" #include "logger.h" #include "tic.h" #include "mqtt.h" @@ -73,7 +72,7 @@ static struct tag_desc tag_descs[] = /* Values for enum attributes of Homie property 'tic'. */ -struct mosquitto *mosq_tic = NULL; +static struct mosquitto *mosq_tic = NULL; int verbose = 0; //TODO static int log_level = LOG_WARNING; static int ha_config = 0; @@ -230,7 +229,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; if (ha_config) - ha_config_init(); + ha_config_init(tic_name, mosq_tic); tic_set_cb_data(tic_info, tic2mqtt_process_group); diff --git a/tic2mqtt.h b/tic2mqtt.h deleted file mode 100644 index f09a911..0000000 --- a/tic2mqtt.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __TIC2MQTT_H__ -#define __TIC2MQTT_H__ - -extern char *tic_name; -extern int verbose; -extern struct mosquitto *mosq_tic; - -#endif