From 7d160dbd4387cdff9e79059419ccfdb01569fd11 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 16:53:41 +0200 Subject: [PATCH 1/6] typing error in BOSWatch description --- README.md | 2 +- boswatch.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index df8486d..893805b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ usage: boswatch.py [-h] -f FREQ [-d DEVICE] [-e ERROR] -a [{FMS,ZVEI,POC512,POC1200,POC2400} ...] [-s SQUELCH] [-v] BOSWatch is a Python Script to Recive and Decode BOS Information with rtl_fm -ans multimon-NG +and multimon-NG optional arguments: -h, --help show this help message and exit diff --git a/boswatch.py b/boswatch.py index c25745a..9550802 100644 --- a/boswatch.py +++ b/boswatch.py @@ -3,7 +3,7 @@ ##### Info ##### # BOSWatch -# Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG +# Python Script to Recive and Decode BOS Information with rtl_fm and multimon-NG # For more Information see the README.md ##### Info ##### @@ -38,7 +38,7 @@ def stop_script(err): #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 BOS Information with rtl_fm ans multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") +parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode 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) From 5bb86ceaa01fc8625cfe84c79300aafec41826b6 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 20:38:23 +0200 Subject: [PATCH 2/6] simple Web Frontend First simple Web Frontend and Database restruction --- README.md | 3 ++- boswatch.sql | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ config.ini | 8 +++--- www/config.php | 12 +++++++++ www/index.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 boswatch.sql create mode 100644 www/config.php create mode 100644 www/index.php diff --git a/README.md b/README.md index 893805b..808de76 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,13 @@ Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG - ZVEI validation (plausibility test) - MySQL Database Support for FMS and ZVEI - All configurations in seperate File "config.ini" +- simple Web Frontend #####Fetaures for the Future: - extensive filtering options - POCSAG 512,1200,2400 support - automatic Audio recording at alarm -- Web Frontend +- Web Frontend with configuration ### Usage `sudo python boswatch.py -f 85.235M -a FMS ZVEI -s 50` diff --git a/boswatch.sql b/boswatch.sql new file mode 100644 index 0000000..489eecd --- /dev/null +++ b/boswatch.sql @@ -0,0 +1,72 @@ +-- phpMyAdmin SQL Dump +-- version 3.4.11.1deb2+deb7u1 +-- http://www.phpmyadmin.net +-- +-- Host: localhost +-- Erstellungszeit: 03. Apr 2015 um 11:16 +-- Server Version: 5.5.41 +-- PHP-Version: 5.4.39-0+deb7u1 + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Datenbank: `boswatch` +-- + +-- -------------------------------------------------------- + +-- +-- Tabellenstruktur für Tabelle `bos_fms` +-- + +CREATE TABLE IF NOT EXISTS `bos_fms` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `time` datetime NOT NULL, + `service` varchar(1) NOT NULL, + `country` varchar(2) NOT NULL, + `location` varchar(2) NOT NULL, + `vehicle` varchar(4) NOT NULL, + `status` varchar(1) NOT NULL, + `direction` varchar(1) NOT NULL, + `tsi` varchar(3) NOT NULL, + PRIMARY KEY (`ID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- -------------------------------------------------------- + +-- +-- Tabellenstruktur für Tabelle `bos_pocsag` +-- + +CREATE TABLE IF NOT EXISTS `bos_pocsag` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `time` datetime NOT NULL, + `ric` varchar(7) NOT NULL DEFAULT '0', + `funktion` int(1) NOT NULL, + `text` text NOT NULL, + KEY `ID` (`ID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- -------------------------------------------------------- + +-- +-- Tabellenstruktur für Tabelle `bos_zvei` +-- + +CREATE TABLE IF NOT EXISTS `bos_zvei` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `time` datetime NOT NULL, + `zvei` varchar(5) NOT NULL DEFAULT '0', + PRIMARY KEY (`ID`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/config.ini b/config.ini index ee2f144..fd273f9 100644 --- a/config.ini +++ b/config.ini @@ -7,11 +7,11 @@ dbserver = localhost dbuser = root dbpassword = root -database = raspoc +database = boswatch -tableFMS = ras_fms_hist -tableZVEI = ras_zvei_hist -tablePOC = ras_pocsag_hist +tableFMS = bos_fms +tableZVEI = bos_zvei +tablePOC = bos_pocsag [FMS] #time to ignore same alarm in a row in seconds diff --git a/www/config.php b/www/config.php new file mode 100644 index 0000000..f0b96e5 --- /dev/null +++ b/www/config.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..15a7573 --- /dev/null +++ b/www/index.php @@ -0,0 +1,70 @@ + + + + + + +BOSWatch + + + +
+ +

