Where can I find the source code - Specifically the Environmental Measurement packet structure?

I am trying to add the new features of gas_resistance, voltage and current data points to the meshtastic-mqtt python program.

It appears that the temp format is wrong (showing 9.3e+21 for temp, which I am assuming is wrong LOL), and the three new listed above.

I have zero experience with Python Proto3 Descriptors and need some direction.

To my knowledge, all the sources are here:

All the messages are defined here GitHub - meshtastic/protobufs: Protobuf definitions for the Meshtastic project

OK, so in EnvironmentalTelemetry.cpp i found:

LOG_INFO(
    "(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, voltage=%f\n",
    m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current,
    m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity,
    m.variant.environment_metrics.temperature, m.variant.environment_metrics.voltage);

Which tells me the order in which the values are sent (barometric pressure, then current and so forth) across the mesh.

So looking at the environmental_measurement_pb2.py python source code I set up the descriptor in that same order:

_ENVIRONMENTALMEASUREMENT = _descriptor.Descriptor(
name=‘EnvironmentalMeasurement’,
full_name=‘EnvironmentalMeasurement’,
filename=None,
file=DESCRIPTOR,
containing_type=None,
create_key=_descriptor._internal_create_key,
fields=[
_descriptor.FieldDescriptor(
name=‘barometric_pressure’, full_name=‘EnvironmentalMeasurement.barometric_pressure’, index=0,
number=1, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name=‘current’, full_name=‘EnvironmentalMeasurement.current’, index=1,
number=2, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name=‘gas_resistance’, full_name=‘EnvironmentalMeasurement.gas_resistance’, index=2,
number=3, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name=‘relative_humidity’, full_name=‘EnvironmentalMeasurement.relative_humidity’, index=3,
number=4, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name=‘temperature’, full_name=‘EnvironmentalMeasurement.temperature’, index=4,
number=5, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
_descriptor.FieldDescriptor(
name=‘voltage’, full_name=‘EnvironmentalMeasurement.voltage’, index=5,
number=6, type=2, cpp_type=6, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key),
],

Since the values are sent as float across the mesh, the descriptor is set up to accept floats (type=2).

The results that I see are:
Pressure: 0.0
Current: 0.0 (the OLED is showing -1mA)
Gas Resistance: 9.542455448153696e+21
Rel Humidity: 0.0
Temp: 0.0
Voltage: 0.0 (OLED shows 1V)

Do I have a clear understanding of how the values are being sent?

Is the Gas Resistance realistic given there is no board to get a reading from (I have ONLY the INA219 board (current/voltage monitor) installed on the T-Beam)?

Is it safe to assume that the temps are sent across the mesh in Centigrade (I have the "Convert to Fahrenheit’ set)?

Since I am reading 1V at -1mA on the OLED shouldn’t I be seeing the same thing in the telemetry stream?

The battery information for the device is on device metrics, those power values are for an INA219

1 Like

I’m not following.

Are you saying the values that are transmitted over thresh above is for the INTERNAL battery or are those values for the INA219 board?

There are several telemetry messages, device, environment and air quality

The power values in environment are for a ina219, the ones in device are for the internal battery / charger

The meshtastic-mqtt mentions in the README:

Note: only functions with old v1.2 meshtastic device firmware
The newer version 2 of the device firmware supports JSON MQTT packets natively, so there is no need for this script.

Wouldn’t it be easier for you to enable JSON for MQTT and process the packets from there?

The file environmental_measurement_pb2.py is automatically generated from the (v1.2) protobufs definitions as shown in line 2:

# Generated by the protocol buffer compiler.  DO NOT EDIT!

If you want to make it work using this, it would be better to generate the necessary files using this script.

I am not seeing any difference when I enable or disable the JSON mode on the node that is forwarding the packets.

Do I have to enable ALL nodes in order for that to work?

No, that shouldn’t be necessary. Did you enable uplink on the channel and configured a server, user, and password? Can you check if encryption enabled is set to false?

I am seeing data come across the Mosquitto feed. I am getting data into the meshtastic-mqtt.

So all i need to do is make the node that is doing the MQTT set to JSON, correct?

Yes, and then it should publish it to the topic msh/2/json/<channelID>/<nodeID>.
Maybe you can use an MQTT explorer to find this.

I am getting the packets into the mosquito and then I to meshtastic-mqtt.

That’s where I start running into problems. For example: when I send a text it comes out as a routing_app. It’s little things like that.

The routing packet is the ack (or failure) after you sent a message, I would familiarize yourself with the different protobuf messages.