Skip to content

Instantly share code, notes, and snippets.

@barryhunter
Created March 20, 2024 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhunter/ccc792e7d0101fdea79e640f150fc180 to your computer and use it in GitHub Desktop.
Save barryhunter/ccc792e7d0101fdea79e640f150fc180 to your computer and use it in GitHub Desktop.
Meshtastic Protocol Buffer class for https://github.com/T0ha/uprotobuf
pip install protobuf
wget https://github.com/protocolbuffers/protobuf/releases/download/v26.0/protoc-26.0-linux-x86_64.zip
unzip protoc-26.0-linux-x86_64.zip
git clone https://github.com/T0ha/uprotobuf
git clone https://github.com/meshtastic/protobufs
cd protobufs/
mkdir output
../bin/protoc --plugin=protoc-gen-custom=../uprotobuf/scripts/uprotobuf_plugin.py --custom_out=output/ meshtastic/mesh.proto
cat output/meshtastic/mesh_upb2.py 
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
class ChannelSettings(Message):
_fields=[
Field(name='channel_num', type='UInt32', id=1),
Field(name='psk', type='Bytes', id=2),
Field(name='name', type='String', id=3),
Field(name='id', type='Fixed32', id=4),
Field(name='uplink_enabled', type='Bool', id=5),
Field(name='downlink_enabled', type='Bool', id=6),
Field(name='module_settings', type='Message', id=7, cls=ModuleSettings),
]
class ModuleSettings(Message):
_fields=[
Field(name='position_precision', type='UInt32', id=1),
]
class Channel(Message):
class Role(Enum):
default = 0
DISABLED = 0
PRIMARY = 1
SECONDARY = 2
_fields=[
Field(name='index', type='Int32', id=1),
Field(name='settings', type='Message', id=2, cls=ChannelSettings),
Field(name='role', type='Enum', id=3, cls=Role),
]
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
class Position(Message):
class LocSource(Enum):
default = 0
LOC_UNSET = 0
LOC_MANUAL = 1
LOC_INTERNAL = 2
LOC_EXTERNAL = 3
class AltSource(Enum):
default = 0
ALT_UNSET = 0
ALT_MANUAL = 1
ALT_INTERNAL = 2
ALT_EXTERNAL = 3
ALT_BAROMETRIC = 4
_fields=[
Field(name='latitude_i', type='SignedFixed32', id=1),
Field(name='longitude_i', type='SignedFixed32', id=2),
Field(name='altitude', type='Int32', id=3),
Field(name='time', type='Fixed32', id=4),
Field(name='location_source', type='Enum', id=5, cls=LocSource),
Field(name='altitude_source', type='Enum', id=6, cls=AltSource),
Field(name='timestamp', type='Fixed32', id=7),
Field(name='timestamp_millis_adjust', type='Int32', id=8),
Field(name='altitude_hae', type='SInt32', id=9),
Field(name='altitude_geoidal_separation', type='SInt32', id=10),
Field(name='PDOP', type='UInt32', id=11),
Field(name='HDOP', type='UInt32', id=12),
Field(name='VDOP', type='UInt32', id=13),
Field(name='gps_accuracy', type='UInt32', id=14),
Field(name='ground_speed', type='UInt32', id=15),
Field(name='ground_track', type='UInt32', id=16),
Field(name='fix_quality', type='UInt32', id=17),
Field(name='fix_type', type='UInt32', id=18),
Field(name='sats_in_view', type='UInt32', id=19),
Field(name='sensor_id', type='UInt32', id=20),
Field(name='next_update', type='UInt32', id=21),
Field(name='seq_number', type='UInt32', id=22),
Field(name='precision_bits', type='UInt32', id=23),
]
class User(Message):
_fields=[
Field(name='id', type='String', id=1),
Field(name='long_name', type='String', id=2),
Field(name='short_name', type='String', id=3),
Field(name='macaddr', type='Bytes', id=4),
Field(name='hw_model', type='Enum', id=5, cls=HardwareModel),
Field(name='is_licensed', type='Bool', id=6),
Field(name='role', type='Enum', id=7, cls=Config.DeviceConfig.Role),
]
class RouteDiscovery(Message):
_fields=[
Field(name='route', type='Fixed32', id=1, repeated=True),
]
class Routing(Message):
class Error(Enum):
default = 0
NONE = 0
NO_ROUTE = 1
GOT_NAK = 2
TIMEOUT = 3
NO_INTERFACE = 4
MAX_RETRANSMIT = 5
NO_CHANNEL = 6
TOO_LARGE = 7
NO_RESPONSE = 8
DUTY_CYCLE_LIMIT = 9
BAD_REQUEST = 32
NOT_AUTHORIZED = 33
_fields=[
Field(name='route_request', type='Message', id=1, cls=RouteDiscovery),
Field(name='route_reply', type='Message', id=2, cls=RouteDiscovery),
Field(name='error_reason', type='Enum', id=3, cls=Error),
]
class Data(Message):
_fields=[
Field(name='portnum', type='Enum', id=1, cls=PortNum),
Field(name='payload', type='Bytes', id=2),
Field(name='want_response', type='Bool', id=3),
Field(name='dest', type='Fixed32', id=4),
Field(name='source', type='Fixed32', id=5),
Field(name='request_id', type='Fixed32', id=6),
Field(name='reply_id', type='Fixed32', id=7),
Field(name='emoji', type='Fixed32', id=8),
]
class Waypoint(Message):
_fields=[
Field(name='id', type='UInt32', id=1),
Field(name='latitude_i', type='SignedFixed32', id=2),
Field(name='longitude_i', type='SignedFixed32', id=3),
Field(name='expire', type='UInt32', id=4),
Field(name='locked_to', type='UInt32', id=5),
Field(name='name', type='String', id=6),
Field(name='description', type='String', id=7),
Field(name='icon', type='Fixed32', id=8),
]
class MqttClientProxyMessage(Message):
_fields=[
Field(name='topic', type='String', id=1),
Field(name='data', type='Bytes', id=2),
Field(name='text', type='String', id=3),
Field(name='retained', type='Bool', id=4),
]
class MeshPacket(Message):
class Priority(Enum):
default = 0
UNSET = 0
MIN = 1
BACKGROUND = 10
DEFAULT = 64
RELIABLE = 70
ACK = 120
MAX = 127
class Delayed(Enum):
default = 0
NO_DELAY = 0
DELAYED_BROADCAST = 1
DELAYED_DIRECT = 2
_fields=[
Field(name='from', type='Fixed32', id=1),
Field(name='to', type='Fixed32', id=2),
Field(name='channel', type='UInt32', id=3),
Field(name='decoded', type='Message', id=4, cls=Data),
Field(name='encrypted', type='Bytes', id=5),
Field(name='id', type='Fixed32', id=6),
Field(name='rx_time', type='Fixed32', id=7),
Field(name='rx_snr', type='Float', id=8),
Field(name='hop_limit', type='UInt32', id=9),
Field(name='want_ack', type='Bool', id=10),
Field(name='priority', type='Enum', id=11, cls=Priority),
Field(name='rx_rssi', type='Int32', id=12),
Field(name='delayed', type='Enum', id=13, cls=Delayed),
Field(name='via_mqtt', type='Bool', id=14),
Field(name='hop_start', type='UInt32', id=15),
]
class NodeInfo(Message):
_fields=[
Field(name='num', type='UInt32', id=1),
Field(name='user', type='Message', id=2, cls=User),
Field(name='position', type='Message', id=3, cls=Position),
Field(name='snr', type='Float', id=4),
Field(name='last_heard', type='Fixed32', id=5),
Field(name='device_metrics', type='Message', id=6, cls=DeviceMetrics),
Field(name='channel', type='UInt32', id=7),
Field(name='via_mqtt', type='Bool', id=8),
Field(name='hops_away', type='UInt32', id=9),
]
class MyNodeInfo(Message):
_fields=[
Field(name='my_node_num', type='UInt32', id=1),
Field(name='reboot_count', type='UInt32', id=8),
Field(name='min_app_version', type='UInt32', id=11),
]
class LogRecord(Message):
class Level(Enum):
default = 0
UNSET = 0
CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
TRACE = 5
_fields=[
Field(name='message', type='String', id=1),
Field(name='time', type='Fixed32', id=2),
Field(name='source', type='String', id=3),
Field(name='level', type='Enum', id=4, cls=Level),
]
class QueueStatus(Message):
_fields=[
Field(name='res', type='Int32', id=1),
Field(name='free', type='UInt32', id=2),
Field(name='maxlen', type='UInt32', id=3),
Field(name='mesh_packet_id', type='UInt32', id=4),
]
class FromRadio(Message):
_fields=[
Field(name='id', type='UInt32', id=1),
Field(name='packet', type='Message', id=2, cls=MeshPacket),
Field(name='my_info', type='Message', id=3, cls=MyNodeInfo),
Field(name='node_info', type='Message', id=4, cls=NodeInfo),
Field(name='config', type='Message', id=5, cls=Config),
Field(name='log_record', type='Message', id=6, cls=LogRecord),
Field(name='config_complete_id', type='UInt32', id=7),
Field(name='rebooted', type='Bool', id=8),
Field(name='moduleConfig', type='Message', id=9, cls=ModuleConfig),
Field(name='channel', type='Message', id=10, cls=Channel),
Field(name='queueStatus', type='Message', id=11, cls=QueueStatus),
Field(name='xmodemPacket', type='Message', id=12, cls=XModem),
Field(name='metadata', type='Message', id=13, cls=DeviceMetadata),
Field(name='mqttClientProxyMessage', type='Message', id=14, cls=MqttClientProxyMessage),
]
class ToRadio(Message):
_fields=[
Field(name='packet', type='Message', id=1, cls=MeshPacket),
Field(name='want_config_id', type='UInt32', id=3),
Field(name='disconnect', type='Bool', id=4),
Field(name='xmodemPacket', type='Message', id=5, cls=XModem),
Field(name='mqttClientProxyMessage', type='Message', id=6, cls=MqttClientProxyMessage),
Field(name='heartbeat', type='Message', id=7, cls=Heartbeat),
]
class Compressed(Message):
_fields=[
Field(name='portnum', type='Enum', id=1, cls=PortNum),
Field(name='data', type='Bytes', id=2),
]
class NeighborInfo(Message):
_fields=[
Field(name='node_id', type='UInt32', id=1),
Field(name='last_sent_by_id', type='UInt32', id=2),
Field(name='node_broadcast_interval_secs', type='UInt32', id=3),
Field(name='neighbors', type='Message', id=4, repeated=True, cls=Neighbor),
]
class Neighbor(Message):
_fields=[
Field(name='node_id', type='UInt32', id=1),
Field(name='snr', type='Float', id=2),
Field(name='last_rx_time', type='Fixed32', id=3),
Field(name='node_broadcast_interval_secs', type='UInt32', id=4),
]
class DeviceMetadata(Message):
_fields=[
Field(name='firmware_version', type='String', id=1),
Field(name='device_state_version', type='UInt32', id=2),
Field(name='canShutdown', type='Bool', id=3),
Field(name='hasWifi', type='Bool', id=4),
Field(name='hasBluetooth', type='Bool', id=5),
Field(name='hasEthernet', type='Bool', id=6),
Field(name='role', type='Enum', id=7, cls=Config.DeviceConfig.Role),
Field(name='position_flags', type='UInt32', id=8),
Field(name='hw_model', type='Enum', id=9, cls=HardwareModel),
Field(name='hasRemoteHardware', type='Bool', id=10),
]
class Heartbeat(Message):
_fields=[
]
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
class ModuleConfig(Message):
class MQTTConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='address', type='String', id=2),
Field(name='username', type='String', id=3),
Field(name='password', type='String', id=4),
Field(name='encryption_enabled', type='Bool', id=5),
Field(name='json_enabled', type='Bool', id=6),
Field(name='tls_enabled', type='Bool', id=7),
Field(name='root', type='String', id=8),
Field(name='proxy_to_client_enabled', type='Bool', id=9),
Field(name='map_reporting_enabled', type='Bool', id=10),
Field(name='map_report_settings', type='Message', id=11, cls=MapReportSettings),
]
class MapReportSettings(Message):
_fields=[
Field(name='publish_interval_secs', type='UInt32', id=1),
Field(name='position_precision', type='UInt32', id=2),
]
class RemoteHardwareConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='allow_undefined_pin_access', type='Bool', id=2),
Field(name='available_pins', type='Message', id=3, repeated=True, cls=.meshtastic.RemoteHardwarePin),
]
class NeighborInfoConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='update_interval', type='UInt32', id=2),
]
class DetectionSensorConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='minimum_broadcast_secs', type='UInt32', id=2),
Field(name='state_broadcast_secs', type='UInt32', id=3),
Field(name='send_bell', type='Bool', id=4),
Field(name='name', type='String', id=5),
Field(name='monitor_pin', type='UInt32', id=6),
Field(name='detection_triggered_high', type='Bool', id=7),
Field(name='use_pullup', type='Bool', id=8),
]
class AudioConfig(Message):
class Audio_Baud(Enum):
default = 0
CODEC2_DEFAULT = 0
CODEC2_3200 = 1
CODEC2_2400 = 2
CODEC2_1600 = 3
CODEC2_1400 = 4
CODEC2_1300 = 5
CODEC2_1200 = 6
CODEC2_700 = 7
CODEC2_700B = 8
_fields=[
Field(name='codec2_enabled', type='Bool', id=1),
Field(name='ptt_pin', type='UInt32', id=2),
Field(name='bitrate', type='Enum', id=3, cls=Audio_Baud),
Field(name='i2s_ws', type='UInt32', id=4),
Field(name='i2s_sd', type='UInt32', id=5),
Field(name='i2s_din', type='UInt32', id=6),
Field(name='i2s_sck', type='UInt32', id=7),
]
class PaxcounterConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='paxcounter_update_interval', type='UInt32', id=2),
]
class SerialConfig(Message):
class Serial_Baud(Enum):
default = 0
BAUD_DEFAULT = 0
BAUD_110 = 1
BAUD_300 = 2
BAUD_600 = 3
BAUD_1200 = 4
BAUD_2400 = 5
BAUD_4800 = 6
BAUD_9600 = 7
BAUD_19200 = 8
BAUD_38400 = 9
BAUD_57600 = 10
BAUD_115200 = 11
BAUD_230400 = 12
BAUD_460800 = 13
BAUD_576000 = 14
BAUD_921600 = 15
class Serial_Mode(Enum):
default = 0
DEFAULT = 0
SIMPLE = 1
PROTO = 2
TEXTMSG = 3
NMEA = 4
CALTOPO = 5
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='echo', type='Bool', id=2),
Field(name='rxd', type='UInt32', id=3),
Field(name='txd', type='UInt32', id=4),
Field(name='baud', type='Enum', id=5, cls=Serial_Baud),
Field(name='timeout', type='UInt32', id=6),
Field(name='mode', type='Enum', id=7, cls=Serial_Mode),
Field(name='override_console_serial_port', type='Bool', id=8),
]
class ExternalNotificationConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='output_ms', type='UInt32', id=2),
Field(name='output', type='UInt32', id=3),
Field(name='output_vibra', type='UInt32', id=8),
Field(name='output_buzzer', type='UInt32', id=9),
Field(name='active', type='Bool', id=4),
Field(name='alert_message', type='Bool', id=5),
Field(name='alert_message_vibra', type='Bool', id=10),
Field(name='alert_message_buzzer', type='Bool', id=11),
Field(name='alert_bell', type='Bool', id=6),
Field(name='alert_bell_vibra', type='Bool', id=12),
Field(name='alert_bell_buzzer', type='Bool', id=13),
Field(name='use_pwm', type='Bool', id=7),
Field(name='nag_timeout', type='UInt32', id=14),
Field(name='use_i2s_as_buzzer', type='Bool', id=15),
]
class StoreForwardConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='heartbeat', type='Bool', id=2),
Field(name='records', type='UInt32', id=3),
Field(name='history_return_max', type='UInt32', id=4),
Field(name='history_return_window', type='UInt32', id=5),
]
class RangeTestConfig(Message):
_fields=[
Field(name='enabled', type='Bool', id=1),
Field(name='sender', type='UInt32', id=2),
Field(name='save', type='Bool', id=3),
]
class TelemetryConfig(Message):
_fields=[
Field(name='device_update_interval', type='UInt32', id=1),
Field(name='environment_update_interval', type='UInt32', id=2),
Field(name='environment_measurement_enabled', type='Bool', id=3),
Field(name='environment_screen_enabled', type='Bool', id=4),
Field(name='environment_display_fahrenheit', type='Bool', id=5),
Field(name='air_quality_enabled', type='Bool', id=6),
Field(name='air_quality_interval', type='UInt32', id=7),
Field(name='power_measurement_enabled', type='Bool', id=8),
Field(name='power_update_interval', type='UInt32', id=9),
Field(name='power_screen_enabled', type='Bool', id=10),
]
class CannedMessageConfig(Message):
class InputEventChar(Enum):
default = 0
NONE = 0
UP = 17
DOWN = 18
LEFT = 19
RIGHT = 20
SELECT = 10
BACK = 27
CANCEL = 24
_fields=[
Field(name='rotary1_enabled', type='Bool', id=1),
Field(name='inputbroker_pin_a', type='UInt32', id=2),
Field(name='inputbroker_pin_b', type='UInt32', id=3),
Field(name='inputbroker_pin_press', type='UInt32', id=4),
Field(name='inputbroker_event_cw', type='Enum', id=5, cls=InputEventChar),
Field(name='inputbroker_event_ccw', type='Enum', id=6, cls=InputEventChar),
Field(name='inputbroker_event_press', type='Enum', id=7, cls=InputEventChar),
Field(name='updown1_enabled', type='Bool', id=8),
Field(name='enabled', type='Bool', id=9),
Field(name='allow_input_source', type='String', id=10),
Field(name='send_bell', type='Bool', id=11),
]
class AmbientLightingConfig(Message):
_fields=[
Field(name='led_state', type='Bool', id=1),
Field(name='current', type='UInt32', id=2),
Field(name='red', type='UInt32', id=3),
Field(name='green', type='UInt32', id=4),
Field(name='blue', type='UInt32', id=5),
]
_fields=[
Field(name='mqtt', type='Message', id=1, cls=MQTTConfig),
Field(name='serial', type='Message', id=2, cls=SerialConfig),
Field(name='external_notification', type='Message', id=3, cls=ExternalNotificationConfig),
Field(name='store_forward', type='Message', id=4, cls=StoreForwardConfig),
Field(name='range_test', type='Message', id=5, cls=RangeTestConfig),
Field(name='telemetry', type='Message', id=6, cls=TelemetryConfig),
Field(name='canned_message', type='Message', id=7, cls=CannedMessageConfig),
Field(name='audio', type='Message', id=8, cls=AudioConfig),
Field(name='remote_hardware', type='Message', id=9, cls=RemoteHardwareConfig),
Field(name='neighbor_info', type='Message', id=10, cls=NeighborInfoConfig),
Field(name='ambient_lighting', type='Message', id=11, cls=AmbientLightingConfig),
Field(name='detection_sensor', type='Message', id=12, cls=DetectionSensorConfig),
Field(name='paxcounter', type='Message', id=13, cls=PaxcounterConfig),
]
class RemoteHardwarePin(Message):
_fields=[
Field(name='gpio_pin', type='UInt32', id=1),
Field(name='name', type='String', id=2),
Field(name='type', type='Enum', id=3, cls=RemoteHardwarePinType),
]
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
class DeviceMetrics(Message):
_fields=[
Field(name='battery_level', type='UInt32', id=1),
Field(name='voltage', type='Float', id=2),
Field(name='channel_utilization', type='Float', id=3),
Field(name='air_util_tx', type='Float', id=4),
]
class EnvironmentMetrics(Message):
_fields=[
Field(name='temperature', type='Float', id=1),
Field(name='relative_humidity', type='Float', id=2),
Field(name='barometric_pressure', type='Float', id=3),
Field(name='gas_resistance', type='Float', id=4),
Field(name='voltage', type='Float', id=5),
Field(name='current', type='Float', id=6),
]
class PowerMetrics(Message):
_fields=[
Field(name='ch1_voltage', type='Float', id=1),
Field(name='ch1_current', type='Float', id=2),
Field(name='ch2_voltage', type='Float', id=3),
Field(name='ch2_current', type='Float', id=4),
Field(name='ch3_voltage', type='Float', id=5),
Field(name='ch3_current', type='Float', id=6),
]
class AirQualityMetrics(Message):
_fields=[
Field(name='pm10_standard', type='UInt32', id=1),
Field(name='pm25_standard', type='UInt32', id=2),
Field(name='pm100_standard', type='UInt32', id=3),
Field(name='pm10_environmental', type='UInt32', id=4),
Field(name='pm25_environmental', type='UInt32', id=5),
Field(name='pm100_environmental', type='UInt32', id=6),
Field(name='particles_03um', type='UInt32', id=7),
Field(name='particles_05um', type='UInt32', id=8),
Field(name='particles_10um', type='UInt32', id=9),
Field(name='particles_25um', type='UInt32', id=10),
Field(name='particles_50um', type='UInt32', id=11),
Field(name='particles_100um', type='UInt32', id=12),
]
class Telemetry(Message):
_fields=[
Field(name='time', type='Fixed32', id=1),
Field(name='device_metrics', type='Message', id=2, cls=DeviceMetrics),
Field(name='environment_metrics', type='Message', id=3, cls=EnvironmentMetrics),
Field(name='air_quality_metrics', type='Message', id=4, cls=AirQualityMetrics),
Field(name='power_metrics', type='Message', id=5, cls=PowerMetrics),
]
"""ATTENTION! This module is autogenerated! Don't edit!"""
from protobuf.uprotobuf import Message, Field, Enum
PACKAGE='meshtastic'
class XModem(Message):
class Control(Enum):
default = 0
NUL = 0
SOH = 1
STX = 2
EOT = 4
ACK = 6
NAK = 21
CAN = 24
CTRLZ = 26
_fields=[
Field(name='control', type='Enum', id=1, cls=Control),
Field(name='seq', type='UInt32', id=2),
Field(name='crc16', type='UInt32', id=3),
Field(name='buffer', type='Bytes', id=4),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment