n8acl / aprsnotify

APRS Notification bot for various Social Media Networks
https://n8acl.github.io/aprsnotify
GNU General Public License v3.0
14 stars 2 forks source link

Line 251 in aprsnotify.py seems to be not needed. #2

Closed KN4KNG closed 3 years ago

KN4KNG commented 3 years ago

aprsnotify.py successfully sends latest data and msgs, but errors out at the end.

Traceback (most recent call last): File "aprsnotify.py", line 251, in chks["lastmsgid"] = lastmsgid NameError: name 'lastmsgid' is not defined

It appears the lastmsgid is defined and used outside of conditional statement and not needed in this section. commenting out solves the error. Not sure if something past this point is needed or not.

    if gooddata == 1: # If we have good msg data
        # create msg status and send to Telegram
        msg_status = srccall + " sent you the following message on APRS: " + msg
        tele_bot_message(msg_status)

#        chks["lastmsgid"] = lastmsgid
n8acl commented 3 years ago

It actually is needed and is part of the conditional (based on indenting). Otherwise it will continue to send the last and all messages to your telegram. It should store the message id to the locdtstamp.txt file so it can reference what the last message sent was. It is defined earlier in the program checking for the locdtstamp.txt file, which if it doesn't exist, should create it:

if not os.path.exists(locdtstampfile): with open(locdtstampfile,"wb") as f: chks = {"lasttime":"1","lastmsgid":"1"} pickle.dump(chks,f) f.close()

and then is brought in with

with open(locdtstampfile,"rb") as f: chks = pickle.load(f) f.close()

Then if it finds a message, it should store the message id back to that variable to be pushed out the locdtstamp.txt file to reference for the next run.

Uncomment that line and try deleting your locdtstamp.txt file and let the app recreate it. It may have not created it right....

KN4KNG commented 3 years ago

I re-cloned the repository just to make sure none of my edits were causing errors, and same issue. I am getting msg: 'N0CALL sent you the following message on APRS: No Message' in telegram even after sending test msgs. Im subscribed to KN4KNG-1 through KN4KNG-15 SSIDs

log from APRS.fi showing successful msgs:

2020-12-09 11:44:29 EST: KN4KNG>KN4KNG-14: Testing APRS
2020-12-09 12:03:11 EST: KN4KNG>KN4KNG: Testing APRS

Perhaps there is a greater issue.

FYI: After re-cloning to make sure my edits were removed, and removing locdtsampfile error perrsists.

Traceback (most recent call last):
  File "aprsnotify.py", line 251, in <module>
    chks["lastmsgid"] = lastmsgid
NameError: name 'lastmsgid' is not defined

I appreciated how quick you've responded. I'll continue to see if I can find a solution too. Thank you n8acl

n8acl commented 3 years ago

Interesting... I just started getting the nocall error the other day too, but I haven't had a chance to dig in to see why i started. For me usually deleting and letting it recreate locdtstamp.txt fixed it for me in the past. I hate using pickle and saving to a txt file since there are so many things that can go wrong, but I have not found a better way to persist data without a database in python. I am sure there is, I just haven't found it yet.

When I have a few moments, I will dig in and see if the api made a change....

Just curious, what version of Python are you using? Is this a Linux/Windows/Mac machine?

KN4KNG commented 3 years ago

I am using a raspberry pi 4 on the latest buster lite:

pi@raspberrypi:~ $ python3 --version
Python 3.7.3
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

I'll see if printing pickle output to locdtstampfile.txt is possible and if it fixes the issues.

n8acl commented 3 years ago

Yeah that is what I am on... Exactly what I am using in fact.... Ugh... ok.... I will dig through and see what I can find too.. Thanks for the heads up!

KN4KNG commented 3 years ago

So there is a slight issue with the api causing msg issues. But even when fixing it, aprsnotify.py send the N0CALL Msg.

The msg function seems to only work with one SSID. To test I sent a message to KN4KNG-14 and created another file reqtest.py:

#!/usr/bin/python3
import requests
url = 'https://api.aprs.fi/api/get'
locpayload = {'name': 'KN4KNG-1,KN4KNG-2,KN4KNG-3,KN4KNG-4,KN4KNG-5,KN4KNG-6,KN4KNG-7,KN4KNG-8,KN4KNG-9,KN4KNG-10,KN4KNG-11,KN4KNG-12,KN4KNG-13,KN4KNG-14,KN4KNG-15', 'what': 'loc', 'apikey': '<KEY>', 'format': 'json'}
loc = requests.get(url, params=locpayload)
print(loc.text)
msgspayload = {'what': 'msg', 'dst': 'KN4KNG-1,KN4KNG-2,KN4KNG-3,KN4KNG-4,KN4KNG-5,KN4KNG-6,KN4KNG-7,KN4KNG-8,KN4KNG-9,KN4KNG-10,KN4KNG-11,KN4KNG-12,KN4KNG-13,KN4KNG-14,KN4KNG-15', 'apikey': '<KEY>', 'format': 'json'}
msgs = requests.get(url, params=msgspayload)
print(msgs.text)

