change to mqtt

master
ademant 2020-01-02 07:14:43 +01:00
parent 199c8409b1
commit 4c71eea1b3
3 changed files with 16 additions and 47 deletions

View File

@ -1,6 +1,7 @@
#!/bin/bash
sqlite_com="sqlite3 /home/pi/gps.sqlite"
mysql_com="mysql -u gps -pgps -D gps -e"
script=$(realpath $0)
sp=$(dirname $script)
TTY=$1
rm /tmp/$1
baud=16384
@ -8,9 +9,7 @@ for i in 4800 9600 19200 38400 57600 115200
do
echo $i
stty $i -F /dev/${TTY}
# tds=$(timeout 10s $(test=$(dd if=/dev/$1 bs=1 count=10000|grep RMC|wc -l);if [ $test -gt 0 ]; then exit 1; else exit 0; fi))
timeout 10s /home/pi/gps/check_baud.sh ${TTY}
# echo $?
timeout 10s ${sp}/check_baud.sh ${TTY}
if [ $? -eq "1" ]; then
echo Test
baud=$i
@ -28,19 +27,12 @@ if [ $baud -ne 16384 ]; then
echo ${TTY}
echo $baud
stty $baud -F /dev/${TTY}
dbe=$(sqlite3 /home/pi/gps.sqlite "select max(utc) from GPS_TTY;")
if [ -z "$dbe" ]; then
echo Anlegen TTY-Tabelle
sqlite3 /home/pi/gps.sqlite "create table GPS_TTY (uid integer,tty text,utc integer,idvendor text,idmodel text,baud integer);"
fi
# TTY=$(echo $i|cut -d/ -f3)
uid=$(echo $(udevadm info --name=/dev/${TTY}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
idp=$(udevadm info -a -q property --export -n /dev/${TTY}|grep ID_MODEL_ID|cut -d= -f2|sed -e "s/'//g")
mosquitto_pub -h 172.24.42.2 -t "gpsi/$(hostname)/${uid}/baud" -m ${baud}
idp=$(udevadm info -a -q property --export -n /dev/${TTY}|grep ID_MODEL_ID|cut -d= -f2|sed -e "s/'//g")
idv=$(udevadm info -a -q property --export -n /dev/${TTY}|grep ID_VENDOR_ID|cut -d= -f2|sed -e "s/'//g")
idpath=$(udevadm info -a -q property --export -n ${TTY}|grep ID_PATH=|cut -d= -f2|sed -e "s/'//g")
echo $(date +%s),${TTY},${idp},${idv},$i
${sqlite_com} "insert into GPS_TTY (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F /dev/${TTY} speed),'${idpath}');"
${mysql_com} "insert into gpstty (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F /dev/${TTY} speed),'${idpath}');"
nohup /home/pi/gps/gps_raw5.sh ${TTY} &
nohup ${sp}/gps_raw5.sh ${TTY} &
fi

View File

@ -16,33 +16,8 @@ if [ ! -f /tmp/${TTY}.pid ]; then
mosquitto_pub -h 172.24.42.2 -r -t "gpsi/$(hostname)/${uid}/serial" -m ${serial}
mosquitto_pub -h 172.24.42.2 -r -t "gpsi/$(hostname)/${uid}/model" -m ${model}
datutc=""
unbuffer cat /dev/${TTY} | unbuffer -p tr -dc "[:print:]\n"|unbuffer -p grep -e RMC -e GST -e GGA |unbuffer -p cut -d* -f1|while IFS="," read telegram payload; do
teletyp=$(echo $telegram|cut -b4-)
# mosquitto_pub -h 172.24.42.2 -t "gps/$(hostname)/${uid}/${teletyp}" -m "${payload}"
if [ "$teletyp" == "RMC" ]; then
IFS=',' read rutc rstat rlat rlatd rlon rlond rspeed rtrack rdate rmag rmdi rmod rcheck <<< ${payload}
lati=$(echo ${rlat}*3600000|bc)
# if [ "$rlatd" == "S" ]; then lati=$(echo (-1)*${lati}|bc); fi
long=$(echo ${rlon}*3600000|bc)
# if [ "$rlond" == "W" ]; then long=$(echo (-1)*${long}|bc); fi
sutc=$(( $(echo "inutc=${rutc}; secs=(inutc%100)*100/60; mins=((inutc/100)%100); hours=60*(inutc/10000);print 60*(hours+mins)+secs"|bc) + $(date -d $(echo ${rdate}|cut -b5-6)$(echo ${rdate}|cut -b3-4)$(echo ${rdate}|cut -b1-2) +%s) ))
mpay=$(echo $sutc,$lati,$long,$rspeed,$rtrack)
mosquitto_pub -h 172.24.42.2 -t "gps/${hn}/${uid}/rmc" -m "${mpay}"
echo ${sutc} > /tmp/${TTY}.utc
echo ${sutc}
fi
if [ "$teletyp" == "GST" ]; then
# IFS=',' read rutc rrmc rerrmaj rerrmin rerror rlat rlon rhei rcheck <<< ${payload}
# mpay=$(echo $(cat /tmp/${TTY}.utc),$rrmc,$rlat,$rlon,$rhei)
mpay=$(echo $(cat /tmp/${TTY}.utc),$(cut -d, --output-delimiter=, -f2,6-8 <<< ${payload} ))
mosquitto_pub -h 172.24.42.2 -t "gps/${hn}/${uid}/gst" -m "${mpay}"
fi
if [ "$teletyp" == "GGA" ]; then
# IFS=',' read rutc rlat rlatd rlon rlond rqual rsats rhdop ralt rmalt rund rmund rr <<< ${payload}
# mpay=$(echo $(cat /tmp/${TTY}.utc),$rsats,$rhdop,$ralt,$rund)
mpay=$(echo $(cat /tmp/${TTY}.utc),$(cut -d, --output-delimiter=, -f7-9,11 <<< ${payload} ))
mosquitto_pub -h 172.24.42.2 -t "gps/${hn}/${uid}/gga" -m "${mpay}"
fi
# cat /tmp/${TTY}.utc
done
topicrmc="gps/$(hostname)/${uid}/rmc"
cat /dev/${TTY}|unbuffer -p cut -d* -f1 |unbuffer -p gawk -f ./gps_pre.awk |while read rmc; do
mosquitto_pub -h 172.24.42.2 -t ${topicrmc} -m "$rmc"
done
fi

View File

@ -1,6 +1,8 @@
#!/bin/sh
/home/pi/gps/gps_init2.sh
script=$(realpath $0)
sp=$(dirname $script)
echo $sp
${sp}/gps_init5.sh
for u in /dev/ttyUSB*; do
nohup /home/pi/gps/gps_init_ser.sh $(basename $u) &>/dev/null &
nohup ${sp}/gps_init_ser.sh $(basename $u) &>/dev/null &
done