mirror of
https://github.com/tomru/cram-luftdaten.git
synced 2026-03-02 22:17:22 +01:00
This commit is contained in:
54
toLineProtocol.sh
Normal file
54
toLineProtocol.sh
Normal file
@@ -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}'
|
||||
|
||||
Reference in New Issue
Block a user