dmitryelj / RPi-P2000Receiver

P2000 paging autonomous receiver with LCD and browser access
15 stars 7 forks source link

[SOLVED] Capcode filter names not showing with multiple capcodes #18

Closed M1K3-NL closed 3 years ago

M1K3-NL commented 3 years ago

I have added all the required capcodes to the capcodes.txt, but if there is more than one capcode in a message, it will not display them. I've tried everything, but it doesn't work.

So if you have one capcode with a message ex: 001100220 and you added this to the capcode file, it will show the name. ex: 001100220,TestCapcode Will show: TestCapcode (001100220) But ex: 001100220 002211550 won't show it. And the capcode 002029568 and 002029569 are GROUP IDs (https://monitor.p2000alarm.nl/capcode/2029568 and https://monitor.p2000alarm.nl/capcode/2029569) but they show as a normal capcode. Can I somehow filter these out?

Any idea of how this can work?

vncviewer_mArdj15eyi sublime_text_ig4vECEGvC notepad++_ZYBo3LEq0l opera_KPKn5MGG5r

M1K3-NL commented 3 years ago

Maybe any idea?

dmitryelj commented 3 years ago

I cannot reproduce it, I run the app now, and see many messages with multiple capcodes: image

If you can share your capcodes.txt file, I can check. Maybe it's not a plain text ansi file?

M1K3-NL commented 3 years ago

capcodes.txt

I don't know if you can download it, but here it is.

M1K3-NL commented 3 years ago

Maybe any idea also how to filter 002029568 and 002029569 out of the capcode part. That is: If a notification comes in with three capcodes, including 002029568 that it doesn't appear and only the other two do, because I don't need that group code and is only extra junk in the capcode list if it's on the index.html or on the print on the terminal.

dmitryelj commented 3 years ago

Your capcodes file works good, I did not find problems. If you can copy full FLEX message lines from the terminal that cause the error, I will check.

For the groups filtering, the easiest way without big program changes, is to add additional file for ignored capcodes. Add this code after "print("Capcodes: {} records loaded".format(len(capcodesDict)))" line:

pythoncapcodesIgnore = loadCapcodesDict(dir_path + os.sep + "capcodes_ignore.txt")
print("Capcodes ignore: {} records loaded".format(len(capcodesIgnore)))

Add this code after "if checkFilter(capcode) is False: continue" line:

if capcode in capcodesIgnore:
    print("Message {} to {} ignored".format(message, capcode))
    continue

Fill the file "capcodes_ignore.txt" using the same way. Then messages to selected groups will be always skipped (but it can cause a problem if the group is the only one receiver of the message).

M1K3-NL commented 3 years ago

FLEX|2020-10-16 19:42:08|1600/2/K/A|10.078|002029568 000220999 000220113 000126999|ALN|A2 10113 Rit 122274 Pontweg Den Burg

Will show as:

A2 10113 Rit 122274 Pontweg Den Burg

002029568 000220999 000220113 000126999

But 002029568 is added to the capcodes.txt, so that one should show a text instead of only capcodes, but it simply doesn't do it... 😒😕

And I want to filter 002029568 and 002029569 out, but I still want to receive the message but simple only with the capcodes behind it. But if that's not possible, then I will rename the capcode to something else.

Are you Dutch by any chance? So we can continue in Dutch 😅

dmitryelj commented 3 years ago

I see now, messages grouping is a new feature of the last multimon-ng. Install older version (I use 1.1.7), should be working fine. I will add this later, nobody asked before.

Ik ben geen nederlander, maar woon in Nederland ;)

M1K3-NL commented 3 years ago

Okay I will look into installing an older multimon later and inform you how it went 🙂🙂

M1K3-NL commented 3 years ago

Sadly it's crashing now since I downgraded Multimon. Screenshot_20201016_233333

M1K3-NL commented 3 years ago

Okay. The problem with the capcode has fixed with MNG 1.7. But now the issue I get: When the data is pushed to the index webpage, it will be combined, but I don't use that because I send everything to Telegram.

So what's happening now, is that the messages get duplicated with every capcode. vncviewer_FXraQPsFqT opera_81HU9c6Df1

And this is the way how I filter to get it to Telegram. So if the line contains a city name, it will Telegram it. sublime_text_qTSYFbdMRV

So or somehow I need to find out how to combine them between the part it strips the FLEX line and send it to Telegram or I need to find something how to filter it. Because I need both capcodes to be in one Telegram message.

So now it is:

P 1 BDH-02 OMS Geverifieerd (brandmelding OMS) Sticht. Constant Rebecqueplein De Constant Rebecqu SGRAVH 157830

Brandweer Haaglanden (Monitorcode) (001503902)
P 1 BDH-02 OMS Geverifieerd (brandmelding OMS) Sticht. Constant Rebecqueplein De Constant Rebecqu SGRAVH 157830

Brandweer Haaglanden Centrum (Kazernealarm) (001500142)

And it needs to become:

P 1 BDH-02 OMS Geverifieerd (brandmelding OMS) Sticht. Constant Rebecqueplein De Constant Rebecqu SGRAVH 157830

Brandweer Haaglanden (Monitorcode) (001503902)
Brandweer Haaglanden Centrum (Kazernealarm) (001500142)
dmitryelj commented 3 years ago

Hi,

I pushed a fix for multimon-ng 1.1.9 now, should be working.

About posting to the Telegram, you can append your code to the postToServer method, that was made especially to the posting to the 3rd party servers. No messages should be duplicated.

M1K3-NL commented 3 years ago

Hi, thanks for the update. The issue is I don't have any experience with the PostToServer method. I tried some things, but it didn't work. Because I don't have anything that could post the JSON info in a respectable way to Telegram. I don't work based on capcodes, I work based on city names:

sublime_text_timYpRfxdS

dmitryelj commented 3 years ago

It's not mandatory to use JSON, you can access all fields directly. I added now message_raw parameter to the MessageItem, that contains the original line from multimon-ng. You can use something like this in postToServer:

if "DELFT" in self.message_raw:
    requests.post(url + '<b>' + self.body + '</b>' + self.receivers + '</i>') 

PS: Instead of duplicating the lines "DELFT" and "Delft", it will be shorter for you to write:

if "delft" in self.message_raw.lower():
   ...

Then you don't need to parse twice different letter registers.

M1K3-NL commented 3 years ago

I did that because the normale FIRE and AMBU messages contained DELFT and the Lifeliner was just Delft. And if it was DELFT it didn't recognize Delft. That wasn't a big deal, because sometimes you have the "delftsestraat rotterdam" and I don't want that one, because it isn't Delft. So i'm still working a lot on it to make it better and better. I used to use Pagermon, but when a messages like 0000000000 00000000000 111111111111 0000000000000 came through it crashed xD

dmitryelj commented 3 years ago

Yes, that makes sense. You can take some ideas also from this thread: https://stackoverflow.com/questions/5319922/python-check-if-word-is-in-a-string

And maybe it's better to parse fields self.body and self.receivers separately, it will be more flexible.

M1K3-NL commented 3 years ago

I'll check that out, otherwise, I'll return back to the old way :-)

M1K3-NL commented 3 years ago

Hi man, I figured the part out and it's currently working like a charm! Thanks for your great assistance!

opera_bjmuL8h7U0 opera_dKGgCRwN9E

M1K3-NL commented 3 years ago

Only sadly the date is UTC due to shitty MultimonNG and not dutch time.

dmitryelj commented 3 years ago

Good to know that it works 👍 I closing this issue now.

You can remove the line 658 "msg.timestamp = timestamp", then local Raspberry Pi timestamp will be used in MessageItem.