aprs_sendstatus.py
· 2.0 KiB · Python
Raw
#!/home/dominic/python/aprs/bin/python3
""" sending aprs status packets for my weather station
and the -10 Packet Station
Author: Dominic Reich (OE7DRT) <quick.hat4396@qtztsjosmprqmgtunjyf.com>
Lastmod: 2026-02-15T11:52:22+0000
"""
import aprslib
import datetime
intervals = (
('weeks', 604800), # 60 * 60 * 24 * 7
('days', 86400), # 60 * 60 * 24
('hours', 3600), # 60 * 60
('minutes', 60),
('seconds', 1),
)
def get_uptime(granularity=2):
with open('/proc/uptime', 'r') as u:
uptime_seconds = int(float(u.readline().split()[0]))
return(display_time(uptime_seconds, granularity))
def display_time(seconds, granularity=2):
result = []
for name, count in intervals:
value = seconds // count
if value:
seconds -= value * count
if value == 1:
name = name.rstrip('s')
result.append("{} {}".format(value, name))
return ', '.join(result[:granularity])
def test():
"""test function"""
print('Uptime: ' + get_uptime())
def main():
"""main func"""
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%d%H%M")
#
# Login as Weatherstation OE7DRT-13
#
AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580)
AIS.connect()
# AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com - happy new year!\r\n")
AIS.sendall("OE7DRT-13>APZ,TCPIP*:>" + timestamp + "zhttps://wx.oe7drt.com")
#
# Log in as iGate OE7DRT-10
#
# Log in multiple times in order to get qAC
# otherwise station x would provide infos for station y and that ends up in qAS
# which is deprecated: https://www.aprs-is.net/q.aspx
AIS = aprslib.IS("OE7DRT-10", passwd="*****", port=14580)
AIS.connect()
# AIS.sendall("OE7DRT-10>APZ,TCPIP:>" + timestamp + "zhttps://oe7drt.com/equipment/radio-stuff/packet-radio-node/")
AIS.sendall("OE7DRT-10>APZ,TCPIP*:>" + timestamp + "zhttps://oe7drt.com/")
if __name__ == "__main__":
main()
| 1 | #!/home/dominic/python/aprs/bin/python3 |
| 2 | |
| 3 | """ sending aprs status packets for my weather station |
| 4 | and the -10 Packet Station |
| 5 | |
| 6 | Author: Dominic Reich (OE7DRT) <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
| 7 | Lastmod: 2026-02-15T11:52:22+0000 |
| 8 | """ |
| 9 | |
| 10 | import aprslib |
| 11 | import datetime |
| 12 | |
| 13 | intervals = ( |
| 14 | ('weeks', 604800), # 60 * 60 * 24 * 7 |
| 15 | ('days', 86400), # 60 * 60 * 24 |
| 16 | ('hours', 3600), # 60 * 60 |
| 17 | ('minutes', 60), |
| 18 | ('seconds', 1), |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | def get_uptime(granularity=2): |
| 23 | with open('/proc/uptime', 'r') as u: |
| 24 | uptime_seconds = int(float(u.readline().split()[0])) |
| 25 | |
| 26 | return(display_time(uptime_seconds, granularity)) |
| 27 | |
| 28 | |
| 29 | def display_time(seconds, granularity=2): |
| 30 | result = [] |
| 31 | |
| 32 | for name, count in intervals: |
| 33 | value = seconds // count |
| 34 | if value: |
| 35 | seconds -= value * count |
| 36 | if value == 1: |
| 37 | name = name.rstrip('s') |
| 38 | result.append("{} {}".format(value, name)) |
| 39 | return ', '.join(result[:granularity]) |
| 40 | |
| 41 | |
| 42 | def test(): |
| 43 | """test function""" |
| 44 | print('Uptime: ' + get_uptime()) |
| 45 | |
| 46 | |
| 47 | def main(): |
| 48 | """main func""" |
| 49 | timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%d%H%M") |
| 50 | |
| 51 | # |
| 52 | # Login as Weatherstation OE7DRT-13 |
| 53 | # |
| 54 | AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580) |
| 55 | AIS.connect() |
| 56 | |
| 57 | # AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com - happy new year!\r\n") |
| 58 | AIS.sendall("OE7DRT-13>APZ,TCPIP*:>" + timestamp + "zhttps://wx.oe7drt.com") |
| 59 | |
| 60 | # |
| 61 | # Log in as iGate OE7DRT-10 |
| 62 | # |
| 63 | # Log in multiple times in order to get qAC |
| 64 | # otherwise station x would provide infos for station y and that ends up in qAS |
| 65 | # which is deprecated: https://www.aprs-is.net/q.aspx |
| 66 | AIS = aprslib.IS("OE7DRT-10", passwd="*****", port=14580) |
| 67 | AIS.connect() |
| 68 | # AIS.sendall("OE7DRT-10>APZ,TCPIP:>" + timestamp + "zhttps://oe7drt.com/equipment/radio-stuff/packet-radio-node/") |
| 69 | AIS.sendall("OE7DRT-10>APZ,TCPIP*:>" + timestamp + "zhttps://oe7drt.com/") |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |
| 73 |