„dl5000sql.sh“ hinzufügen
Erste Version - Proof of concept. Provisorien leben am längsten.
This commit is contained in:
parent
be731dee7a
commit
6b57864e5c
82
dl5000sql.sh
Normal file
82
dl5000sql.sh
Normal file
@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
# dl5000sql.sh reads data from the DL5000 weather station and writes it up to a MySQL/MariaDB.
|
||||
# https://code.hw12.org/tilman/dl5000
|
||||
#
|
||||
# Version 0.0.1 - 15.04.2020 "Proof of concept"
|
||||
#
|
||||
# License GPL3.0 or later
|
||||
# https://code.hw12.org/tilman/dl5000/src/branch/master/LICENSE
|
||||
|
||||
#Log file and temporary txt.
|
||||
PFAD=$(dirname "$(readlink -e "$0")");
|
||||
FILE=$PFAD"/"$DATE."txt";
|
||||
LOG=$PFAD"/dl5000sql.log";
|
||||
|
||||
TMP0="dl5000.tmp";
|
||||
TMP1="dl5001.tmp";
|
||||
TMP2="dl5002.tmp";
|
||||
|
||||
#Database
|
||||
DB_USER="dbuser";
|
||||
DB_PASS="dbpasswd";
|
||||
DB_HOST="dbhost";
|
||||
DB_NAME="dbname";
|
||||
DB_TAB="TempData";
|
||||
|
||||
#Get date and round to nearest 5min (for harmonized use with data from other scripts in pChart)
|
||||
DATE_RAW=$(/bin/date +%s);
|
||||
DATE=$(/bin/date -d @$DATE_RAW "+%Y-%m-%d %H:%M:%S");
|
||||
DATE_N5M=$(echo "($DATE_RAW % 300)"|bc);
|
||||
|
||||
if [ $DATE_N5M -lt 150 ];then
|
||||
DATE_N5M=$(echo "($DATE_RAW - ($DATE_RAW % 300))"|bc);
|
||||
else
|
||||
DATE_N5M=$(echo "($DATE_RAW - ($DATE_RAW % 300) + 300)"|bc);
|
||||
fi
|
||||
DATE_N5M=$(/bin/date -d @$DATE_N5M "+%Y-%m-%d %H:%M:%S");
|
||||
|
||||
readsensors(){
|
||||
cd /opt/raumklima
|
||||
|
||||
. ./venv/bin/activate
|
||||
python src/read_rs500_test.py > ${TMP0}
|
||||
deactivate
|
||||
|
||||
#Prüfe abgelegte Datei
|
||||
TMP_FILE=$(wc -c ${TMP0} | awk '{print $1}')
|
||||
if [ ${TMP_FILE} -le 12 ]; then
|
||||
sleep 5;
|
||||
readsensors;
|
||||
fi
|
||||
|
||||
}
|
||||
#Start mit Datenabruf
|
||||
readsensors;
|
||||
|
||||
#Erste Zeile entfernen
|
||||
sed -e '1d' ${TMP0} > ${TMP1};
|
||||
#Leerzeichen entfernen
|
||||
tr -d ' ' < ${TMP1} > ${TMP2};
|
||||
|
||||
#Zeilenweise in Array übertragen
|
||||
while read -r DATA;
|
||||
do DATASETS+=(${DATA});
|
||||
done < dl5002.tmp;
|
||||
|
||||
#Zeilen in Variablen nach Raum übertragen
|
||||
for DATASETS in "${DATASETS[@]}"
|
||||
do
|
||||
readarray -td';' DATASET <<< "${DATASETS[@]}";
|
||||
|
||||
declare "S${DATASET[0]}_Temp"=${DATASET[1]};
|
||||
declare "S${DATASET[0]}_Humidity"=${DATASET[2]:0:2};
|
||||
|
||||
done
|
||||
|
||||
#Send data to database
|
||||
mysql -u $DB_USER -p$DB_PASS -h $DB_HOST -D $DB_NAME <<EOF
|
||||
INSERT INTO $DB_TAB (TimeStamp,Nearest5min,S1_Temp,S1_Humidity,S2_Temp,S2_Humidity,S3_Temp,S3_Humidity,S4_Temp,S4_Humidity,S5_Temp,S5_Humidity,S6_Temp,S6_Humidity,S7_Temp,S7_Humidity,S8_Temp,S8_Humidity) VALUES ('${DATE}','${DATE_N5M}','${S1_Temp}','${S1_Humidity}','${S2_Temp}','${S2_Humidity}','${S3_Temp}','${S3_Humidity}','${S4_Temp}','${S4_Humidity}','${S5_Temp}','${S5_Humidity}','${S6_Temp}','${S6_Humidity}','${S7_Temp}','${S7_Humidity}','${S8_Temp}','${S8_Humidity}');
|
||||
EOF
|
||||
|
||||
#Temporäre Dateien entfernen
|
||||
rm dl500*.tmp;
|
||||
Loading…
Reference in New Issue
Block a user