Created
January 26, 2026 01:21
-
-
Save alecperkins/b8eb7ab0cd4ec9c322c45799cd4e6e66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The functions that CmWx uses to send its regular text messages and | |
| # telemetry to the mesh. | |
| from meshtastic import portnums_pb2, telemetry_pb2, BROADCAST_ADDR, mesh_pb2 | |
| import logging | |
| def sendTextMessage (interface, data, channelIndex=0): | |
| logging.debug('sendTextMessage', channelIndex, data.get('hops'), data.get('priority')) | |
| hops = data.get('hops', 3) | |
| priority = mesh_pb2.MeshPacket.Priority.RELIABLE | |
| if data.get('priority') == 'background': | |
| priority = mesh_pb2.MeshPacket.Priority.BACKGROUND | |
| result = interface.sendData( | |
| data['text'].strip().encode('utf-8'), | |
| destinationId=BROADCAST_ADDR, | |
| portNum=portnums_pb2.PortNum.TEXT_MESSAGE_APP, | |
| wantResponse=False, | |
| onResponse=None, | |
| channelIndex=channelIndex, | |
| hopLimit=hops, | |
| priority=priority, | |
| ) | |
| logging.debug(result) | |
| def sendWeatherMessage (interface, data): | |
| return sendTextMessage(interface, data, 1) | |
| def sendWeatherTelemetry (interface, data): | |
| logging.debug('sendWeatherTelemetry', data.get('priority')) | |
| payload = telemetry_pb2.Telemetry() | |
| payload.environment_metrics.CopyFrom( | |
| telemetry_pb2.EnvironmentMetrics( | |
| temperature=data['temperature_c'], | |
| relative_humidity=data['relative_humidity_pct'], | |
| wind_direction=data['wind_degrees'], | |
| wind_speed=data['wind_meters_per_second'], | |
| rainfall_1h=data['rainfall_1h_mm'], | |
| ## Disabled b/c it wasn't working properly in the clients | |
| # barometric_pressure=data.get('barometric_pressure_mb'), | |
| # lux=data.get('lux'), | |
| # iaq=data.get('iaq'), | |
| ) | |
| ) | |
| priority = mesh_pb2.MeshPacket.Priority.BACKGROUND | |
| if data.get('priority') == 'reliable': | |
| priority = mesh_pb2.MeshPacket.Priority.RELIABLE | |
| result = interface.sendData( | |
| payload, | |
| destinationId=BROADCAST_ADDR, | |
| portNum=portnums_pb2.PortNum.TELEMETRY_APP, | |
| wantResponse=False, | |
| onResponse=None, | |
| channelIndex=0, | |
| hopLimit=1, | |
| priority=priority, | |
| ) | |
| logging.debug(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment