-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (69 loc) · 3.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#PersonalAPRSServer
import aprslib
from random import randint
from datetime import datetime
startTime = datetime.now()
from hamcall import callsign_start as callinfo
from aprsc import aprscrafter
aprsc = aprscrafter()
import requests
import configparser
config = configparser.ConfigParser()
config.read('conf.ini')
mycall = config['user']['mycall']
myphone = config['user']['myphone']
mysmskey = config['user']['mysmskey']
menuenabled = config['features']['menu']
menutext = config['features']['menutext']
aboutenabled = config['features']['about']
abouttext = config['features']['abouttext']
uptimeenabled = config['features']['uptime']
callenabled = config['features']['call']
def app():
try:
AIS = aprslib.IS(mycall, aprslib.passcode(mycall), port=14580)
AIS.connect()
AIS.sendall(aprsc.status(mycall, 'Starting Personal Mailbox APRS Service - Beta '))
def callback(packet):
parsed = aprsc.parsemsg(packet)##Parsed array is fromcall, tocall, message, ack, timestamp or location
print(packet)
print(parsed)
rxcall = parsed[0]
rxmsg = parsed[2]
rxack = parsed[3]
##HANDLES ACK
ack = '{' + str(randint(1,999))
if 'TCP' in rxack:##If TCP* in ACK field we ignore and dont send an ack response
pass
else:
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message='ack' + rxack))###Send ACK
##END ACK HANDLING
rxmsg = str(rxmsg).lower()
if 'menu' in rxmsg and menuenabled == 'on':
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message=menutext + ack))
if 'about' in rxmsg and aboutenabled == 'on':
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message=abouttext + ack))
if 'uptime' in rxmsg and uptimeenabled == 'on':
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message=str(datetime.now() - startTime) + ack))
if 'call' in rxmsg and callenabled == 'on':
try:
callreq = rxmsg.split( )[1]
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message=callinfo(callreq) + ack))
except:
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message='MSG Format: CALL callsign' + ack))#if all else fails, send ack lol
if 'sms' in rxmsg:
try:
smsmsg = rxmsg
resp = requests.post('https://textbelt.com/text', {
'phone': myphone,
'message': rxcall + ' ' + smsmsg,
'key': mysmskey,
})
print(resp.json())
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message='Sending your message to ' + mycall + ack))
except:
AIS.sendall(aprsc.msg(fromcall=mycall, tocall=rxcall, message='MSG Format: SMS your_message_here' + ack))#if all else fails, send ack lol
AIS.consumer(callback, raw=True)
except:
app()
app()