forked from pdxlocations/Meshtastic-Python-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-environment-metrics.py
46 lines (35 loc) · 1.34 KB
/
send-environment-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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from meshtastic import portnums_pb2, telemetry_pb2
# 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.2.89', noProto=False)
# NODE ID to send the weather infomation
BROADCAST_ADDR = XXXXXX
# Grab the Weather info
file1 = open('AirQuality')
sendAirQuality = file1.readlines()
file2 = open('Humidity')
sendHumidity = file2.readlines()
file3 = open('Pressure')
sendPressure = file3.readlines()
file4 = open('Temperature')
sendTemperature = file4.readlines()
# Send data to the node
telemetry_data = telemetry_pb2.Telemetry()
for line in sendTemperature:
print("telemetry_data.environment_metrics.temperature = {}".format(line.strip()))
for line in sendHumidity:
print("telemetry_data.environment_metrics.relative_humidity = {}".format(line.strip()))
for line in sendPressure:
print("telemetry_data.environment_metrics.barometric_pressure = {}".format(line.strip()))
for line in sendAirQuality:
print("telemetry_data.environment_metrics.gas_resistance = {}".format(line.strip()))
interface.sendData(
telemetry_data,
destinationId=BROADCAST_ADDR,
portNum=portnums_pb2.PortNum.TELEMETRY_APP,
wantResponse=False,
)
interface.close()