and I get the following output:

pi@raspberrypi:~ $ ./reqtest.py
{"command":"get","result":"ok","what":"loc","found":1,"entries":[{"class":"a","name":"KN4KNG-14","type":"l","time":"1607538117","lasttime":"1607538117","lat":"36.42617","lng":"-78.47717","course":13,"speed":0,"symbol":"\/$","srccall":"KN4KNG-14","dstcall":"","comment":"A=449APRSpro for iPhone 3.29V@48% hE<14m Oxford","path":"TCPIP*,qAC,KN4KNG-14"}]}
{"command":"get","result":"ok","found":0,"what":"msg","entries":[]}

I then sent a msg to both KN4KNG-14 & KN4KNG-1 and changed SSID Order to KN4KNG-14 in place of KN4KNG-1:

#!/usr/bin/python3
import requests
url = 'https://api.aprs.fi/api/get'
locpayload = {'name': 'KN4KNG-1,KN4KNG-2,KN4KNG-3,KN4KNG-4,KN4KNG-5,KN4KNG-6,KN4KNG-7,KN4KNG-8,KN4KNG-9,KN4KNG-10,KN4KNG-11,KN4KNG-12,KN4KNG-13,KN4KNG-14,KN4KNG-15', 'what': 'loc', 'apikey': '<KEY>', 'format': 'json'}
loc = requests.get(url, params=locpayload)
print(loc.text)
msgspayload = {'what': 'msg', 'dst': 'KN4KNG-14,KN4KNG-2,KN4KNG-3,KN4KNG-4,KN4KNG-5,KN4KNG-6,KN4KNG-7,KN4KNG-8,KN4KNG-9,KN4KNG-10,KN4KNG-11,KN4KNG-12,KN4KNG-13,KN4KNG-1,KN4KNG-15', 'apikey': '<KEY>', 'format': 'json'}
msgs = requests.get(url, params=msgspayload)
print(msgs.text)

and I get the following output:

pi@raspberrypi:~ $ ./reqtest.py
{"command":"get","result":"ok","what":"loc","found":1,"entries":[{"class":"a","name":"KN4KNG-14","type":"l","time":"1607538117","lasttime":"1607538117","lat":"36.42617","lng":"-78.47717","course":13,"speed":0,"symbol":"\/$","srccall":"KN4KNG-14","dstcall":"","comment":"A=449APRSpro for iPhone 3.29V@48% hE<14m Oxford","path":"TCPIP*,qAC,KN4KNG-14"}]}
{"command":"get","result":"ok","found":1,"what":"msg","entries":[{"messageid":"59834024","time":"1607532269","srccall":"KN4KNG","dst":"KN4KNG-14","message":"Testing APRS"}]}

So we now have some more understanding into api issues but not completely resolved as even with KN4KNG-14 as the only SSID in config I receive the same error.

n8acl commented 3 years ago

OK. That makes sense. I will look at changing the way I am pulling from the api then. It's supposed to pull messages for all the ssids and then find the most recent one (which is why I store the lastmsgid) and send that. They may have changed how it displays from when I wrote that. Let me dig into it tonight and see what i can come up with. If you disable messaging in the config file (set enable_aprs_msg_notify = 0) that will ignore the messaging for now till I can get that fixed.

Thanks for the help!

KN4KNG commented 3 years ago

Disregard the last message on the fact that the aprsnotify.py doesn't get the msg with even one SSID, I was editing the wrong config.py to one SSID. So setting only one SSID to monitor is the config works! No errors!

The issue with the config file is bc I have a script that I use to just refresh everything from git and copying config files. here the script file, which is helpful for me to troubleshoot.

update_aprsnotify.sh

#!/bin/bash
sudo cp $HOME/aprsnotify/config.py $HOME/config.py
sudo rm -rf aprsnotify
git clone https://github.com/n8acl/aprsnotify.git
sudo cp $HOME/config.py aprsnotify/config.py
KN4KNG commented 3 years ago

Closing the issue and creating specific request for API support for better tracking. I'll let you know if I find a way to pull multiple SSIDs, which should work if we can pull multi SSIDs combine all the second lines and pull the highest time value.

I love this project, thanks for all of your help.

73 de KN4KNG

n8acl commented 3 years ago

ok cool! But that is still a problem LOL.. At one point i was able to pull multiple ssids with one URL. I will look on my end and see what I can do too. Thanks for looking into it.. While I can respond while working from home sometimes I can't dive in till after work.

Glad you like it. Once we get that part fixed, spread the word :)