initial steps to use multiple devices

This commit is contained in:
Eric D. Brown 2021-03-27 11:27:57 -06:00
parent 8874e8ecf0
commit 096be98019
2 changed files with 65 additions and 37 deletions

View file

@ -40,44 +40,53 @@ try:
except: except:
sys.exit("Can't read configuration file: " + cf) sys.exit("Can't read configuration file: " + cf)
#### TODO: EDB - add ability to use multiple inreach devices on command line
# #Command-line options
# op = OptionParser()
#Command-line options # op.add_option("-s","--ssid",action="store",type="string",dest="ssid",help="APRS SSID")
op = OptionParser() # op.add_option("-p","--pass",action="store",type="int",dest="passwd",help="APRS-IS password")
# op.add_option("-P","--port",action="store",type="int",dest="port",help="APRS-IS port")
# op.add_option("-u","--user",action="store",type="string",dest="user",help="inReach username")
# op.add_option("-i","--irpass",action="store",type="string",dest="irpass",help="inReach feed password")
# op.add_option("-U","--url",action="store",type="string",dest="url",help="URL for KML feed")
# op.add_option("-c","--comment",action="store",type="string",dest="comment",help="APRS-IS location beacon comment text")
# op.add_option("-d","--delay",action="store",type="int",dest="delay",help="Delay between polls of KML feed")
# (opts,args) = op.parse_args()
op.add_option("-s","--ssid",action="store",type="string",dest="ssid",help="APRS SSID") # #Allow command-line arguments to override the config file.
op.add_option("-p","--pass",action="store",type="int",dest="passwd",help="APRS-IS password") # if opts.ssid:
op.add_option("-P","--port",action="store",type="int",dest="port",help="APRS-IS port") # conf['APRS']['SSID'] = opts.ssid
op.add_option("-u","--user",action="store",type="string",dest="user",help="inReach username") # if opts.passwd:
op.add_option("-i","--irpass",action="store",type="string",dest="irpass",help="inReach feed password") # conf['APRS']['Password'] = str(opts.passwd)
op.add_option("-U","--url",action="store",type="string",dest="url",help="URL for KML feed") # if opts.port:
op.add_option("-c","--comment",action="store",type="string",dest="comment",help="APRS-IS location beacon comment text") # conf['APRS']['Port'] = str(opts.port)
op.add_option("-d","--delay",action="store",type="int",dest="delay",help="Delay between polls of KML feed") # if opts.user:
(opts,args) = op.parse_args() # conf['inReach']['User'] = opts.user
# if opts.irpass:
# conf['inReach']['Password'] = opts.irpass
# if opts.url:
# conf['inReach']['URL'] = opts.url
# if opts.comment:
# conf['APRS']['Comment'] = opts.comment
# if opts.delay:
# conf['General']['Period'] = opts.delay
#Allow command-line arguments to override the config file.
if opts.ssid: # Setup number of devices in conf file.
conf['APRS']['SSID'] = opts.ssid num_devices = len(conf['DEVICES'])
if opts.passwd: NAME = "iR-APRSISD"
conf['APRS']['Password'] = str(opts.passwd) REV = "0.1"
if opts.port:
conf['APRS']['Port'] = str(opts.port)
if opts.user:
conf['inReach']['User'] = opts.user
if opts.irpass:
conf['inReach']['Password'] = opts.irpass
if opts.url:
conf['inReach']['URL'] = opts.url
if opts.comment:
conf['APRS']['Comment'] = opts.comment
if opts.delay:
conf['General']['Period'] = opts.delay
#The beginning of our APRS packets should contain a source, path, #The beginning of our APRS packets should contain a source, path,
# q construct, and gateway address. We'll reuse the same SSID as a gate. # q construct, and gateway address. We'll reuse the same SSID as a gate.
ARPreamble = ''.join([conf['APRS']['SSID'],'>APRS,','TCPIP*,','qAS,',conf['APRS']['SSID']]) #IF you have multiple devices, determine device IMEI and preamble to use for each device.
# if there is only one device, it will setup 1 preamble just like the original version
NAME = "iR-APRSISD" for i in range(1,num_devices+1):
REV = "0.1" #The beginning of our APRS packets should contain a source, path,
# q construct, and gateway address. We'll reuse the same SSID as a gate.
exec("ARPreamble_" + str(i) + " = ''.join([conf['APRS']['SSID_' + str(i)],'>APRS,','TCPIP*,','qAS,',conf['APRS']['SSID_' + str(i)]]) ")
exec("DEVICE_" + str(i) + " = conf['DEVICES']['DEVICE_' + str(i)]")
#Start with the current time. We use this to keep track of whether we've #Start with the current time. We use this to keep track of whether we've
# already sent a position, so if we cut it off when the program starts, we # already sent a position, so if we cut it off when the program starts, we
@ -99,7 +108,7 @@ urllib.request.install_opener(http)
def reconnect(): def reconnect():
global AIS global AIS
while True: while True:
AIS = aprslib.IS(conf['APRS']['SSID'],passwd=conf['APRS']['Password'],port=conf['APRS']['Port']) AIS = aprslib.IS(conf['APRS']['SSID'],passwd=int(conf['APRS']['Password']),port=int(conf['APRS']['Port'])))
try: try:
AIS.connect() AIS.connect()
break break
@ -135,6 +144,7 @@ while True:
try: try:
#Here is the position vector #Here is the position vector
latitude = extended['Latitude'] latitude = extended['Latitude']
longitude = extended['Longitude'] longitude = extended['Longitude']
elevation = extended['Elevation'] elevation = extended['Elevation']
@ -142,7 +152,15 @@ while True:
course = extended['Course'] course = extended['Course']
uttime = extended['Time UTC'] uttime = extended['Time UTC']
device = extended['Device Type'] device = extended['Device Type']
# EDB : add IMEI to compare with KML and determine which SSID / IMEI to use
imei = extended['IMEI']
# Determine which ARPreamble to use based on IMEI of device
for i in range(1,num_devices+1):
if imei == eval('DEVICE_' + str(i)):
ARPreamble = eval('ARPreamble_' + str(i))
#Some time conversions. First the time struct. #Some time conversions. First the time struct.
ts = time.strptime(''.join([uttime," UTC"]),"%m/%d/%Y %I:%M:%S %p %Z") ts = time.strptime(''.join([uttime," UTC"]),"%m/%d/%Y %I:%M:%S %p %Z")
@ -221,7 +239,7 @@ while True:
print(aprsPacket) print(aprsPacket)
#This will throw an exception if the packet is somehow wrong. #This will throw an exception if the packet is somehow wrong.
aprslib.parse(aprsPacket) aprslib.parse(aprsPacket)
AIS.sendall(aprsPacket) # AIS.sendall(aprsPacket)
lastUpdate = etime lastUpdate = etime
except Exception as e: except Exception as e:
print("Could not send the update: ") print("Could not send the update: ")

View file

@ -1,14 +1,24 @@
# New config file to handle multiple inreach devices
[inReach] [inReach]
User = Your-inReach-Username User = Your-inReach-Username
#If this is defined, we will authenticate to the inReach service. #If this is defined, we will authenticate to the inReach service.
# If it is not, we will assume public access is ok. # If it is not, we will assume public access is ok.
#Password = Your inReach feed password, if required #Password = Your inReach Feed password, if required
# This should be the location of your KML feed. # This should be the location of your KML feed.
URL = https://share.garmin.com/Feed/Share/%(User)s URL = https://share.garmin.com/Feed/Share/%(User)s
[DEVICES]
DEVICE_1 = IMEI_1
DEVICE_2 = IMEI_2
DEVICE_x = IMEI_x
[APRS] [APRS]
SSID = N0CALL-10 SSID_1 = NOCALL-10
SSID_2 = NOCALL-11
SSID_x = NOCALL-x
Password = 1234 Password = 1234
Port = 14580 Port = 14580