Stap 5: De CWOP APRS-pakketten verzenden
Vervolgens, hebben we de code die we gebruiken voor het bouwen van de CWOP APRS-pakketten.
#!/usr/bin/env python # SwitchDoc Labs # July 24, 2015 # Version 1.0 """ initially from Tom Hayward builds and submits an APRS weather packet to the APRS-IS/CWOP. BSD License and stuff Copyright 2010 Tom Hayward <tom """ import sys, os, time from datetime import datetime, timedelta from socket import * sys.path.append('..') # Check for user imports try: import conflocal as conf except ImportError: import conf def make_aprs_wx(wind_dir=None, wind_speed=None, wind_gust=None, temperature=None, rain_since_midnight=None, humidity=None, pressure=None): """ Assembles the payload of the APRS weather packet. """ def str_or_dots(number, length): """ If parameter is None, fill space with dots. Else, zero-pad. """ if number is None: return '.'*length else: format_type = { 'int': 'd', 'float': '.0f', }[type(number).__name__] return ''.join(('%0',str(length),format_type)) % number timeStringZulu = time.strftime("%d%H%M") return ' % ( timeStringZulu, conf.STATIONLATITUDE, conf.STATIONLONGITUDE, str_or_dots(wind_dir, 3), str_or_dots(wind_speed, 3), str_or_dots(wind_gust, 3), str_or_dots(temperature, 3), str_or_dots(rain_since_midnight, 3), str_or_dots(humidity, 2), str_or_dots(pressure, 5), conf.STATION_TYPE ) def post_CWOP(wind_dir=None, wind_speed=None, wind_gust=None, temperature=None, rain_since_midnight=None, humidity=None, pressure=None): # post to aprs wx = make_aprs_wx(wind_dir=wind_dir, wind_speed=wind_speed, wind_gust=wind_gust, temperature=temperature, rain_since_midnight=rain_since_midnight, humidity=humidity, pressure=pressure) print time.strftime("%Y-%m-%d %H:%M:%S"), wx send_aprs(conf.APRS_HOST, conf.APRS_PORT, conf.APRS_USER, conf.APRS_PASS, conf.CALLSIGN, wx) return