commit f38490c546ab8969fcce79a7f5f69d2d23fcfd78 Author: Thomas Ruoff Date: Tue May 30 01:20:51 2017 +0200 diff --git a/toLineProtocol.sh b/toLineProtocol.sh new file mode 100644 index 0000000..bc7549f --- /dev/null +++ b/toLineProtocol.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# Converts CSV exports from https://www.madavi.de/sensor/csvfiles.php to +# InfluxDB LineProtocol https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/ +# +# Note: timestamps are in seconds, therefore user precision parameter when +# writing, see https://docs.influxdata.com/influxdb/v1.2/tools/api/#write + +# CSV file spects +# +# | DB Field | DB field | CSV Column | CSV Format +# |-------------|----------|-----------------------|--------------------- +# | time | time | 1 Time | 2017/05/19 00:00:11 +# | | | 2 durP1 | +# | | | 3 ratioP1 | +# | | | 4 P1 | +# | | | 5 durP2 | +# | | | 6 ratioP2 | +# | | | 7 P2 | +# | SDS_P1 | field | 8 SDS_P1 | 10.36 +# | SDS_P2 | field | 9 SDS_P2 | 9.50 +# | temperature | field | 10 Temp | 16.00 +# | humidity | field | 11 Humidity | 79.00 +# | | | 12 BMP_temperature | +# | | | 13 BMP_pressure | +# | | | 14 BME280_temperature | +# | | | 15 BME280_humidity | +# | | | 16 BME280_pressure | +# | samples | field | 17 Samples | 828799 +# | min_micro | field | 18 Min_cycle | 172 +# | max_micro | field | 19 Max_cycle | 25198 +# | | | 20 Signal | -91 +# | node | tag | -- -- | e.g. esp8266-16229960 + +# TODO: +# - check if CSV export is in UTC ? + +SRC_FILE="${1:-/dev/stdin}" + +DATABASE=feinstaub +SENSOR_ID=16229960 + +NODE=esp8266-$SENSOR_ID + + +STRIP_CSV_HEADERS="tail -n +2" + +cat $SCR_FILE \ + | $STRIP_CSV_HEADERS \ + | gawk -v db="$DATABASE" -v node="$NODE" \ + 'BEGIN { FS = ";" } ; \ + { timestamp=mktime(gensub(/\/|:/," ", "g", $1)); \ + print db",node="node" SDS_P1="$8",SDS_P2="$9",humidity="$11",min_micro="$18",max_micro="$19",samples="$17",temperature="$10" "timestamp}' +