diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-07 10:51:50 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-07 10:51:50 +0100 |
commit | 3e8854ef1ac6a12b4b5f137ee6200c7809d01d84 (patch) | |
tree | 0823167c82cd52c47cac71ff1d2b3f9e8dbe72bc | |
parent | 65a1fe9cfd7c283acf4697dda3e11d4b8df30f02 (diff) |
Add InfluxDB support
-rw-r--r-- | src/init.lua | 14 |
1 files 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() |