-
Notifications
You must be signed in to change notification settings - Fork 3
/
send-device-metrics.py
32 lines (26 loc) · 954 Bytes
/
send-device-metrics.py
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
try:
from meshtastic.protobuf import portnums_pb2, telemetry_pb2
from meshtastic import BROADCAST_NUM
except ImportError:
from meshtastic import portnums_pb2, telemetry_pb2, BROADCAST_NUM
import time
# For connection over serial
import meshtastic.serial_interface
interface = meshtastic.serial_interface.SerialInterface()
# For connection over TCP
# import meshtastic.tcp_interface
# interface = meshtastic.tcp_interface.TCPInterface(hostname='192.168.1.42', noProto=False)
telemetry_data = telemetry_pb2.Telemetry()
telemetry_data.device_metrics.battery_level = 69
telemetry_data.device_metrics.voltage = 4.1
telemetry_data.device_metrics.channel_utilization = 42
telemetry_data.device_metrics.air_util_tx = 1
telemetry_data.time = int(time.time())
interface.sendData(
telemetry_data,
destinationId=BROADCAST_NUM,
portNum=portnums_pb2.PortNum.TELEMETRY_APP,
wantResponse=False,
onResponse=False,
)
interface.close()