BOSWatch

+ + Last alarms for FMS and ZVEI (max. 50)

+ +
+ Last FMS alarms + '; + while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC)) + { + echo ""; + echo "". $data['id'] . ""; + echo "". $data['time'] . ""; + echo "". $data['service'] . ""; + echo "". $data['country'] . ""; + echo "". $data['location'] . ""; + echo "". $data['vehicle'] . ""; + echo "". $data['status'] . ""; + echo "". $data['direction'] . ""; + echo "". $data['tsi'] . ""; + echo ""; + } + echo ""; + ?> +
+ +
+ Last ZVEI alarms + '; + while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC)) + { + echo ""; + echo "". $data['id'] . ""; + echo "". $data['time'] . ""; + echo "". $data['zvei'] . ""; + echo ""; + } + echo ""; + ?> +
+ +
+ + + \ No newline at end of file From 9aa8c0155795f05cb2b7ea63acdaf35ed6dda678 Mon Sep 17 00:00:00 2001 From: Schrolli91 Date: Fri, 3 Apr 2015 20:48:53 +0200 Subject: [PATCH 3/6] Update README.md Section Configuration created --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 808de76..0027cbd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # BOSWatch Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG -### Fetaures -#####Actual implementet: +### Features +#####Implementeted Features: - FMS and ZVEI decoding and Displaying - Filtering double alarms with adjustable time - ZVEI validation (plausibility test) @@ -10,12 +10,22 @@ Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG - All configurations in seperate File "config.ini" - simple Web Frontend -#####Fetaures for the Future: +#####Features for the Future: - extensive filtering options - POCSAG 512,1200,2400 support - automatic Audio recording at alarm - Web Frontend with configuration +### Configuration +##### boswatch.py +To use the boswatch.py script, you must edit the "config.ini". +Now you must set the Userdata to your local MySQL Database. +For the other Functions see "Usage" below. + +##### Web Frontend +Put the Files in Folder /wwww/ into your local Webserver Folder (/var/www/). +Now you must edit the "config.php" with your Userdata to yout local Database. + ### Usage `sudo python boswatch.py -f 85.235M -a FMS ZVEI -s 50` Starts boswatch at Frequency 85.235 MHz with the Demodulation Functions FMS and ZVEI. @@ -45,4 +55,4 @@ optional arguments: -v, --verbose Shows more Information More Options you can find in the extern config.ini File in this Folder -``` \ No newline at end of file +``` From fcc4ba3389f8ece997ce06c2fda34b15c4ce5166 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 21:43:00 +0200 Subject: [PATCH 4/6] option useMySQL in config.ini now can set MySQL support in config.ini useMySQL = (0|1) --- README.md | 7 ++++-- boswatch.py | 61 ++++++++++++++++++++++++++++++----------------------- config.ini | 6 ++++-- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 0027cbd..fe3789d 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,11 @@ Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG ### Configuration ##### boswatch.py -To use the boswatch.py script, you must edit the "config.ini". -Now you must set the Userdata to your local MySQL Database. +You can set the ignore time for double alarms in seconds. + +To use the script with MySQL Support, you must edit the "config.ini". +Now set "useMySQL = 1" and the Userdata to your local MySQL Database. + For the other Functions see "Usage" below. ##### Web Frontend diff --git a/boswatch.py b/boswatch.py index 9550802..151d554 100644 --- a/boswatch.py +++ b/boswatch.py @@ -25,8 +25,9 @@ def curtime(format="%Y-%m-%d %H:%M:%S"): def stop_script(err): print "ERR: "+err try: - if args.verbose: print "disconnect MySQL" - connection.close() + if useMySQL: #only if MySQL is active + if args.verbose: print "disconnect MySQL" + connection.close() rtl_fm.terminate() if args.verbose: print "rtl_fm terminated" multimon_ng.terminate() @@ -103,27 +104,33 @@ try: config.read("./config.ini") fms_double_ignore_time = int(config.get("FMS", "double_ignore_time")) zvei_double_ignore_time = int(config.get("ZVEI", "double_ignore_time")) + + #MySQL config + useMySQL = int(config.get("MySQL", "useMySQL")) #use MySQL support? + if useMySQL: #only if MySQL is active + dbserver = config.get("MySQL", "dbserver") + dbuser = config.get("MySQL", "dbuser") + dbpassword = config.get("MySQL", "dbpassword") + database = config.get("MySQL", "database") + + #MySQL tables + tableFMS = config.get("MySQL", "tableFMS") + tableZVEI = config.get("MySQL", "tableZVEI") + tablePOC = config.get("MySQL", "tablePOC") except: stop_script("config reading error") exit(0) - dbserver = config.get("MySQL", "dbserver") - dbuser = config.get("MySQL", "dbuser") - dbpassword = config.get("MySQL", "dbpassword") - database = config.get("MySQL", "database") - - tableFMS = config.get("MySQL", "tableFMS") - tableZVEI = config.get("MySQL", "tableZVEI") - tablePOC = config.get("MySQL", "tablePOC") - - if args.verbose: print "connect to MySQL database" - try: - connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) - except: - print "MySQL connect error" - exit(0) + if useMySQL: #only if MySQL is active + if args.verbose: print "connect to MySQL database" + try: + connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) + except: + print "MySQL connect error" + exit(0) + #variables pre-load if args.verbose: print "pre-load variables" fms_id = 0 fms_id_old = 0 @@ -191,11 +198,12 @@ try: print curtime("%H:%M:%S")+" BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi fms_id_old = fms_id #save last id fms_time_old = timestamp #save last time - - 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() + + if useMySQL: #only if MySQL is active + 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() elif args.verbose: #crc error only in verbose mode print "CRC error" @@ -217,10 +225,11 @@ try: zvei_id_old = zvei_id #save last id zvei_time_old = timestamp #save last time - cursor = connection.cursor() - cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) - cursor.close() - connection.commit() + if useMySQL: #only if MySQL is active + cursor = connection.cursor() + cursor.execute("INSERT INTO "+tableZVEI+" (time,zvei) VALUES (%s,%s)",(curtime(),zvei_id)) + cursor.close() + connection.commit() elif args.verbose: #Invalid error only in verbose mode print "No valid ZVEI: "+decoded diff --git a/config.ini b/config.ini index fd273f9..9cf5251 100644 --- a/config.ini +++ b/config.ini @@ -3,7 +3,9 @@ ######################## #Data for MySQL connection +#useMySQL = (0|1) [MySQL] +useMySQL = 0 dbserver = localhost dbuser = root dbpassword = root @@ -15,8 +17,8 @@ tablePOC = bos_pocsag [FMS] #time to ignore same alarm in a row in seconds -double_ignore_time = 5 +double_ignore_time = 10 [ZVEI] #time to ignore same alarm in a row in seconds -double_ignore_time = 10 \ No newline at end of file +double_ignore_time = 5 \ No newline at end of file From 0ed0bd98ebd19771c69913de0e03ed7be1c73706 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 22:38:53 +0200 Subject: [PATCH 5/6] FMS and ZVEI validation insert FMS validation edit ZVEI validation --- README.md | 5 +++-- boswatch.py | 50 +++++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index fe3789d..4a1d8e2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG #####Implementeted Features: - FMS and ZVEI decoding and Displaying - Filtering double alarms with adjustable time -- ZVEI validation (plausibility test) +- FMS and ZVEI validation (plausibility test) - MySQL Database Support for FMS and ZVEI - All configurations in seperate File "config.ini" - simple Web Frontend @@ -51,7 +51,8 @@ optional arguments: Device you want to use (Check with rtl_test) -e ERROR, --error ERROR Frequency-Error of your Device in PPM - -a {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...], --demod {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...] + -a {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...], + --demod {FMS,ZVEI,POC512,POC1200,POC2400} [{FMS,ZVEI,POC512,POC1200,POC2400} ...] Demodulation Functions -s SQUELCH, --squelch SQUELCH Level of Squelch diff --git a/boswatch.py b/boswatch.py index 151d554..92f6393 100644 --- a/boswatch.py +++ b/boswatch.py @@ -23,6 +23,7 @@ def curtime(format="%Y-%m-%d %H:%M:%S"): return time.strftime(format) def stop_script(err): + print "" print "ERR: "+err try: if useMySQL: #only if MySQL is active @@ -165,7 +166,8 @@ try: exit(0) - if args.verbose: print "start decoding" + if args.verbose: print "start decoding" + print "" while True: #RAW Data from Multimon-NG #ZVEI2: 25832 @@ -178,6 +180,7 @@ try: #if args.verbose: print "RAW: "+decoded #for verbose mode, print Raw input data #FMS Decoder Section + #check FMS: -> check CRC -> validate -> check double alarm -> print -> (MySQL) if "FMS:" in decoded: if args.verbose: print "recived FMS" @@ -189,34 +192,35 @@ try: fms_direction = decoded[101] #Richtung fms_tsi = decoded[114:117] #Taktische Kruzinformation - if "CRC correct" in decoded: #check CRC is correct + if "CRC correct" in decoded: #check CRC is correct fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id - if fms_id == fms_id_old and timestamp < fms_time_old + fms_double_ignore_time: #check for double alarm - if args.verbose: print "FMS double alarm: "+fms_id_old - fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new - else: - print curtime("%H:%M:%S")+" BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi - fms_id_old = fms_id #save last id - fms_time_old = timestamp #save last time - - if useMySQL: #only if MySQL is active - 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() - + if re.search("[0-9]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid + if fms_id == fms_id_old and timestamp < fms_time_old + fms_double_ignore_time: #check for double alarm + if args.verbose: print "FMS double alarm: "+fms_id_old + fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new + else: + print curtime("%H:%M:%S")+" BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi + fms_id_old = fms_id #save last id + fms_time_old = timestamp #save last time + + if useMySQL: #only if MySQL is active + 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() + elif args.verbose: #Invalid error only in verbose mode + print "No valid FMS: "+fms_id elif args.verbose: #crc error only in verbose mode - print "CRC error" + print "CRC incorrect" - #ZVEI Decoder Section + #ZVEI Decoder Section + #check ZVEI: -> validate -> check double alarm -> print -> (MySQL) if "ZVEI2:" in decoded: if args.verbose: print "recived ZVEI" - #ZVEI RegEX Pattern: http://www.regexr.com/3ao2u - zvei = re.search("[0-9F]{5}", decoded) - if zvei: #if ZVEI is valid - zvei_id = zvei.group() #save ZVEI in working var + zvei_id = decoded[7:12] #ZVEI Code + if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid if zvei_id == zvei_id_old and timestamp < zvei_time_old + zvei_double_ignore_time: #check for double alarm if args.verbose: print "ZVEI double alarm: "+zvei_id_old zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new @@ -232,7 +236,7 @@ try: connection.commit() elif args.verbose: #Invalid error only in verbose mode - print "No valid ZVEI: "+decoded + print "No valid ZVEI: "+zvei_id except KeyboardInterrupt: From 9e2922f9dc1668ab6d86fad5e34cacede2416092 Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Fri, 3 Apr 2015 22:46:30 +0200 Subject: [PATCH 6/6] edit README.md --- README.md | 5 ++++- boswatch.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a1d8e2..c82c505 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # BOSWatch -Python Script to Recive and Decode BOS Information with rtl_fm ans multimon-NG +Python Script to Recive and Decode German BOS Information with rtl_fm ans multimon-NG ### Features #####Implementeted Features: @@ -60,3 +60,6 @@ optional arguments: More Options you can find in the extern config.ini File in this Folder ``` + +Thanks to smith_fms and McBo from [Funkmeldesystem.de - Forum](http://www.funkmeldesystem.de/) for Inspiration and Groundwork! +Greetz Schrolli \ No newline at end of file diff --git a/boswatch.py b/boswatch.py index 92f6393..91ccf77 100644 --- a/boswatch.py +++ b/boswatch.py @@ -40,7 +40,7 @@ def stop_script(err): #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 BOS Information with rtl_fm and multimon-NG", epilog="More Options you can find in the extern config.ini File in this Folder") +parser = argparse.ArgumentParser(prog="boswatch.py", description="BOSWatch is a Python Script to Recive and Decode German BOS Information with rtl_fm ans 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)