From 3b63e41466adc7e6617ac962873dd255f0192343 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 20:12:58 +0200 Subject: [PATCH 1/9] fixed install.sh replace /home/pi with ~ (Userpath) --- README.md | 2 +- install.sh | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index fe544ee..4082767 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ You can easy install BOSWatch with the install.sh Script. - And use the script `sudo sh install.sh` Now the script downloads and compile all needed data. -At the end you can find the Programm in `/home/pi/bos/BOSWatch` +At the end you can find the Programm in `~/bos/BOSWatch` Caution, script don't install a Webserver with PHP and MySQL. So you have to make up manually if you want to use MySQL support. diff --git a/install.sh b/install.sh index 23eac5a..76e3f6d 100644 --- a/install.sh +++ b/install.sh @@ -14,26 +14,26 @@ echo "" echo "Caution, script don't install a Webserver with PHP and MySQL" echo "So you have to make up manually if you want to use MySQL support" -mkdir -p /home/pi/bos/install +mkdir -p ~/bos/install tput cup 13 15 echo "[ 1/10] [#---------]" tput cup 15 5 echo "-> make a apt-get update................" -apt-get update > /home/pi/bos/install/setup_log.txt 2>&1 +apt-get update > ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 2/10] [##--------]" tput cup 15 5 echo "-> download GIT an other stuff.........." -apt-get -y install git cmake build-essential libusb-1.0 qt4-qmake libpulse-dev libx11-dev sox >> /home/pi/bos/install/setup_log.txt 2>&1 +apt-get -y install git cmake build-essential libusb-1.0 qt4-qmake libpulse-dev libx11-dev sox >> ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 3/10] [###-------]" tput cup 15 5 echo "-> download rtl_fm......................" -cd /home/pi/bos/install -git clone git://git.osmocom.org/rtl-sdr.git >> /home/pi/bos/install/setup_log.txt 2>&1 +cd ~/bos/install +git clone git://git.osmocom.org/rtl-sdr.git >> ~/bos/install/setup_log.txt 2>&1 cd rtl-sdr/ tput cup 13 15 @@ -41,17 +41,17 @@ echo "[ 4/10] [####------]" tput cup 15 5 echo "-> compile rtl_fm......................" mkdir -p build && cd build -cmake ../ -DINSTALL_UDEV_RULES=ON >> /home/pi/bos/install/setup_log.txt 2>&1 -make >> /home/pi/bos/install/setup_log.txt 2>&1 -make install >> /home/pi/bos/install/setup_log.txt 2>&1 -ldconfig >> /home/pi/bos/install/setup_log.txt 2>&1 +cmake ../ -DINSTALL_UDEV_RULES=ON >> ~/bos/install/setup_log.txt 2>&1 +make >> ~/bos/install/setup_log.txt 2>&1 +make install >> ~/bos/install/setup_log.txt 2>&1 +ldconfig >> ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 5/10] [#####-----]" tput cup 15 5 echo "-> download multimon-ng................" -cd /home/pi/bos/install -git clone https://github.com/EliasOenal/multimonNG.git >> /home/pi/bos/install/setup_log.txt 2>&1 +cd ~/bos/install +git clone https://github.com/EliasOenal/multimonNG.git >> ~/bos/install/setup_log.txt 2>&1 cd multimonNG/ tput cup 13 15 @@ -60,17 +60,17 @@ tput cup 15 5 echo "-> compile multimon-ng................." mkdir -p build cd build -qmake ../multimon-ng.pro >> /home/pi/bos/install/setup_log.txt 2>&1 -make >> /home/pi/bos/install/setup_log.txt 2>&1 -make install >> /home/pi/bos/install/setup_log.txt 2>&1 +qmake ../multimon-ng.pro >> ~/bos/install/setup_log.txt 2>&1 +make >> ~/bos/install/setup_log.txt 2>&1 +make install >> ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 7/10] [#######---]" tput cup 15 5 echo "-> download MySQL Connector for Python." -cd /home/pi/bos/install -wget "http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-1.0.9.tar.gz/from/http://cdn.mysql.com/" -O mysql-connector.tar >> /home/pi/bos/install/setup_log.txt 2>&1 -tar xfv mysql-connector.tar >> /home/pi/bos/install/setup_log.txt 2>&1 +cd ~/bos/install +wget "http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-1.0.9.tar.gz/from/http://cdn.mysql.com/" -O mysql-connector.tar >> ~/bos/install/setup_log.txt 2>&1 +tar xfv mysql-connector.tar >> ~/bos/install/setup_log.txt 2>&1 cd mysql-connector-python* tput cup 13 15 @@ -78,14 +78,14 @@ echo "[ 8/10] [########--]" tput cup 15 5 echo "-> install MySQL Connector for Python.." chmod +x ./setup.py -./setup.py install >> /home/pi/bos/install/setup_log.txt 2>&1 +./setup.py install >> ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 9/10] [#########-]" tput cup 15 5 echo "-> download BOSWatch..................." -cd /home/pi/bos -git clone https://github.com/Schrolli91/BOSWatch >> /home/pi/bos/install/setup_log.txt 2>&1 +cd ~/bos +git clone https://github.com/Schrolli91/BOSWatch >> ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[10/10] [##########]" @@ -96,5 +96,5 @@ chmod +x * echo "# blacklist the DVB drivers to avoid conflict with the SDR driver\n blacklist dvb_usb_rtl28xxu \n blacklist rtl2830\n blacklist dvb_usb_v2\n blacklist dvb_core" >> /etc/modprobe.d/boswatch_blacklist_sdr.conf tput cup 17 1 -echo "BOSWatch are now in /home/pi/bos/BOSWatch/" +echo "BOSWatch are now in ~/bos/BOSWatch/" echo "Install ready!" \ No newline at end of file From e301585c810c48791e6547f6a33c714e18a3a5c5 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 20:18:11 +0200 Subject: [PATCH 2/9] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4082767..39c06ae 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG -### Note: +#### Note: **This software is for illustrative purposes only and may be used only by authorized persons.** **The intercept of the German BOS radio is strictly prohibited !!!** + **Please** only use Code from **master**-Branch - thats **the only stable!** unless you are developer you can use the develop-Branch - may be unstable! From 046ae7263b0600211313e52af4a31e46d0b91de6 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 20:40:02 +0200 Subject: [PATCH 3/9] edit some error messages --- boswatch.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/boswatch.py b/boswatch.py index d16b3a8..578785f 100644 --- a/boswatch.py +++ b/boswatch.py @@ -146,7 +146,7 @@ try: url = config.get("HTTPrequest", "url") except: - log("config reading error","error") + log("cannot read config file","error") #variables pre-load log("pre-load variables") @@ -163,7 +163,7 @@ try: try: connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) except: - log("MySQL connect error","error") + log("cannot connect to MySQL database","error") log("starting rtl_fm") @@ -225,30 +225,30 @@ try: fms_time_old = timestamp #save last time if useMySQL: #only if MySQL is active - log("FMS to MySQL") + log("insert FMS into MySQL") try: cursor = connection.cursor() cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) cursor.close() connection.commit() except: - log("FMS cannot insert","error") + log("FMS cannot insert into MySQL","error") if useHTTPrequest: #only if HTTPrequest is active - log("FMS to HTTP") + log("FMS to HTTP request") try: httprequest = httplib.HTTPConnection(url) httprequest.request("HEAD", "/") httpresponse = httprequest.getresponse() #if args.verbose: print httpresponse.status, httpresponse.reason except: - log("FMS cannot request","error") + log("FMS HTTP request failed","error") else: log("No valid FMS: "+fms_id) else: - log("CRC incorrect") + log("FMS CRC incorrect") #ZVEI Decoder Section @@ -268,25 +268,25 @@ try: if useMySQL: #only if MySQL is active - log("ZVEI to MySQL") + log("insert ZVEI into MySQL") try: cursor = connection.cursor() cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) cursor.close() connection.commit() except: - log("ZVEI cannot insert","error") + log("ZVEI cannot insert into MySQL","error") if useHTTPrequest: #only if HTTPrequest is active - log("ZVEI to HTTP") + log("ZVEI to HTTP request") try: httprequest = httplib.HTTPConnection(url) httprequest.request("HEAD", "/") httpresponse = httprequest.getresponse() #if args.verbose: print httpresponse.status, httpresponse.reason except: - log("ZVEI cannot request","error") + log("ZVEI HTTP request failed","error") else: log("No valid ZVEI: "+zvei_id) From 36584dce162a9c9f3d744ec440b42c312e1f045d Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 21:02:56 +0200 Subject: [PATCH 4/9] change relative to absolute paths --- boswatch.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/boswatch.py b/boswatch.py index 578785f..59ce75f 100644 --- a/boswatch.py +++ b/boswatch.py @@ -11,7 +11,7 @@ import time #import sys import subprocess -#import os +import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) import mysql import mysql.connector import httplib @@ -20,7 +20,6 @@ import argparse #for parse the args import ConfigParser #for parse the config file import re #Regex - # Functions def curtime(format="%Y-%m-%d %H:%M:%S"): return time.strftime(format) @@ -35,17 +34,19 @@ def log(msg, level="log"): if not level == "log" and not args.quiet or args.verbose: print log_entry - bos_log = open("log_bos.txt", "a") + bos_log = open(script_path+"/log_bos.txt", "a") bos_log.write(log_entry+"\n") bos_log.close() try: + script_path = os.path.dirname(os.path.abspath(__file__)) + try: - bos_log = open("log_bos.txt", "w") - rtl_log = open("log_rtl.txt", "w") - mon_log = open("log_mon.txt", "w") + bos_log = open(script_path+"/log_bos.txt", "w") + rtl_log = open(script_path+"/log_rtl.txt", "w") + mon_log = open(script_path+"/log_mon.txt", "w") bos_log.write("##### "+curtime()+" #####\n\n") rtl_log.write("##### "+curtime()+" #####\n\n") mon_log.write("##### "+curtime()+" #####\n\n") @@ -123,7 +124,7 @@ try: log("reading config file") try: config = ConfigParser.ConfigParser() - config.read("./config.ini") + config.read(script_path+"/config.ini") fms_double_ignore_time = int(config.get("FMS", "double_ignore_time")) zvei_double_ignore_time = int(config.get("ZVEI", "double_ignore_time")) @@ -171,7 +172,7 @@ try: rtl_fm = subprocess.Popen("rtl_fm -d "+str(device)+" -f "+str(freq)+" -M fm -s 22050 -p "+str(error)+" -E DC -F 0 -l "+str(squelch)+" -g 100", #stdin=rtl_fm.stdout, stdout=subprocess.PIPE, - stderr=open('log_rtl.txt','a'), + stderr=open(script_path+"/log_rtl.txt","a"), shell=True) except: log("cannot start rtl_fm","error") @@ -182,7 +183,7 @@ try: multimon_ng = subprocess.Popen("multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - ", stdin=rtl_fm.stdout, stdout=subprocess.PIPE, - stderr=open('log_mon.txt','a'), + stderr=open(script_path+"/log_mon.txt","a"), shell=True) except: log("cannot start multimon-ng","error") @@ -232,8 +233,7 @@ try: cursor.close() connection.commit() except: - log("FMS cannot insert into MySQL","error") - + log("FMS cannot insert into MySQL","error") if useHTTPrequest: #only if HTTPrequest is active log("FMS to HTTP request") @@ -243,8 +243,7 @@ try: httpresponse = httprequest.getresponse() #if args.verbose: print httpresponse.status, httpresponse.reason except: - log("FMS HTTP request failed","error") - + log("FMS HTTP request failed","error") else: log("No valid FMS: "+fms_id) else: @@ -265,8 +264,7 @@ try: log("5-Ton: "+zvei_id,"info") zvei_id_old = zvei_id #save last id zvei_time_old = timestamp #save last time - - + if useMySQL: #only if MySQL is active log("insert ZVEI into MySQL") try: @@ -275,8 +273,7 @@ try: cursor.close() connection.commit() except: - log("ZVEI cannot insert into MySQL","error") - + log("ZVEI cannot insert into MySQL","error") if useHTTPrequest: #only if HTTPrequest is active log("ZVEI to HTTP request") @@ -286,8 +283,7 @@ try: httpresponse = httprequest.getresponse() #if args.verbose: print httpresponse.status, httpresponse.reason except: - log("ZVEI HTTP request failed","error") - + log("ZVEI HTTP request failed","error") else: log("No valid ZVEI: "+zvei_id) From 6efb78130922f769b35bbbb29d8cc18123896d3e Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 21:18:37 +0200 Subject: [PATCH 5/9] fix sql connection timeout for every action a new connection are created and closed --- boswatch.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/boswatch.py b/boswatch.py index 59ce75f..78484ad 100644 --- a/boswatch.py +++ b/boswatch.py @@ -14,11 +14,11 @@ import subprocess import os #for absolute path: os.path.dirname(os.path.abspath(__file__)) import mysql import mysql.connector -import httplib +import httplib #for the HTTP request import argparse #for parse the args import ConfigParser #for parse the config file -import re #Regex +import re #Regex for validation # Functions def curtime(format="%Y-%m-%d %H:%M:%S"): @@ -160,11 +160,14 @@ try: zvei_time_old = 0 if useMySQL: #only if MySQL is active - log("connect to MySQL database") + log("testing MySQL connection") try: connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) + connection.close() + log("connection test successful") except: - log("cannot connect to MySQL database","error") + log("connection test failed - MySQL support deactivated","error") + useMySQL = 0 log("starting rtl_fm") @@ -228,10 +231,12 @@ try: if useMySQL: #only if MySQL is active log("insert FMS into MySQL") try: + connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) cursor = connection.cursor() cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) cursor.close() connection.commit() + connection.close() except: log("FMS cannot insert into MySQL","error") @@ -268,10 +273,12 @@ try: if useMySQL: #only if MySQL is active log("insert ZVEI into MySQL") try: + connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) cursor = connection.cursor() cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) cursor.close() connection.commit() + connection.close() except: log("ZVEI cannot insert into MySQL","error") @@ -292,9 +299,6 @@ except KeyboardInterrupt: except: log("unknown Error","error") finally: - if useMySQL: #only if MySQL is active - log("disconnect MySQL") - connection.close() rtl_fm.terminate() log("rtl_fm terminated") multimon_ng.terminate() From 40d45538db9ea74416ae769319e91e8fb136ce7d Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 21:20:48 +0200 Subject: [PATCH 6/9] preload variables --- boswatch.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/boswatch.py b/boswatch.py index 78484ad..00c057d 100644 --- a/boswatch.py +++ b/boswatch.py @@ -120,6 +120,19 @@ try: print "Verbose Mode!" print "" + #variables pre-load + log("pre-load variables") + fms_id = 0 + fms_id_old = 0 + fms_time_old = 0 + + zvei_id = 0 + zvei_id_old = 0 + zvei_time_old = 0 + + useMySQL = 0 + useHTTPrequest = 0 + #ConfigParser log("reading config file") try: @@ -148,16 +161,7 @@ try: except: log("cannot read config file","error") - - #variables pre-load - log("pre-load variables") - fms_id = 0 - fms_id_old = 0 - fms_time_old = 0 - - zvei_id = 0 - zvei_id_old = 0 - zvei_time_old = 0 + if useMySQL: #only if MySQL is active log("testing MySQL connection") From c4efc529a92c94b82bf6097c02cf9992be997efb Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 21:36:15 +0200 Subject: [PATCH 7/9] in case of config file error set std values --- boswatch.py | 26 +++++++++++++++----------- config.ini | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/boswatch.py b/boswatch.py index 00c057d..2d73e27 100644 --- a/boswatch.py +++ b/boswatch.py @@ -120,18 +120,16 @@ try: print "Verbose Mode!" print "" - #variables pre-load - log("pre-load variables") - fms_id = 0 - fms_id_old = 0 - fms_time_old = 0 + #variables pre-load + log("pre-load variables") + fms_id = 0 + fms_id_old = 0 + fms_time_old = 0 - zvei_id = 0 - zvei_id_old = 0 - zvei_time_old = 0 - - useMySQL = 0 - useHTTPrequest = 0 + zvei_id = 0 + zvei_id_old = 0 + zvei_time_old = 0 + #ConfigParser log("reading config file") @@ -161,6 +159,12 @@ try: except: log("cannot read config file","error") + + log("set to standard configuration") + fms_double_ignore_time = 5 + zvei_double_ignore_time = 5 + useMySQL = 0 + useHTTPrequest = 0 if useMySQL: #only if MySQL is active diff --git a/config.ini b/config.ini index 98969de..8771905 100644 --- a/config.ini +++ b/config.ini @@ -4,7 +4,7 @@ [FMS] #time to ignore same alarm in a row (sek) -double_ignore_time = 10 +double_ignore_time = 5 [ZVEI] #time to ignore same alarm in a row (sek) From f45b4797ac3946ef7bf655270e155a755c8467ab Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 21:38:17 +0200 Subject: [PATCH 8/9] sql connection close in every case --- boswatch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/boswatch.py b/boswatch.py index 2d73e27..04242cf 100644 --- a/boswatch.py +++ b/boswatch.py @@ -171,11 +171,12 @@ try: log("testing MySQL connection") try: connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) - connection.close() log("connection test successful") except: log("connection test failed - MySQL support deactivated","error") useMySQL = 0 + finally: + connection.close() #Close connection in every case log("starting rtl_fm") @@ -244,9 +245,10 @@ try: cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) cursor.close() connection.commit() - connection.close() except: - log("FMS cannot insert into MySQL","error") + log("FMS cannot insert into MySQL","error") + finally: + connection.close() #Close connection in every case if useHTTPrequest: #only if HTTPrequest is active log("FMS to HTTP request") @@ -286,9 +288,10 @@ try: cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) cursor.close() connection.commit() - connection.close() except: - log("ZVEI cannot insert into MySQL","error") + log("ZVEI cannot insert into MySQL","error") + finally: + connection.close() #Close connection in every case if useHTTPrequest: #only if HTTPrequest is active log("ZVEI to HTTP request") From bcd45125914ed8da743ac12b90577f68034f27a1 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Tue, 7 Apr 2015 22:31:16 +0200 Subject: [PATCH 9/9] update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 39c06ae..20c64b4 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ unless you are developer you can use the develop-Branch - may be unstable! ##### boswatch.py The configuration for the Script you can find in config.ini - You can set the ignore time for double alarms in seconds. -- To use the script with MySQL Support set "useMySQL = 1" and the Userdata to your local MySQL Database. +- to use the script with MySQL Support set "useMySQL = 1" and the Userdata to your local MySQL Database. +- to use the script with HTTP request Support set "useHTTPrequest = 1" and set a URL to your destination. For the other Functions see "Usage" below. @@ -66,6 +67,7 @@ optional arguments: -s SQUELCH, --squelch SQUELCH Level of Squelch -v, --verbose Shows more Information + -q, --quiet Shows no Information. Only Logfiles ``` ### Installation