mirror of
				https://github.com/kemenril/iR-APRSISD.git
				synced 2025-03-05 20:51:35 -08:00 
			
		
		
		
	Minor clean-up, and added some simple but useful logging to STDOUT.
This commit is contained in:
		
							parent
							
								
									2a9c938eaa
								
							
						
					
					
						commit
						c49d6298e8
					
				
							
								
								
									
										43
									
								
								ir-aprsisd
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								ir-aprsisd
									
									
									
									
									
								
							|  | @ -137,14 +137,15 @@ urllib.request.install_opener(http) | |||
| #Handle connection to APRS-IS | ||||
| def reconnect(): | ||||
| 	global AIS | ||||
| 	attempt = 1 | ||||
| 	while True: | ||||
| 		AIS = aprslib.IS(conf['APRS']['SSID'],passwd=conf['APRS']['Password'],port=conf['APRS']['Port']) | ||||
| 		try: | ||||
| 			AIS.connect() | ||||
| 			break | ||||
| 		except Exception as e: | ||||
| 			print("Trouble connecting to APRS-IS server.") | ||||
| 			print(e) | ||||
| 			print("Connection failed.  Reconnecting: " + str(attempt)) | ||||
| 			attempt += 1 | ||||
| 			time.sleep(3) | ||||
| 			continue | ||||
| 
 | ||||
|  | @ -153,32 +154,39 @@ SSIDList = {} | |||
| #We'll store timestamps here | ||||
| lastUpdate = {} | ||||
| 
 | ||||
| #Packet counts here | ||||
| transmitted = {} | ||||
| #Last time stats() was run: | ||||
| lastStats = calendar.timegm(time.gmtime()) | ||||
| 
 | ||||
| 
 | ||||
| #Load any preconfigured mappings | ||||
| if conf.has_section('Devices'): | ||||
| 	print("Loading predefined SSID mappings.") | ||||
| 	for device in conf['Devices'].keys(): | ||||
| 		SSIDList[conf['Devices'][device]] = device.upper() | ||||
| 		print("Static mapping: " + SSIDList[conf['Devices'][device]] + " -> " + device.upper()) | ||||
| 		 | ||||
| 
 | ||||
| #Get an SSID | ||||
| #An apocryphal concern is that this will happily generate an SSID for None, | ||||
| #	or whatever else might get passed along to it. | ||||
| # There's a record in the usual set of inReach Placemarks where this happens, | ||||
| # but because the record has no extended data, no packets are ever generated | ||||
| # for it. Such a record is generally not interesting and on the end of the list, | ||||
| # so there has been no reason to explicitly skip it. | ||||
| def getSSID(DID): | ||||
| 	global lastUpdate, SSIDList, SSNum, Call | ||||
| 	global lastUpdate, SSIDList, transmitted, SSNum, Call | ||||
| 	if not DID:	# Don't map None | ||||
| 		return None | ||||
| 	#If we have a Devices section, the SSID list is static. | ||||
| 	if DID not in SSIDList: | ||||
| 		if conf.has_section('Devices'): | ||||
| 			return None | ||||
| 		SSIDList[DID] = ''.join([Call,"-",str(SSNum)]) | ||||
| 		SSNum = SSNum + 1 | ||||
| 		print("Mapping: " + DID + " -> " + SSIDList[DID]) | ||||
| 	#Add a timestamp on the first call | ||||
| 	# This prevents us from redelivering an old message, which can stay | ||||
| 	# in the feed. | ||||
| 	if DID not in lastUpdate: | ||||
| 		lastUpdate[DID] = calendar.timegm(time.gmtime()) | ||||
| 	if DID not in transmitted: | ||||
| 		transmitted[DID] = 0 | ||||
| 	return SSIDList[DID] | ||||
| 
 | ||||
| 
 | ||||
