wip
This commit is contained in:
parent
7e04386a2b
commit
cf7e2d1b9d
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
2
mqtt.h
2
mqtt.h
|
@ -1,6 +1,8 @@
|
|||
#ifndef __MQTT_H__
|
||||
#define __MQTT_H__
|
||||
|
||||
#include <mosquitto.h>
|
||||
|
||||
#define TOPIC_MAXLEN 255
|
||||
#define TIC_QOS 0
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef __TIC2MQTT_H__
|
||||
#define __TIC2MQTT_H__
|
||||
|
||||
extern char *tic_name;
|
||||
extern int verbose;
|
||||
extern struct mosquitto *mosq_tic;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue