From 04b748ae0227816a73a5edf5e6b624ce2a67b8b8 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 17 Apr 2020 19:20:58 +0200 Subject: [PATCH] Logging to RRD and MQTT can be configured (by #define's) --- README | 10 ++++++---- arexxd.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README b/README index 03ad357..50d9efa 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Arexx Data Logger Daemon - (c) 2011--2018 Martin Mares + (c) 2011--2020 Martin Mares You can use and distribute this program under the terms of GPLv2. @@ -21,9 +21,11 @@ so I reverse-engineered the communication protocol and wrote my own software. This package contains a daemon (arexxd), which watches USB and whenever the data logger is connected, it downloads all data points from its memory and continues fetching all further measurements in real time. Also, it synchronizes -the clock of the logger to the system time. The data points are stored in a RRD -database (see http://oss.oetiker.ch/rrdtool/), but you can easily tweak the -source to process the data in any way you like. +the clock of the logger to the system time. + +The data points can be stored in a RRD database (see http://oss.oetiker.ch/rrdtool/) +or sent to InfluxDB (this is configured rather crudely in the source code). +You can easily tweak the source to process the data in any way you like. This program is not supported or endorsed by AREXX in any way. Also, there is no warranty on what it does or does not. However, if you have any bug reports diff --git a/arexxd.c b/arexxd.c index 1bde4a2..df1877b 100644 --- a/arexxd.c +++ b/arexxd.c @@ -1,7 +1,7 @@ /* * Linux Interfece for Arexx Data Loggers * - * (c) 2011-2018 Martin Mares + * (c) 2011-2020 Martin Mares */ #include @@ -34,6 +34,9 @@ #define MAX_FUTURE_TIME 300 #define IGNORE_UNKNOWN_SENSORS +#undef LOG_TO_RRD +#undef LOG_TO_MQTT + typedef unsigned char byte; typedef unsigned int uint; static libusb_context *usb_ctxt; @@ -104,6 +107,8 @@ static void log_pkt(char *fmt, ...) /*** MQTT interface ***/ +#ifdef LOG_TO_MQTT + #include static struct mosquitto *mosq; @@ -155,8 +160,12 @@ static void mqtt_point(time_t t, const char *name, double val, char *unit UNUSED mqtt_publish(topic, "%.3f %lld", val, (long long) t); } +#endif + /*** RRD interface ***/ +#ifdef LOG_TO_RRD + #include #define MAX_ARGS 20 @@ -231,6 +240,8 @@ static void rrd_point(time_t t, const char *name, double val, char *unit) } } +#endif + /*** Transforms ***/ #define TIME_OFFSET 946681200 // Timestamp of 2000-01-01 00:00:00 @@ -298,8 +309,12 @@ static void cooked_point(time_t t, uint id, double val, char *unit, int q) } data_point_counter++; +#ifdef LOG_TO_RRD rrd_point(t, name, val2, unit); +#endif +#ifdef LOG_TO_MQTT mqtt_point(t, name, val2, unit); +#endif } static void raw_point(uint t, uint id, int raw, int q) @@ -763,7 +778,9 @@ int main(int argc, char **argv) use_syslog = 1; } +#ifdef LOG_TO_MQTT mqtt_init(); +#endif struct sigaction sa = { .sa_handler = sigterm_handler }; sigaction(SIGTERM, &sa, NULL); -- 2.39.2