This commit is contained in:
Gilles Grandou 2021-08-05 19:47:35 +02:00
parent 6843d3f739
commit 23fd1c3da0
1 changed files with 102 additions and 115 deletions

View File

@ -11,7 +11,6 @@
#include <stdlib.h>
#include <unistd.h>
#define TIC2MQTT_VERSION "1.0.1"
#define DEFAULT_TTY "/dev/ttyUSB0"
@ -22,9 +21,7 @@
#define DEFAULT_TIC_NAME "Linky"
tic_info_t *tic_info = NULL;
/* Tags for 'compteur monophasé multitarif'. */
static tic_info_t *tic_info = NULL;
struct tag_desc {
const char *tag; // Name of tag.
@ -67,10 +64,7 @@ static struct tag_desc tag_descs[] =
{ NULL, 0 } /* End of table marker. */
};
/* Values for enum attributes of Homie property 'tic'. */
static struct mosquitto *mosq_tic = NULL;
int verbose = 0; //TODO
static int log_level = LOG_WARNING;
static int ha_config = 0;
@ -100,8 +94,7 @@ static void tic2mqtt_process_group(const char *tag, const char *data, time_t dat
char topic[TOPIC_MAXLEN + 1];
snprintf(topic, TOPIC_MAXLEN, "tic2mqtt/%s/%s", tic_name, tag);
if (verbose)
printf("%ld %s %s\n", stamp, topic, data);
log_info("%ld %s %s\n", stamp, topic, data);
if (mosq_tic) {
int res = mqtt_publish(mosq_tic, topic, NULL, data, TIC_QOS);
@ -122,10 +115,6 @@ static void sighandler(int signum)
exit(EXIT_SUCCESS);
}
/**
* @brief Clean-up before exit.
*/
static void cleanup(void)
{
tic_exit(tic_info);
@ -164,11 +153,9 @@ int main(int argc, char *argv[])
while ((opt = getopt(argc, argv, "vdat:n:h:p:k:H")) != -1) {
switch (opt) {
case 'v':
verbose = 1;
log_level = LOG_INFO;
break;
case 'd':
verbose = 1;
log_level = LOG_DEBUG;
break;