From 6269a10b99406870b082b7350ae06475888e8957 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 19 Apr 2015 19:21:35 +0200 Subject: [PATCH 1/5] exit error with args parser --- boswatch.py | 63 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/boswatch.py b/boswatch.py index de771e1..b1ceb85 100644 --- a/boswatch.py +++ b/boswatch.py @@ -38,40 +38,41 @@ def log(msg, level="log"): bos_log = open(script_path+"/log_bos.txt", "a") bos_log.write(log_entry+"\n") bos_log.close() - + +# Programm + +#Clear the Logfiles +try: + script_path = os.path.dirname(os.path.abspath(__file__)) + 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") + bos_log.close() + rtl_log.close() + mon_log.close() +except: + log("cannot clear logfiles","error") try: + #With -h or --help you get the Args help + #ArgsParser + parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") + #parser.add_argument("-c", "--channel", help="BOS Channel you want to listen") + parser.add_argument("-f", "--freq", help="Frequency you want to listen", required=True) + parser.add_argument("-d", "--device", help="Device you want to use (Check with rtl_test)", type=int, default=0) + parser.add_argument("-e", "--error", help="Frequency-Error of your Device in PPM", type=int, default=0) + parser.add_argument("-a", "--demod", help="Demodulation Functions", choices=['FMS', 'ZVEI', 'POC512', 'POC1200', 'POC2400'], required=True, nargs="+") + parser.add_argument("-s", "--squelch", help="Level of Squelch", type=int, default=0) + parser.add_argument("-v", "--verbose", help="Shows more Information", action="store_true") + parser.add_argument("-q", "--quiet", help="Shows no Information. Only Logfiles", action="store_true") + args = parser.parse_args() +except: + log("cannot parse Args","error") - script_path = os.path.dirname(os.path.abspath(__file__)) - - try: - 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") - bos_log.close() - rtl_log.close() - mon_log.close() - except: - log("cannot clear logfiles","error") - - try: - #With -h or --help you get the Args help - #ArgsParser - parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") - #parser.add_argument("-c", "--channel", help="BOS Channel you want to listen") - parser.add_argument("-f", "--freq", help="Frequency you want to listen", required=True) - parser.add_argument("-d", "--device", help="Device you want to use (Check with rtl_test)", type=int, default=0) - parser.add_argument("-e", "--error", help="Frequency-Error of your Device in PPM", type=int, default=0) - parser.add_argument("-a", "--demod", help="Demodulation Functions", choices=['FMS', 'ZVEI', 'POC512', 'POC1200', 'POC2400'], required=True, nargs="+") - parser.add_argument("-s", "--squelch", help="Level of Squelch", type=int, default=0) - parser.add_argument("-v", "--verbose", help="Shows more Information", action="store_true") - parser.add_argument("-q", "--quiet", help="Shows no Information. Only Logfiles", action="store_true") - args = parser.parse_args() - except: - log("cannot parse Args","error") +try: #Read Data from Args, Put it into working Variables freq = args.freq From 53b93e466bd6456815e4c988531f70cb3b6d94f0 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Sun, 19 Apr 2015 21:48:10 +0200 Subject: [PATCH 2/5] update -y arg --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 76e3f6d..4eb6c7a 100644 --- a/install.sh +++ b/install.sh @@ -20,7 +20,7 @@ tput cup 13 15 echo "[ 1/10] [#---------]" tput cup 15 5 echo "-> make a apt-get update................" -apt-get update > ~/bos/install/setup_log.txt 2>&1 +apt-get update -y > ~/bos/install/setup_log.txt 2>&1 tput cup 13 15 echo "[ 2/10] [##--------]" From 7dba02be33ea8cf33942771e62f3529f8cbb65dc Mon Sep 17 00:00:00 2001 From: Smith-fms Date: Mon, 27 Apr 2015 01:06:29 +0200 Subject: [PATCH 3/5] added POCSAG512 and POGSAC1200 support --- boswatch.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/boswatch.py b/boswatch.py index b1ceb85..4ee4946 100644 --- a/boswatch.py +++ b/boswatch.py @@ -131,6 +131,10 @@ try: zvei_id = 0 zvei_id_old = 0 zvei_time_old = 0 + + poc_id = 0 + poc_id_old = 0 + poc_time_old = 0 #ConfigParser @@ -140,6 +144,7 @@ try: 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")) + poc_double_ignore_time = int(config.get("POC", "double_ignore_time")) #MySQL config useMySQL = int(config.get("Module", "useMySQL")) #use MySQL support? @@ -165,6 +170,7 @@ try: log("set to standard configuration") fms_double_ignore_time = 5 zvei_double_ignore_time = 5 + poc_double_ignore_time = 10 useMySQL = 0 useHTTPrequest = 0 @@ -312,6 +318,103 @@ try: log("ZVEI to HTTP failed","error") else: log("No valid ZVEI: "+zvei_id) + #POCSAG512 Decoder Section + #check POCSAG512: -> validate -> check double alarm -> log -> (MySQL) + #POCSAG512: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh + + if "POCSAG512:" in decoded: + log("recived POCSAG1200") + poc_id = decoded[20:27] #POC Code + poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") + if decoded.__contains__("Alpha:"): + poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() + else: + poc_text = "" + if len(poc_id) == 7: #if POC is valid + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + log("POC512 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + log("POCSAG512: "+poc_id+""+poc_sub+""+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) + cursor.close() + connection.commit() + except: + log("POC512 to MySQL failed","error") + finally: + connection.close() #Close connection in every case + + if useHTTPrequest: #only if HTTPrequest is active + log("POC512 to HTTP") + try: + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") + except: + log("POCSAG512 to HTTP failed","error") + else: + log("No valid POCSAG512: "+poc_id) + + #POCSAG1200 Decoder Section + #check POCSAG1200: -> validate -> check double alarm -> log -> (MySQL) + #POCSAG1200: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh + + if "POCSAG1200:" in decoded: + log("recived POCSAG1200") + poc_id = decoded[21:28] #POC Code + poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") + if decoded.__contains__("Alpha:"): + poc_text = decoded.split('Alpha: ')[1].strip().rstrip('').strip() + else: + poc_text = "" + if len(poc_id) == 7: #if POC is valid + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + log("POC1200 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + log("POCSAG1200: "+poc_id+""+poc_sub+""+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) + cursor.close() + connection.commit() + except: + log("POC1200 to MySQL failed","error") + finally: + connection.close() #Close connection in every case + + if useHTTPrequest: #only if HTTPrequest is active + log("POC1200 to HTTP") + try: + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") + except: + log("POCSAG1200 to HTTP failed","error") + else: + log("No valid POCSAG1200: "+poc_id) except KeyboardInterrupt: @@ -324,4 +427,4 @@ finally: multimon_ng.terminate() log("multimon-ng terminated") log("exiting BOSWatch") - exit(0) \ No newline at end of file + exit(0) From edd664803938ef9144878ac86f3a9cbc27386484 Mon Sep 17 00:00:00 2001 From: Smith-fms Date: Mon, 27 Apr 2015 15:11:09 +0200 Subject: [PATCH 4/5] Added rangefilter for POCSAG1200 and POCSAG512 --- boswatch.py | 151 +++++++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 67 deletions(-) diff --git a/boswatch.py b/boswatch.py index 4ee4946..13d2a44 100644 --- a/boswatch.py +++ b/boswatch.py @@ -141,11 +141,13 @@ try: log("reading config file") try: config = ConfigParser.ConfigParser() - config.read(script_path+"/config.ini") + config.read(script_path+"/config/config.ini") fms_double_ignore_time = int(config.get("FMS", "double_ignore_time")) zvei_double_ignore_time = int(config.get("ZVEI", "double_ignore_time")) poc_double_ignore_time = int(config.get("POC", "double_ignore_time")) - + poc_filter_range_start = int(config.get("POC", "filter_range_start")) + poc_filter_range_end = int(config.get("POC", "filter_range_end")) + #MySQL config useMySQL = int(config.get("Module", "useMySQL")) #use MySQL support? if useMySQL: #only if MySQL is active @@ -171,9 +173,12 @@ try: fms_double_ignore_time = 5 zvei_double_ignore_time = 5 poc_double_ignore_time = 10 + poc_filter_range_start = 0000000 + poc_filter_range_end = 9999999 useMySQL = 0 useHTTPrequest = 0 + if useMySQL: #only if MySQL is active log("testing MySQL connection") @@ -323,7 +328,7 @@ try: #POCSAG512: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh if "POCSAG512:" in decoded: - log("recived POCSAG1200") + log("recived POCSAG512") poc_id = decoded[20:27] #POC Code poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") if decoded.__contains__("Alpha:"): @@ -331,39 +336,45 @@ try: else: poc_text = "" if len(poc_id) == 7: #if POC is valid - if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - log("POC512 double alarm: "+poc_id_old) - poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + if poc_id >= poc_filter_range_start: + if poc_id >= poc_filter_range_start: + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + log("POC512 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + log("POCSAG512: "+poc_id+" "+poc_sub+" "+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) + cursor.close() + connection.commit() + except: + log("POC512 to MySQL failed","error") + finally: + connection.close() #Close connection in every case + + if useHTTPrequest: #only if HTTPrequest is active + log("POC512 to HTTP") + try: + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") + except: + log("POCSAG512 to HTTP failed","error") + else: + log("POCSAG512: "+poc_id+" out of filter range! Nothing to do.","info") else: - log("POCSAG512: "+poc_id+""+poc_sub+""+poc_text,"info") - poc_id_old = poc_id #save last id - poc_time_old = timestamp #save last time - - if useMySQL: #only if MySQL is active - log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) - cursor.close() - connection.commit() - except: - log("POC512 to MySQL failed","error") - finally: - connection.close() #Close connection in every case - - if useHTTPrequest: #only if HTTPrequest is active - log("POC512 to HTTP") - try: - httprequest = httplib.HTTPConnection(url) - httprequest.request("HEAD", "/") - httpresponse = httprequest.getresponse() - if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error - log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) - else: - log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") - except: - log("POCSAG512 to HTTP failed","error") + log("POCSAG512: "+poc_id+" out of filter range! Nothing to do.","info") else: log("No valid POCSAG512: "+poc_id) @@ -380,39 +391,45 @@ try: else: poc_text = "" if len(poc_id) == 7: #if POC is valid - if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm - log("POC1200 double alarm: "+poc_id_old) - poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + if poc_id >= poc_filter_range_start: + if poc_id >= poc_filter_range_start: + if poc_id == poc_id_old and timestamp < poc_time_old + poc_double_ignore_time: #check for double alarm + log("POC1200 double alarm: "+poc_id_old) + poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new + else: + log("POCSAG1200: "+poc_id+" "+poc_sub+" "+poc_text,"info") + poc_id_old = poc_id #save last id + poc_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) + cursor.close() + connection.commit() + except: + log("POC1200 to MySQL failed","error") + finally: + connection.close() #Close connection in every case + + if useHTTPrequest: #only if HTTPrequest is active + log("POC1200 to HTTP") + try: + httprequest = httplib.HTTPConnection(url) + httprequest.request("HEAD", "/") + httpresponse = httprequest.getresponse() + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") + except: + log("POCSAG1200 to HTTP failed","error") + else: + log("POCSAG1200: "+poc_id+" out of filter range! Nothing to do.","info") else: - log("POCSAG1200: "+poc_id+""+poc_sub+""+poc_text,"info") - poc_id_old = poc_id #save last id - poc_time_old = timestamp #save last time - - if useMySQL: #only if MySQL is active - log("POC to 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 "+tablePOC+" (time,ric,funktion,text) VALUES (%s,%s,%s,%s)",(curtime(),poc_id,poc_sub,poc_text,)) - cursor.close() - connection.commit() - except: - log("POC1200 to MySQL failed","error") - finally: - connection.close() #Close connection in every case - - if useHTTPrequest: #only if HTTPrequest is active - log("POC1200 to HTTP") - try: - httprequest = httplib.HTTPConnection(url) - httprequest.request("HEAD", "/") - httpresponse = httprequest.getresponse() - if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error - log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) - else: - log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") - except: - log("POCSAG1200 to HTTP failed","error") + log("POCSAG1200: "+poc_id+" out of filter range! Nothing to do.","info") else: log("No valid POCSAG1200: "+poc_id) From 429a571f0f78b2e76d60cb55cba8b7f615e60f23 Mon Sep 17 00:00:00 2001 From: Smith-fms Date: Mon, 27 Apr 2015 15:12:42 +0200 Subject: [PATCH 5/5] added rangefilter and poc double_ignore function --- config.ini | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/config.ini b/config.ini index 8771905..32247f9 100644 --- a/config.ini +++ b/config.ini @@ -10,23 +10,29 @@ double_ignore_time = 5 #time to ignore same alarm in a row (sek) double_ignore_time = 5 +[POC] +#time to ignore same alarm in a row (sek) +double_ignore_time = 10 +filter_range_start = 0000000 +filter_range_end = 9999999 + #can take on or off the modules (0|1) [Module] -useMySQL = 0 +useMySQL = 1 #useAudiorecord = 0 useHTTPrequest = 0 [MySQL] #Data for MySQL connection -dbserver = localhost -dbuser = root -dbpassword = root -database = boswatch +dbserver = www.bos-tec.de +dbuser = raspoc +dbpassword = 080787 +database = bos-tec.de #tables in the database tableFMS = bos_fms tableZVEI = bos_zvei -tablePOC = bos_pocsag +tablePOC = pocsag_hist #[Audiorecord] #recording time (sek) @@ -34,4 +40,4 @@ tablePOC = bos_pocsag [HTTPrequest] #url without http:// ! -url = www.google.de \ No newline at end of file +url = www.google.de