| 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 |
dominic / aprs_sendstatus.py
Last active 4 months ago
Revision 64f28670e283b3294f4f4fd728569c5dad7f7546