This commit is contained in:
Gilles Grandou 2021-08-05 19:25:41 +02:00
parent 7e04386a2b
commit cf7e2d1b9d
6 changed files with 9 additions and 17 deletions

View File

@ -1,4 +1,3 @@
#include "tic2mqtt.h"
#include "homeassistant.h" #include "homeassistant.h"
#include "mqtt.h" #include "mqtt.h"
#include "logger.h" #include "logger.h"
@ -50,7 +49,7 @@ static void unescape_str(const char *str)
*d = '\0'; *d = '\0';
} }
void ha_config_init() void ha_config_init(const char *tic_name, struct mosquitto *mosq_tic)
{ {
ha_config_desc *desc; ha_config_desc *desc;
// char payload[512]; // char payload[512];
@ -90,8 +89,7 @@ void ha_config_init()
const char *payload = json_object_to_json_string(obj); const char *payload = json_object_to_json_string(obj);
unescape_str(payload); unescape_str(payload);
if (verbose) log_info("%s\n%s\n", topic, payload);
printf("%s\n%s\n", topic, payload);
if (mosq_tic) { if (mosq_tic) {
int res = mqtt_publish(mosq_tic, topic, NULL, payload, TIC_QOS); int res = mqtt_publish(mosq_tic, topic, NULL, payload, TIC_QOS);

View File

@ -1,6 +1,8 @@
#ifndef __HOME_ASSISTANT_H__ #ifndef __HOME_ASSISTANT_H__
#define __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 #endif

1
mqtt.c
View File

@ -1,4 +1,3 @@
#include "tic2mqtt.h"
#include "mqtt.h" #include "mqtt.h"
#include "logger.h" #include "logger.h"

2
mqtt.h
View File

@ -1,6 +1,8 @@
#ifndef __MQTT_H__ #ifndef __MQTT_H__
#define __MQTT_H__ #define __MQTT_H__
#include <mosquitto.h>
#define TOPIC_MAXLEN 255 #define TOPIC_MAXLEN 255
#define TIC_QOS 0 #define TIC_QOS 0

View File

@ -1,4 +1,3 @@
#include "tic2mqtt.h"
#include "logger.h" #include "logger.h"
#include "tic.h" #include "tic.h"
#include "mqtt.h" #include "mqtt.h"
@ -73,7 +72,7 @@ static struct tag_desc tag_descs[] =
/* Values for enum attributes of Homie property 'tic'. */ /* Values for enum attributes of Homie property 'tic'. */
struct mosquitto *mosq_tic = NULL; static struct mosquitto *mosq_tic = NULL;
int verbose = 0; //TODO int verbose = 0; //TODO
static int log_level = LOG_WARNING; static int log_level = LOG_WARNING;
static int ha_config = 0; static int ha_config = 0;
@ -230,7 +229,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
if (ha_config) if (ha_config)
ha_config_init(); ha_config_init(tic_name, mosq_tic);
tic_set_cb_data(tic_info, tic2mqtt_process_group); tic_set_cb_data(tic_info, tic2mqtt_process_group);

View File

@ -1,8 +0,0 @@
#ifndef __TIC2MQTT_H__
#define __TIC2MQTT_H__
extern char *tic_name;
extern int verbose;
extern struct mosquitto *mosq_tic;
#endif