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

aprsnotify.py unable to pull latest message from multiple SSIDs #3

Closed KN4KNG closed 3 years ago

KN4KNG commented 3 years ago

As per issue #2 aprsnotify.py is only able to pull messages from one SSID.

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"}]}
KN4KNG commented 3 years ago

Clarification, can pull different SSIDs as in KN4KNG, KI4SHC per below example. Just not able to pull from multiple SSIDs with numerical suffix ie: KN4KNG-1 & KN4KNG-14.

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': 'KI4SHC,KN4KNG', 'apikey': '<KEY>', 'format': 'json'}
msgs = requests.get(url, params=msgspayload)
print(msgs.text)

Output:

pi@raspberrypi:~ $ ./reqtest.py
{"command":"get","result":"ok","what":"loc","found":1,"entries":[{"class":"a","name":"KN4KNG-14","type":"l","time":"1607538117","lasttime":"1607543517","lat":"36.42617","lng":"-78.47717","course":77,"speed":0,"symbol":"\/$","srccall":"KN4KNG-14","dstcall":"","comment":"A=440APRSpro for iPhone 3.28V@34% hE<28m Oxford","path":"TCPIP*,qAC,KN4KNG-14"}]}
{"command":"get","result":"ok","found":2,"what":"msg","entries":[{"messageid":"59836188","time":"1607544652","srccall":"KN4KNG","dst":"KI4SHC","message":"Testing APRS Msg while debugging APRS Telegram Bot"},{"messageid":"59834273","time":"1607533391","srccall":"KN4KNG","dst":"KN4KNG","message":"Testing APRS"}]}
n8acl commented 3 years ago

Finally had a chance to dig myself and found our problem. I tried it a couple of times with my own callsign and finally started looking back at the API's website. Turns out it's a limitation of the API. According to the website, you are only able to pull messages for 10 destination callsigns and locations for 20 with the aprs.fi API. Anymore and the API bombs out. It looks like you are trying to pull 15 for messaging. It works fine for location packets, but you are over the limit for messages.... So first I am so sorry you spent all that time troubleshooting only for us to find that out.

I never gave a thought to a limit on the API for the number of callsigns because when I designed this, I designed it for me and only have ever had like 3 or 4 callsigns to monitor. I just assumed that most would have the same number or less when I gave this to the world. You are certainly a fringe case ;). Never crossed my mind to look back at the API when it stopped working for you. I only thought of it when I went looking to see if there was an update to it. That's when I found the notes on the limitations.

There are two ways to fix this for now: drop below the 10 callsign limit for messaging in your callsign list or turn off messaging till I can put out a patch.

For now, I will have to put a fix in force a 10 callsign limit for messaging and 20 limit for locations based on the length of the callsign array. The downside is it will require a prioritization by the user to make sure they put the 10 callsigns in the first half of the list that they want to monitor for messages.

I will also update the Readme to bring that information to the attention of people.

The reason I said for now is this will probably prompt me to look at another method to pull the information. There are a couple of libraries I have been playing with for other applications that I will have to see if I can make them fit this.

KN4KNG commented 3 years ago

Yep, I can confirm that now, thanks!

Perhaps a for i in callsign_list to loop through the callsign list for both location and data which would remove prioritizations.

I was just using 15 for the 15 possible suggested SSIDs by APRS, using the shorten list to 2 or 3 works for me.

I think if a for loop may make it universal to receive any new update for all monitored SSIDs would be cool, but I guess you would need to set a last know msg/loc text file for each. I'm just a self taught 'pythonist' so that may be harder than I think, just thinking aloud.

n8acl commented 3 years ago

I just pushed a patch to fix the API limitations problem. I have split the callsign list into 2 lists, pos_callsign_list for the position array and msg_callsign_list for the messages array. The aprsnotify script only pulls the first 20 in the pos callsign list and the first 10 in the msg callsign list. This makes setting things up alittle easier.

There are some changes to the config file, namely the two new lists, so you can reference the configuration.md file for the two new lists or use setup.py to rebuild the config file and you can just copy the API keys in....

I am looking at other ways to pull the information, but the easiest way at this point is to use the aprs.fi api. I will keep looking, but this is at least a way to handle it for now.

I thought about a for loop like you suggested, but hitting the api that many times will give them heart burn. building one URL and sending it makes them feel much better and keeps them from blocking the aprsnotify app and sending me nasty grams.

Thanks for helping with the troubleshooting.

I'm going to close this issue for now and keep the "API change" thing on my radar while i work on other things and maybe find a good way down the road....

n8acl commented 3 years ago

BTW If you are feeling froggy and do find a way to pull the information, please by all means submit a PR. I am happy to review it and see about getting it merged...