How i can send the sensor data via mqtt?

Like the title say, i have 2 tbeams, 1 heltec and 1 ttgo lora esp32, the thing is, 1 device is configured as gateway while the others are nodes, so, 3 devices had a dht11 sensor connected, when i try to send the temperature data from the gateway to mqtt, i cant see the data, i mean, i subscribe to the topic: msh/1/json/# but i cant see any temperature data, is possible to send the temperature data that i get from the dht11 sensor to mqtt? If yes, how i can do that? Pls help :pleading_face:

1 Like

The data sent over MQTT is in a binary format called “protobuf”, that’s how the meshtastic nodes do all of their communication (over the Lora, bluetooth, serial, IP, etc). That means what you are seeing on the MQTT topic is a binary payload that needs to be decoded. There is also another complication because the protobuf is usually encrypted.

I have a python script that is able to decode the protobuf and republish the data in a more easily used format (I use it to monitor my node batteries in Grafana).

But I haven’t taken the time to figure out the encryption yet, so my hacky solution is to modify the device firmware to do the decryption on-device, then publish decrypted protobufs to another MQTT topic. It’s quite easy to modify the firmware to do that, there’s a few lines of code in Router.cpp that you need to move. Do you have VS Code and Platform IO? Then just clone the meshtastic-device repo, make the change, possibly set the board type in platformio.ini, then hit go and it will just work.

My python script is on GitHub: GitHub - joshpirihi/meshtastic-mqtt: A python script to translate Meshtastic MQTT location messages into a format that Traccar can understand. Also publishes battery % to its own topic (eg for Grafana)

1 Like

Thatnks for the response, and no, i dont have vs code and platformio installed, do you know how to build the firmware for any device? Sorry im lost in these type of things :cry:

Well I have some tbeams here which I think I could do a build and send it to you. But it’s pretty easy to do it yourself, vs code and platform io make it very very easy. If you’re keen to give that a go I can talk you through it, start by installing vs code, then platform io.

How have you been flashing your devices?

Also, are you using your own MQTT server, or the default meshtastic one?

1 Like

curious if instead you tried disabling crypto like: meshtastic --setchan psk 0

im using the meshtastic mqtt server and im flashing the devices via the firmware that provides meshtastic in github

ooh I didn’t think of that. I’ve got it working for now, but I do think this should be easier (getting easily readable data on an MQTT server).

@hcorrea4 My approach would be to get your own MQTT server running, then try disabling crypto as @AndreK suggests. Then I can modify my python script to support environmental messages. I run my MQTT and that python script from my Home Assistant that’s running on a raspberry pi.

Do you have something similar (like an RPi or old computer you can put home assistant on)? Home Assistant is the easiest way to get MQTT and the graphs that take a project like this to the next level.

It’s a bit of a steep learning curve initially, but this may be the start of a glorious rabbit hole that will consume you for years to come :wink:

1 Like

but that script lets you send and see the temperature and humidity data coming out from the tbeam to the mqtt server? because that is my main problem, since I need to send that data through mqtt and with that I can already show it in a dashboard as grafana, I’m sorry if you already answered it, but I would appreciate it if you explain me better

It sounds like you’re using the environment measurement plugin? My script doesn’t support that right now but I think it’d be pretty straight forward to make it work.

I am also hoping to get a feature added to the device firmware to allow it to publish plain values straight to MQTT on its own.

I’m putting up another relay node this week hopefully, I’ll make sure I put a temperature sensor on it. Then won’t be able to put off making it work on my MQTT and grafana. I’ll let you know once I get it working on my mesh

Yeah im using the environment plugin because i don’t know other method to catch the temperature and humidity from the dht11 sensor, maybe you know some kind of way that how i can send the data from the sensor to the mqtt server?

Im new here but decrypting the packet should not be too hard. It is AES128 or AES256 bit and you have the psk for the channel from doing a meshtastic --info. You should be able to decode it with any of the openssl libraries.

Im new and could be wrong here but that should not be too difficult to decode.