-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhab-logger
More file actions
executable file
·68 lines (53 loc) · 2.3 KB
/
hab-logger
File metadata and controls
executable file
·68 lines (53 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/home/trick/venv/bin/python
# -*- coding: utf-8 -*-
import sys
import meshtastic
import meshtastic.serial_interface
import time
from datetime import datetime, timezone
hourago = int(time.time()) - 3600
age_10m = int(time.time()) - 600
iface = meshtastic.serial_interface.SerialInterface()
nodes = iface.nodes
#print(nodes)
import json
print(json.dumps(nodes))
live_nodes = 0
for a in nodes.values():
if "lastHeard" in a.keys() and "snr" in a.keys():
if a['lastHeard'] > age_10m:
live_nodes += 1
if a['lastHeard'] > hourago:
print("Live Node: id=\"{}\", longName=\"{}\", shortName=\"{}\" {}".format(a['user']['id'], a['user']['longName'], a['user']['shortName'], a['snr']))
else:
print("{} is too old {} {}".format(a['user']['id'], a['lastHeard'], hourago))
1
else:
print("{} has no lastHeard or snr".format(a['user']['id']))
1
# Extract latitude and longitude for node !433e1118
node_id = '!433e1118'
latitude = longitude = altitude = uptime_seconds = channel_util = air_util = None
try:
if nodes[node_id]['position']:
position = nodes[node_id]['position']
latitude = position['latitude']
longitude = position['longitude']
altitude = position['altitude']
else:
latitude = longitude = altitude = None
uptime_seconds = nodes[node_id]['deviceMetrics']['uptimeSeconds']
channel_util = nodes[node_id]['deviceMetrics']['channelUtilization']
air_util = nodes[node_id]['deviceMetrics']['airUtilTx']
except Exception as e:
print("masking exception: {}".format(e))
def send_to_ground(message):
print("Sending to ground: {}".format(message))
iface.sendText(message, destinationId='!1fa06c00', wantAck=False, wantResponse=False)
# Get current UTC date and time in ISO format
current_utc_time_iso = datetime.now(timezone.utc).isoformat()
send_to_ground("Hello at {} from lat={} lon={} alt={} chanUtil={} airUtilTx={} uptime={}".format(current_utc_time_iso, latitude, longitude, altitude, channel_util, air_util, uptime_seconds))
send_to_ground("{} live nodes".format(live_nodes))
#iface.sendText("Hello World", destinationId='!1fa06c00', wantAck=False, wantResponse=False)
#iface.sendText("{} live nodes", destinationId='!1fa06c00', wantAck=False, wantResponse=False)
iface.close()