From 3e8854ef1ac6a12b4b5f137ee6200c7809d01d84 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 7 Jan 2024 10:51:50 +0100 Subject: Add InfluxDB support --- src/init.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/init.lua b/src/init.lua index f31aa78..fd9c31d 100644 --- a/src/init.lua +++ b/src/init.lua @@ -87,8 +87,18 @@ function uart_callback(data) local json_str = string.format('{"rssi_dbm":%d,"co2_ppm":%d,"temperature_celsius":%d}', wifi.sta.getrssi(), mh_z19.co2, mh_z19.temp) mqttclient:publish(mqtt_prefix .. "/data", json_str, 0, 0, function(client) publishing_mqtt = false - gpio.write(ledpin, 1) - collectgarbage() + if have_wifi and influx_url and not publishing_http then + local influx_str = string.format("co2_ppm=%d,temperature_celsius=%d,abc_ticks=%d,abc_count=%d", mh_z19.co2, mh_z19.temp, mh_z19.abc_ticks, mh_z19.abc_count) + publishing_http = true + http.post(influx_url, influx_header, "mh_z19" .. influx_attr .. " " .. influx_str, function(code, data) + gpio.write(ledpin, 1) + publishing_http = false + collectgarbage() + end) + else + gpio.write(ledpin, 1) + collectgarbage() + end end) else collectgarbage() -- cgit v1.2.3