|  | @ -271,7 +279,7 @@ def getEvents(): | |||
| #	float Longitude, float Altitude in feet, int float course in degrees, | ||||
| #	float speed in knots, comment | ||||
| def sendAPRS(device, DevID, ARPreamble, tstamp, lat, long, alt, course, speed, comment): | ||||
| 	global		conf | ||||
| 	global		conf, transmitted | ||||
| 	etime		= calendar.timegm(tstamp) | ||||
| 
 | ||||
| 	#Latitude conversion | ||||
|  | @ -331,11 +339,26 @@ def sendAPRS(device, DevID, ARPreamble, tstamp, lat, long, alt, course, speed, c | |||
| 		pass | ||||
| 	#Last update in UTC | ||||
| 	lastUpdate[DevID]	= calendar.timegm(tstamp) | ||||
| 	transmitted[DevID]	+= 1 | ||||
| 
 | ||||
| def stats(): | ||||
| 	global transmitted, lastStats | ||||
| 	lastStats = calendar.timegm(time.gmtime()) | ||||
| 	print("----------------Packet Forwarding Summary----------------") | ||||
| 	print("|\t" + time.strftime("%Y-%m-%d %R",time.localtime())) | ||||
| 	print("| SSID		DevID			Packets forwarded") | ||||
| 	for device in transmitted: | ||||
| 		print("| " + getSSID(device) + "\t" + device + "\t\t" + str(transmitted[device])) | ||||
| 	print("---------------------------------------------------------") | ||||
| 	print() | ||||
| 
 | ||||
| #... and here is the main loop. | ||||
| while True: | ||||
| 	for packet in getEvents(): | ||||
| 		sendAPRS(*packet)	#Otherwise a list of sendAPRS args for the next packet to send. | ||||
| 	if "Logstats" in conf["General"]: | ||||
| 		if calendar.timegm(time.gmtime()) > lastStats + conf.getint("General","Logstats"): | ||||
| 			stats() | ||||
| 	time.sleep(conf.getfloat('General','Period')) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,44 +0,0 @@ | |||
| [inReach] | ||||
| User		= Your inReach feed user | ||||
| #If this is defined, we will authenticate to the inReach service. | ||||
| # If it is not, we will assume public access is ok. | ||||
| #Password	= Your inReach feed password, if required | ||||
| 
 | ||||
| # This should be the location of your KML feed. | ||||
| URL		= https://share.garmin.com/Feed/Share/%(User)s | ||||
| 
 | ||||
| [APRS] | ||||
| #This SSID is used for logging into APRS-IS, and also as a base ID for  | ||||
| # generating callsigns for devices.  The first device found will be this | ||||
| # SSID, the next will be this ID + 1, and so on.  If you define a [Devices] | ||||
| # section, it is _only_ used for the login, and the device mapping must be | ||||
| # given in full in the [Devices] section. | ||||
| SSID		= N0CALL | ||||
| # If you don't have a password, you can use the --genpass command-line | ||||
| # option to calculate it. | ||||
| Password	= 1234 | ||||
| Port		= 14580 | ||||
| 
 | ||||
| #If the separator is /, your icon will come from the primary symbol table. | ||||
| # if it is \, it will draw from the secondary table. | ||||
| Separator	= / | ||||
| #This character represents an APRS icon from the table tied to Separator. | ||||
| Symbol		= ( | ||||
| 
 | ||||
| #This information is included at the end of each packet, along with some  | ||||
| # other data. | ||||
| Comment		= APRS-IS KML forwarder, by K0SIN | ||||
| 
 | ||||
| #Define this section if you'd like to enforce an SSID to IMEI mapping. | ||||
| # It must contain all devices you want to publish.  Anything without a | ||||
| # mapping defined will be ignored if this section exists. | ||||
| #[Devices] | ||||
| #N0CALL-12	= 987654321987654 | ||||
| #N0CALL-15	= 987654321987656 | ||||
| #N0CALL-8	= 092847784398753 | ||||
| 
 | ||||
| [General] | ||||
| # KML polling interval in seconds. | ||||
| Period		= 300 | ||||
| 
 | ||||
| 
 | ||||
		Loading…
	
		Reference in a new issue