EliasOenal / multimon-ng

GNU General Public License v2.0
923 stars 206 forks source link

Stops recieving #173

Closed paulvanderheijden90 closed 3 months ago

paulvanderheijden90 commented 3 years ago

Hello, i use a Raspberry PI4 with a RTL Sdr Antenna to collect the P2000 messages. The code i use is 50/50 copy past and self made.

The idee is that wenn a message on a certain Capcode comes in it send it tru to a MQTT broker. This can run for monts without any problem. But after some time it is not reciving mesages.

Pi still function and code is running but no output of the multimong. Can anyone help to find the problem ?

import time import sys import subprocess import os import re import paho.mqtt.publish as publish from RID_MWB_V1_2 import replace from datetime import datetime from dateutil import tz from termcolor import colored

INIT

MQTT_SERVER = "10.0.184.44" groupidold = "" #########################################################################################

05-05-2020

P2000 to MQTT voor thuis. NAV nieuwe Revolution Core. Nieuwe Multimon output.

Deze versie heeft 1 flex string met variable lengte. En meerdere capcodes

#########################################################################################

Declaratie zoektermen

capcode_Steenbergen_homealarm= "001201999"

capcode_Steenbergen_lichtkrant= "001201972" capcode_NVM_lichtkrant= "001201954" capcode_Steenbergen_homealarm= "001200768" capcode_Steenbergen_proefalarm= "001201998" capcode_MWB_Ambu= ["001220499"] capcode_MWB_Brw= ["001201999"] capcode_MWB_Pol= ["001230999"] Steenbergen="Steenbergen NB" OPS_Middel="MIDDEL" capcode_MWB_STB= ["001220499","001201999","001230266"]

Definitie voor de tijd.

def curtime(): return time.strftime("%H:%M:%S %Y-%m-%d") with open('error.txt','a') as file: file.write(('#' * 20) + '\n' + curtime() + '\n')

KLADBLOK

#Topics
#  V P2000/mwb/brw
#  V P2000/mwb/pol
#  V P2000/mwb/amb
#  V P2000/mwb/stb
#  V P2000/mwb/lichtkrant
#  V P2000/mwb/homealarm
#  V P2000/mwb/mid
#and (melding.__contains__("A1"))

Call Multimon:

multimon_ng = subprocess.Popen("rtl_fm -f 169.65M -M fm -s 22050 -p 43 | multimon-ng -a FLEX -t raw -", stdout=subprocess.PIPE, stderr=open('error.txt','a'), shell=True) time.sleep(15) publish.single('P2000/mwb/startup', "Multimon is gestart Script loopt" , hostname=MQTT_SERVER) time.sleep(1)

publish.single('P2000/mwb/amb', "Ambu P2000 systeem Check" , hostname=MQTT_SERVER)

time.sleep(1)

publish.single('P2000/mwb/pol', "Politie P2000 systeem Check" , hostname=MQTT_SERVER)

time.sleep(1)

publish.single('P2000/mwb/brw', "Brandweer P2000 systeem Check" , hostname=MQTT_SERVER)

time.sleep(1)

publish.single('P2000/mwb/stb', "Steenbergen P2000 systeem Check" , hostname=MQTT_SERVER)

time.sleep(1)

publish.single('P2000/mwb/nieuwvossemeer',"nieuwvossemeer P2000 systeem Check" , hostname=MQTT_SERVER)

time.sleep(1)

sys.stdout.write("Code Draait\n")

Code:

try: while True: line = multimon_ng.stdout.readline()

