Last active 1731166851

aprs_sendstatus.py Raw
1#!/usr/bin/env python3
2
3""" sending aprs status packets for my weather station
4
5 Author: Dominic Reich (OE7DRT) <quick.hat4396@qtztsjosmprqmgtunjyf.com>
6"""
7
8import aprslib
9
10
11intervals = (
12 ('weeks', 604800), # 60 * 60 * 24 * 7
13 ('days', 86400), # 60 * 60 * 24
14 ('hours', 3600), # 60 * 60
15 ('minutes', 60),
16 ('seconds', 1),
17)
18
19
20def get_uptime(granularity=2):
21 with open('/proc/uptime', 'r') as u:
22 uptime_seconds = int(float(u.readline().split()[0]))
23
24 return(display_time(uptime_seconds, granularity))
25
26
27def display_time(seconds, granularity=2):
28 result = []
29
30 for name, count in intervals:
31 value = seconds // count
32 if value:
33 seconds -= value * count
34 if value == 1:
35 name = name.rstrip('s')
36 result.append("{} {}".format(value, name))
37 return ', '.join(result[:granularity])
38
39
40def test():
41 """test function"""
42 print('Uptime: ' + get_uptime())
43
44
45def main():
46 """main func"""
47 AIS = aprslib.IS("OE7DRT-13", passwd="*****", port=14580)
48
49 #AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Running for " + get_uptime(2) + " on https://wx.oe7drt.com\r\n")
50 try:
51 AIS.connect()
52 except TimeoutError:
53 print("Could not send packets - Timeout.")
54 except:
55 print("An unexpected Error occured:")
56
57 AIS.sendall("OE7DRT-13>APRS,TCPIP*:>Weatherpage: https://wx.oe7drt.com\r\n")
58
59if __name__ == "__main__":
60 main()
61