many changes
This commit is contained in:
parent
5c975d58ea
commit
2dbc64739d
|
@ -1,10 +1,18 @@
|
||||||
from socketIO_client import SocketIO
|
from socketIO_client import SocketIO
|
||||||
import json
|
import json
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
import time
|
||||||
|
|
||||||
tg = [91, 98002]
|
|
||||||
min_duration = 2
|
|
||||||
id = ""
|
id = ""
|
||||||
|
last_activity = {}
|
||||||
|
|
||||||
|
|
||||||
|
# adapt the following variables to your needs
|
||||||
|
talkgroups = [91, 98002] # Talkgroups to monitor
|
||||||
|
#dmr_ids = [2637550]
|
||||||
|
callsigns = ["DL6MHC", "OE1MEW"]
|
||||||
|
min_duration = 2 # Min. duration of QSO to qualify for a push notification
|
||||||
|
min_silence = 300 # Min. time in seconds after the last QSO before a new push notification will be send.
|
||||||
|
|
||||||
def on_connect():
|
def on_connect():
|
||||||
print('connect')
|
print('connect')
|
||||||
|
@ -15,22 +23,42 @@ def on_disconnect():
|
||||||
def on_reconnect():
|
def on_reconnect():
|
||||||
print('reconnect')
|
print('reconnect')
|
||||||
|
|
||||||
def on_mqtt(*args):
|
def construct_message(c):
|
||||||
|
tg = c["DestinationID"]
|
||||||
out = ""
|
out = ""
|
||||||
|
duration = c["Stop"] - c["Start"]
|
||||||
|
#print(c["DestinationName"])
|
||||||
|
# convert unix time stamp to human readable format
|
||||||
|
time = dt.datetime.utcfromtimestamp(c["Start"]).strftime("%Y/%m/%d %H:%M")
|
||||||
|
# construct text message from various QSO properties
|
||||||
|
out += c["SourceCall"] + ' (' + c["SourceName"] + ') was active on '
|
||||||
|
out += str(tg) + ' (' + c["DestinationName"] + ') at '
|
||||||
|
out += time + ' (' + str(duration) + ' seconds)'
|
||||||
|
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
|
||||||
|
# remember ID to prevent doublets
|
||||||
|
#id = call["SessionID"]
|
||||||
|
#last_activity[tg] = call["Start"]
|
||||||
|
# finally print out the text message
|
||||||
|
print(out)
|
||||||
|
|
||||||
|
def on_mqtt(*args):
|
||||||
global id
|
global id
|
||||||
|
# get json data of QSO
|
||||||
call = json.loads(args[0]['payload'])
|
call = json.loads(args[0]['payload'])
|
||||||
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
|
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
|
||||||
#if call["DestinationID"] in tg and id != call["SessionID"]:
|
# check if talkgroup is one of those to be monitored, if QSO has already been
|
||||||
if call["DestinationID"] in tg and call["Stop"] > 0 and id != call["SessionID"]:
|
# ended and the same QSO has already been handled
|
||||||
|
tg = call["DestinationID"]
|
||||||
|
if call["SourceCall"] in callsigns:
|
||||||
|
construct_message(call)
|
||||||
|
elif tg in talkgroups and call["Stop"] > 0 and id != call["SessionID"] and (tg not in last_activity or (last_activity[tg] + min_silence) < call["Start"]):
|
||||||
|
# calculate duration of QSO
|
||||||
duration = call["Stop"] - call["Start"]
|
duration = call["Stop"] - call["Start"]
|
||||||
if duration > min_duration:
|
# only proceed if QSO has the configured min. duration
|
||||||
time = dt.datetime.utcfromtimestamp(call["Start"]).strftime("%Y/%m/%d %H:%M")
|
if duration >= min_duration:
|
||||||
out += call["SourceCall"] + ' (' + call["SourceName"] + ') was active on '
|
construct_message(call)
|
||||||
out += str(call["DestinationID"]) + ' (' + call["DestinationName"] + ') at '
|
|
||||||
out += time + ' (' + str(duration) + ' seconds)'
|
|
||||||
#print(json.dumps(call,separators=(',',':'),sort_keys=True,indent=4))
|
|
||||||
id = call["SessionID"]
|
id = call["SessionID"]
|
||||||
print(out)
|
last_activity[tg] = call["Start"]
|
||||||
|
|
||||||
socket = SocketIO('https://api.brandmeister.network/lh')
|
socket = SocketIO('https://api.brandmeister.network/lh')
|
||||||
socket.on('connect', on_connect)
|
socket.on('connect', on_connect)
|
||||||
|
|
Loading…
Reference in New Issue