Merge pull request #1 from Schrolli91/develop

Relase v0.2
This commit is contained in:
Schrolli91 2015-04-03 22:52:08 +02:00
commit 202af86baf
6 changed files with 247 additions and 60 deletions

View file

@ -1,19 +1,33 @@
# 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
### Fetaures
#####Actual implementet:
### Features
#####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
#####Fetaures for the Future:
#####Features for the Future:
- extensive filtering options
- POCSAG 512,1200,2400 support
- automatic Audio recording at alarm
- Web Frontend
- Web Frontend with configuration
### Configuration
##### boswatch.py
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
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`
@ -28,7 +42,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
@ -37,11 +51,15 @@ 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
-v, --verbose Shows more Information
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

View file

@ -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 #####
@ -23,10 +23,12 @@ def curtime(format="%Y-%m-%d %H:%M:%S"):
return time.strftime(format)
def stop_script(err):
print ""
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()
@ -38,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 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 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)
@ -103,27 +105,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
@ -158,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
@ -171,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"
@ -182,33 +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
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
@ -217,13 +229,14 @@ 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
print "No valid ZVEI: "+zvei_id
except KeyboardInterrupt:

72
boswatch.sql Normal file
View file

@ -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 */;

View file

@ -3,20 +3,22 @@
########################
#Data for MySQL connection
#useMySQL = (0|1)
[MySQL]
useMySQL = 0
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
double_ignore_time = 5
double_ignore_time = 10
[ZVEI]
#time to ignore same alarm in a row in seconds
double_ignore_time = 10
double_ignore_time = 5

12
www/config.php Normal file
View file

@ -0,0 +1,12 @@
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "root";
$database = "boswatch";
$tableFMS = "bos_fms";
$tableZVEI = "bos_zvei";
$tablePOC = "bos_pocsag";
?>

70
www/index.php Normal file
View file

@ -0,0 +1,70 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
require_once ("config.php");
$db_link = mysqli_connect ($dbhost, $dbuser, $dbpassword, $database);
?>
<html>
<head>
<title>BOSWatch</title>
</head>
<body>
<div style="text-align: center; width: 1050px; margin: 0px auto;">
<h1>BOSWatch</h1>
Last alarms for FMS and ZVEI (max. 50)<br><br>
<div style="float: left; width: 600px;">
<b>Last FMS alarms</b>
<?php
$sql = "SELECT id, time, service, country, location, vehicle, status, direction, tsi FROM ".$tableFMS." ORDER BY id DESC LIMIT 50";
$db_erg = mysqli_query( $db_link, $sql );
echo '<table border="1" style="width: 600px;">';
while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td>". $data['id'] . "</td>";
echo "<td>". $data['time'] . "</td>";
echo "<td>". $data['service'] . "</td>";
echo "<td>". $data['country'] . "</td>";
echo "<td>". $data['location'] . "</td>";
echo "<td>". $data['vehicle'] . "</td>";
echo "<td>". $data['status'] . "</td>";
echo "<td>". $data['direction'] . "</td>";
echo "<td>". $data['tsi'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</div>
<div style="float: right; width: 400px;">
<b>Last ZVEI alarms</b>
<?php
$sql = "SELECT id, time, zvei FROM ".$tableZVEI." ORDER BY id DESC LIMIT 50";
$db_erg = mysqli_query( $db_link, $sql );
echo '<table border="1" style="width: 400px;">';
while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td>". $data['id'] . "</td>";
echo "<td>". $data['time'] . "</td>";
echo "<td>". $data['zvei'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</div>
</div>
</body>
</html>