Retrieving INA219 data (Current and Voltage)

Looking at the INA219Sensor.cpp source code I see:

bool INA219Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
measurement->variant.environment_metrics.voltage = ina219.getBusVoltage_V();
measurement->variant.environment_metrics.current = ina219.getCurrent_mA();
return true;
}

Which tells me that the current and voltage of the INA219 is in the ENVIRONMENTAL_MEASUREMENT_APP packet coming from the node.

Looking at the environmental_measurement_pb2.py

_descriptor.FieldDescriptor(
  name='voltage', full_name='EnvironmentalMeasurement.voltage', index=4,
  number=5, type=1, 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=5,
  number=6, type=1, 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),

I see where the voltage and current are listed. However when i receive a packet from the node that has the INA219 module on it, I am getting 0 VDC and 0 Amps, which i know is not true.

I am showing on the node that the
Sensor Options: Enabled
Show on device screen: Enabled
Display Fahrenheit: Enabled

I am seeing the current and voltage correctly on the OLED, but it is not in the data stream. As a matter of fact, ALL of the environmental variables from the telemetry stream are showing a value of 0.0.

Run the serial monitor when the device boots and look for the sensor detection

If it’s showing correctly on the screen, then the sensor should be detected already.

But, as I mentioned before and as stated in its README, meshtastic-mqtt only works with firmware 1.2, not with 2.0. In 2.0, there is no environmental_measurment_pb2.py anymore, it’s in telemetry_pb2.py. New generated files are here: python/meshtastic at master · meshtastic/python · GitHub

However, if you enable JSON, exactly what you’re trying to do with Python is already done in the firmware, but then it is published to the msh/2/json/# MQTT topic. Right now you probably set it to msh/2/c/# in meshtastic-mqtt, which then converts the protobufs to something readable, but if you look at the data in msh/2/json/#, it will be in plaintext already. Maybe check with the CLI (meshtastic - -info) if mqtt.json_enabled is really set to true.

Another benefit of letting the firmware do this is that if in a newer version any of these definitions change, you don’t have to update your Python files.

Setting the to msh/2/json/# when I send a text I get:

Connected to MQTT Broker!
<paho.mqtt.client.Client object at 0xb6569dc0>
None
<paho.mqtt.client.MQTTMessage object at 0xb60d08b0>

So how do I decode this? I have confirmed that json is “ON” on the node that I have the WiFi and such activated.

Your’re now printing an object. Probably you need to print msg.payload or something equivalent.

Or you need str(msg.payload.decode("utf-8"))), I’m not sure, never used this in Python.

Let me skin this cat another way. i am have a Mosquitto running in the background.

All i want to do is get all the traffic that comes across that node for the simple matter of being able to monitor the V and I of a remote node.

- and appologies…

I know ZERO about json, so anything you could point me to that would help me get this off the ground would be greatly appreciated!

Please slow down, I’m only trying to help, and I think you’re almost there.

JSON is just a human-readible format. Probably in def on_message in meshtastic-mqtt you can just directly use print(str(msg.payload.decode())).

I’ve only used MQTT with Home Assistant and openHAB, which can directly display any JSON data.

I would also recommend http://mqtt-explorer.com/. Then you’ll probably see directly how the data looks like.

Will bookmark that page…My goodness that was a test of human endurance…I’ve been working this for hours and hours…

thanks again…

1 Like