line = "FLEX: 2017-07-10 07:45:34 1600/2/A 11.059 [001201999] ALN P 1 BR GEBOUW Warwickstraat Steenbergen NB 201634 (inci-02)"

    multimon_ng.poll()
    if line.__contains__("ALN"):
    if line.startswith('FLEX'):
        posiALN=(line.find("|ALN|"))
        len_line=len(line)
        flex = line[0:4]
        timestamp = line[5:24]
        melding = line[posiALN+5:len_line]
        meldingp1 = line[posiALN+8:len_line]
        groupid = line[36:43]
        capcode = line[43:posiALN]
        prio    = line[posiALN+5:posiALN+8]
        #print(line)

    if melding.__contains__("TESTOPROEP HOOFDSYSTEEM MKOB DEN BOSCH"):
        publish.single('P2000/mwb/startup', "handshake" , hostname=MQTT_SERVER)
        print("handshake   " + timestamp)

    if capcode_Steenbergen_homealarm in (str(capcode)):
        print("Uitruk STB " + curtime()+melding+groupid+' '),
                publish.single('P2000/mwb/spraak', replace(meldingp1) , hostname=MQTT_SERVER),
        if prio.__contains__('1') :
                    publish.single('P2000/mwb/homealarm', "alert1" , hostname=MQTT_SERVER),
                else:
                    publish.single('P2000/mwb/homealarm', "alert2" , hostname=MQTT_SERVER),

            if capcode_NVM_lichtkrant in (str(capcode)): 
        print("Uitruk NVM " + curtime()+melding+groupid+' '), 
            publish.single('P2000/mwb/nieuwvossemeer',melding , hostname=MQTT_SERVER), 

            if capcode_Steenbergen_proefalarm in (str(capcode)):
                print("Proefalarm MWB: " + curtime()+melding+groupid+' '),
                publish.single('P2000/mwb/spraak', melding , hostname=MQTT_SERVER), 

    if capcode_Steenbergen_lichtkrant in (str(capcode)): 
        print("Uitruk STB " + curtime()+melding+groupid+' '), 
        publish.single('P2000/mwb/lichtkrant',melding , hostname=MQTT_SERVER), 

        #Alarm voor Ambulance, Brandweer of Politie
            if (any(b in capcode for b in capcode_MWB_Ambu))and (melding.__contains__("A1")):
                publish.single('P2000/mwb/amb', melding + " - "+curtime(), hostname=MQTT_SERVER),
                print(curtime()+" - Ambulance: "  + melding),

            if (any(c in capcode for c in capcode_MWB_Brw)):
                publish.single('P2000/mwb/brw', replace(melding) + " - "+curtime(), hostname=MQTT_SERVER),
                print(curtime()+" - Brandweer: " + melding),

            if (any(d in capcode for d in capcode_MWB_Pol)):
                publish.single('P2000/mwb/pol', melding + " - "+curtime(), hostname=MQTT_SERVER),
                print(curtime()+" - Politie: " + melding),

    if groupid == groupidold:

        #print colored(capcode, 'red'),
                temp=33

    else:
                    #Alarm met de text "steenbergen"
                    if melding.__contains__(Steenbergen) :
                        publish.single('P2000/mwb/stb', melding+" - "+curtime(), hostname=MQTT_SERVER),
                        print colored("Steenbergen: "+melding , 'red',  attrs=['bold']),

                    #Alarm dat word gekwalificeerd als "Middel"
                    if (any(ca in capcode for ca in capcode_MWB_Brw)) and (melding.__contains__("MIDDEL")):
                        publish.single('P2000/mwb/mid', melding+" "+curtime(), hostname=MQTT_SERVER),
                        print("Ops: Middel: "+curtime()+melding),

                #Orginal
        #utc = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        #utc = utc.replace(tzinfo=tz.tzutc())
        #local = utc.astimezone(tz.tzlocal())
        #local = local.strftime("%d-%m-%Y %H:%M:%S")
                    #lcd.clear()
                    #lcd.goto(0,0)
                    #lcd.write(datetime.now().strftime('%b %d  %H:%M:%S\n'))
                    #lcd.goto(0,1)
                    #lcd.write(capcode)

        #print '     '
        #print colored(datetime.now().strftime('%H:%M:%S\n')+groupid,'blue', attrs=['bold']), colored(prio, 'blue'), colored(melding, 'white',  attrs=['bold']),
        #print '                  ',
        #print colored(capcode, 'white'),

        groupidold = groupid

except KeyboardInterrupt: os.kill(multimon_ng.pid, 9)