diff --git a/balloon.ini b/balloon.ini index 0b5659f..ff623bc 100644 --- a/balloon.ini +++ b/balloon.ini @@ -6,13 +6,22 @@ push_aprs = True # This is the callsign the object comes from. This should NOT have any SSID's on it (i.e. -9) aprsCallsign = "myhamcall" + # Replace with your own callsign. This should NOT have any SSID's on it (i.e. -9) aprsUser = 'myaprsisuser' + # APRS-IS passcode for your callsign. aprsPass = 'myaprsispass' -# [ habhub name, aprs-call, band in mhz, channel, timeslot ] -balloons = [[ "BSY22","SA7XXX",14,11,0 ], - [ "B2", "SOMECALL",14,12,0 ]] +push_html = False +push_ftp = False +ftp_server = ftp.uus.ro +ftp_username = xxx +ftp_password = xxx + +# [ habhub name, aprs-wspr-call, band in mhz, channel, timeslot, datetime, html_push, aprs-ssid, aprs_comment] :: html_push ONLY for one balloon + +balloons = [["BS234","CALL1",14,11,0,"20200831T0557",0,"12","Balloon 20m WSPR"], + ["ISDF","CALL2",14,15,2,"20200831T0558",0,"12","Balloon 20m WSPR"]] diff --git a/sonde_to_aprs.py b/sonde_to_aprs.py index 00dcacf..38c595a 100755 --- a/sonde_to_aprs.py +++ b/sonde_to_aprs.py @@ -20,6 +20,7 @@ import configparser import time, datetime, urllib3, sys +import logging from socket import * # APRS-IS login info @@ -35,144 +36,78 @@ aprsPass = config['main']['aprsPass'] # This is the callsign the object comes from. Doesn't necessarily have to be the same as your APRS-IS login. callsign = config['main']['aprsCallsign'] -# Get KML from SondeMonitor and parse into a Python dictionary def get_sonde(): - sonde_data = {} - sonde_data["lat"] = str(sys.argv[2]) - sonde_data["lon"] = str(sys.argv[3]) - sonde_data["alt"] = "10000" - sonde_data["id"] = str(sys.argv[1]) - return sonde_data + sonde_data = {} + sonde_data["lat"] = str(sys.argv[2]) + sonde_data["lon"] = str(sys.argv[3]) + sonde_data["alt"] = "10000" + sonde_data["id"] = str(sys.argv[1]) + sonde_data["speed"] = "0" + sonde_data["temp"] = "0" + sonde_data["batt"] = "0" + sonde_data["comment"] = str(sys.argv[8]) + return sonde_data # Push a Radiosonde data packet to APRS as an object. def push_balloon_to_aprs(sonde_data): - # Pad or limit the sonde ID to 9 characters. - object_name = sonde_data["id"] - if len(object_name) > 9: - object_name = object_name[:9] - elif len(object_name) < 9: - object_name = object_name + " "*(9-len(object_name)) + # Pad or limit the sonde ID to 9 characters. + object_name = sonde_data["id"] + if len(object_name) > 9: + object_name = object_name[:9] + elif len(object_name) < 9: + object_name = object_name + " "*(9-len(object_name)) - # Convert float latitude to APRS format (DDMM.MM) - lat = float(sonde_data["lat"]) - lat_degree = abs(int(lat)) - lat_minute = abs(lat - int(lat)) * 60.0 - lat_min_str = ("%02.2f" % lat_minute).zfill(5) - lat_dir = "S" - if lat>0.0: - lat_dir = "N" - lat_str = "%02d%s" % (lat_degree,lat_min_str) + lat_dir + # Convert float latitude to APRS format (DDMM.MM) + lat = float(sonde_data["lat"]) + lat_degree = abs(int(lat)) + lat_minute = abs(lat - int(lat)) * 60.0 + lat_min_str = ("%02.2f" % lat_minute).zfill(5) + lat_dir = "S" + if lat>0.0: + lat_dir = "N" + + lat_str = "%02d%s" % (lat_degree,lat_min_str) + lat_dir - # Convert float longitude to APRS format (DDDMM.MM) - lon = float(sonde_data["lon"]) - lon_degree = abs(int(lon)) - lon_minute = abs(lon - int(lon)) * 60.0 - lon_min_str = ("%02.2f" % lon_minute).zfill(5) - lon_dir = "E" - if lon<0.0: - lon_dir = "W" - lon_str = "%03d%s" % (lon_degree,lon_min_str) + lon_dir - - # Convert Alt (in metres) to feet - alt = int(float(sonde_data["alt"])/0.3048) - - # Produce the APRS object string. - out_str = ";%s*111111z%s/%sO000/000/A=%06d Balloon" % (object_name,lat_str,lon_str,alt) - print(out_str) + # Convert float longitude to APRS format (DDDMM.MM) + lon = float(sonde_data["lon"]) + lon_degree = abs(int(lon)) + lon_minute = abs(lon - int(lon)) * 60.0 + lon_min_str = ("%02.2f" % lon_minute).zfill(5) + lon_dir = "E" + if lon<0.0: + lon_dir = "W" + lon_str = "%03d%s" % (lon_degree,lon_min_str) + lon_dir - # Connect to an APRS-IS server, login, then push our object position in. - + # Convert Alt (in metres) to feet + alt = int(float(sonde_data["alt"])/0.3048) + + # Convert Speed (in metres) to feet + speed = round(float(sonde_data["speed"])) + + #if speed < 1: + # speed = 1; + + temp = round(float(sonde_data["temp"]),1) + batt = round(float(sonde_data["batt"]),2) + object_comment = sonde_data["comment"] + + + # Produce the APRS object string. + #out_str = ";%s*111111z%s/%sO000/000/A=%06d Balloon" % (object_name,lat_str,lon_str,alt) + # print(out_str) + out_str = ";%s*111111z%s/%sO000/%03d/A=%06dTemp=%sC Solar=%sV %s" % (object_name,lat_str,lon_str,speed,alt,temp,batt,object_comment) + logging.info('\033[33m' + "APRS: %s" + '\033[0m' , out_str) + + # Connect to an APRS-IS server, login, then push our object position in. # create socket & connect to server - sSock = socket(AF_INET, SOCK_STREAM) - sSock.connect((serverHost, serverPort)) + sSock = socket(AF_INET, SOCK_STREAM) + sSock.connect((serverHost, serverPort)) # logon - sSock.send(b'user %s pass %s vers VK5QI-Python 0.01\n' % (aprsUser.encode('utf-8'), aprsPass.encode('utf-8')) ) + sSock.send(b'user %s pass %s vers VK5QI-Python 0.01\n' % (aprsUser.encode('utf-8'), aprsPass.encode('utf-8')) ) # send packet - sSock.send(b'%s>APRS:%s\n' % (callsign.encode('utf-8'), out_str.encode('utf-8')) ) + sSock.send(b'%s>APRS:%s\n' % (callsign.encode('utf-8'), out_str.encode('utf-8')) ) # close socket - sSock.shutdown(0) - sSock.close() + sSock.shutdown(0) + sSock.close() - - -# VE3OCL-11:PARM.Speed,Temp,Vbat,GPS,Sats -# VE3OCL-11:UNIT.kn,C,V,, -# VE3OCL-11:BITS.11111111,10mW research balloon -# VE3OCL-11:EQNS.0,0.1,0,0,0.1,-273.2,0,0.001,0,0,1,0,0,1,0 - -# $speed = int(($speed * 10) + 0.5); -# $temp = int((($temp + 273.2) * 10) + 0.5); -# $vbat = int(($vbat * 1000) + 0.5); - - - - - -# For explanation of encoding see: -# http://he.fi/doc/aprs-base91-comment-telemetry.txt - - -# sub usage () -# { -# print STDERR "\n"; -# print STDERR "telem-data91.pl - Format data into compressed base 91 telemetry.\n"; -# print STDERR "\n"; -# print STDERR "Usage: telem-data91.pl sequence value1 [ value2 ... ]\n"; -# print STDERR "\n"; -# print STDERR "A sequence number and up to 5 analog values can be specified.\n"; -# print STDERR "Any sixth value must be 8 binary digits.\n"; -# print STDERR "Values must be integers in range of 0 to 8280.\n"; - - -# if ($#ARGV+1 < 2 || $#ARGV+1 > 7) { -# print STDERR "2 to 7 command line arguments must be provided.\n"; -# usage(); -# } - - -# if ($#ARGV+1 == 7) { -# if ( ! ($ARGV[6] =~ m/^[01]{8}$/)) { -# print STDERR "The sixth value must be 8 binary digits.\n"; -# usage(); -# } -# # Convert binary digits to value. -# $ARGV[6] = oct("0b" . reverse($ARGV[6])); -# } - -# $result = "|"; - -# for ($n = 0 ; $n <= $#ARGV; $n++) { -# #print $n . " = " . $ARGV[$n] . "\n"; -# $v = $ARGV[$n]; -# if ($v != int($v) || $v < 0 || $v > 8280) { -# print STDERR "argn $n - $v is not an integer in range of 0 to 8280.\n"; -# usage(); -# } - -# $result .= base91($v); -# } - -# $result .= "|"; -# print "$result\n"; -# exit 0; - - -# sub base91 () -# { -# my $x = @_[0]; - -# my $d1 = int ($x / 91); -# my $d2 = $x % 91; - -# return chr($d1+33) . chr($d2+33); -# } -# : - -# Py2 & Py3 compability -# import sys -# if sys.version_info[0] >= 3: -# is_py3 = True -# string_type = (str, ) -# string_type_parse = string_type + (bytes, ) -# int_type = int diff --git a/sonde_to_html.py b/sonde_to_html.py new file mode 100644 index 0000000..198ba80 --- /dev/null +++ b/sonde_to_html.py @@ -0,0 +1,100 @@ +import fileinput +import sys +import ftplib +import datetime +import configparser +import ftplib +import json + +config = configparser.ConfigParser( + converters = { + 'datetime': lambda s : datetime.datetime.fromisoformat(s) + } +) +config.read('balloon.ini') + +push_ftp = config['main'].getboolean('push_ftp') +ftp_server = config['main']['ftp_server'] +ftp_username = config['main']['ftp_username'] +ftp_password = config['main']['ftp_password'] +balloons = json.loads(config.get('main','balloons')) +then = datetime.datetime.strptime(balloons[0][5], "%Y%m%dT%H%M") + +def getDuration(then, now, interval = "default"): + + # Returns a duration as specified by variable interval + # Functions, except totalDuration, returns [quotient, remainder] + + duration = now - then # For build-in functions + duration_in_s = duration.total_seconds() + + def months(): + return duration_in_s // 2592000 # Seconds in a month=2592000. + + def days(): + return (duration_in_s // 86400 - 30 * months()) % 30# Seconds in a day = 86400 + + def hours(): + return (duration_in_s // 3600 - 24 * days()) % 24# Seconds in an hour = 3600 + + def minutes(): + return (duration_in_s // 60 - 60 * hours()) % 60# Seconds in a minute = 60 + + return { + 'months': int(months()), + 'days': int(days()), + 'hours': int(hours()), + 'minutes': int(minutes()), + }[interval] + +def push_balloon_to_html(telemetry): + def add_position(file): # search and replace for the map position + searchExp = "// #POSITION#" + replaceExp = f"\t\tnew google.maps.LatLng({telemetry['lat']},{telemetry['lon']}),\n// #POSITION#" + for line in fileinput.input(file, inplace=1): + if searchExp in line: + line = line.replace(searchExp,replaceExp) + sys.stdout.write(line) + add_position('ICT_RPI.html'); + + + def update_popup1(file): # search and replace for the telemetry popup1 + time = telemetry['time'].strftime("%d-%b-%Y %H%M") + time_now = datetime.datetime.utcnow() + time_now_delta = time_now.strftime("%Y%m%dT%H%M") + #print(then) + #print(telemetry['time']) + + searchExp = "'
Updated" + replaceExp = f"'
Updated {time}Z
Locator = {telemetry['loc'].upper()}
Duration = {getDuration(then,telemetry['time'],'months')}mo {getDuration(then,telemetry['time'],'days')}d {getDuration(then,telemetry['time'],'hours')}h {getDuration(then,telemetry['time'],'minutes')}m
Distance = '+ distance + \n"
+ for line in fileinput.input(file, inplace=1):
+ if searchExp in line:
+ line = line.replace(line,replaceExp)
+ sys.stdout.write(line)
+ update_popup1('ICT_RPI.html');
+
+ def update_popup2(file): # search and replace for the telemetry popup2
+ searchExp = "'km
Altitude"
+ replaceExp = f"'km
Altitude = {telemetry['alt']}m
Speed = {telemetry['speed']}kt {round(telemetry['speed']*1.852)}km/h
Solar = {round(telemetry['batt'],2)}V, Temp = {round(telemetry['temp'],1)}C
GPS = {int(telemetry['gps'])}, Sats = {int(telemetry['sats'])}