Unable to receive data over the mesh

Hey there,
I am trying to slightly modify the existing firmware for my T-beamV1.1 so that a node can read an ADC pin and send its value over the mesh. I know that we can use the serial module to read sensor data but I find that using an external MCU to just read an ADC pin is wasting a lot of power.

On the serial monitor, I can see that my node is trying to send the message but it is not being shown on the screen of my receiver. This is a relevant piece of the serial log of the transmitter.

DEBUG | ??:??:?? 14 Moisture reading is 303
DEBUG | ??:??:?? 14 Msg from=0x55c6a2a0, id=0x5412efc9, msg=/
DEBUG | ??:??:?? 14 Update DB node 0x55c6a2a0, rx_time=0, channel=0
DEBUG | ??:??:?? 14 handleReceived(LOCAL) (id=0x5412efc9 fr=0xa0 to=0xff, WantAck=0, HopLim=3 Ch=0x0 Portnum=0)
DEBUG | ??:??:?? 14 No modules interested in portnum=0, src=LOCAL
DEBUG | ??:??:?? 14 localSend to channel 0
DEBUG | ??:??:?? 14 Add packet record (id=0x5412efc9 fr=0xa0 to=0xff, WantAck=0, HopLim=3 Ch=0x0 Portnum=0)
DEBUG | ??:??:?? 14 Expanding short PSK #1
DEBUG | ??:??:?? 14 Using AES128 key!
DEBUG | ??:??:?? 14 ESP32 crypt fr=55c6a2a0, num=5412efc9, numBytes=6!
DEBUG | ??:??:?? 14 enqueuing for send (id=0x5412efc9 fr=0xa0 to=0xff, WantAck=0, HopLim=3 Ch=0x8 encrypted)
DEBUG | ??:??:?? 14 txGood=0,rxGood=0,rxBad=0
DEBUG | ??:??:?? 24 [Power] Battery: usbPower=1, isCharging=0, batMv=0, batPct=0
DEBUG | ??:??:?? 24 [RadioIf] Completed sending (id=0x5412efc8 fr=0xa0 to=0xff, WantAck=0, HopLim=3 Ch=0x8 encrypted priority=64)

DEBUG | ??:??:?? 14 No modules interested in portnum=0, src=LOCAL makes me think that the none of the receivers want to pick up the message for some reason??

This is the piece of code I am using to send the message.

const int sensor_pin = 2;
int moist;
moist = analogRead(sensor_pin);
LOG_DEBUG(“Moisture reading is %d\n”, moist);
meshtastic_MeshPacket *z = router->allocForSending(); //Initialize packet struct
z->decoded.payload.size = sizeof(moist);
memcpy(z->decoded.payload.bytes, &moist, z->decoded.payload.size);
LOG_DEBUG(“Msg from=0x%0x, id=0x%x, msg=%.*s\n”, z->from, z->id, z->decoded.payload.size, z->decoded.payload.bytes);
service.sendToMesh(z);

Any help would be appreciated. Cheers.

The serial module is the right way to do this, the routing in the firmware is really complex and the serial module is there to keep you out of that complexity. This “shortcut” is likely to cost you a bunch of time.

If you only need one analogRead per message and you send it only once every couple minutes, I think this is OK to do it the main firmware. If you need continuous sampling and averaging, you’d for sure be better off using the SerialModule.

When you allocate a MeshPacket, you have to set the Portnum, otherwise other devices and clients don’t know how to handle it. E.g. if you want to send a text message, you need to set z->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; (and convert your reading to a string).

1 Like

Sorry for the late reply, but this worked for me.

If you only need one analogRead per message and you send it only once every couple minutes, I think this is OK to do it the main firmware.

This is exactly what I am trying to do. Sampling and transmitting every few minutes. Additionally, I would also like to dynamically set the sampling/transmitting parameters later down the line.

1 Like

I would like to do something similar, send analog values two or three times a day. I assume this needs to be done in the firmware directly and not using one of the configuration via bluetooth or web interface. Any help would be appreciated. Thanks.

Once your sensor reads a value, you need to create a MeshPacket that contains the relevant information for packet transfer. Currently I am doing this through the router client.

meshtastic_MeshPacket *z = router->allocForSending(); //Initialize packet structure
z->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
z->decoded.payload.size = sensed_value.size() + 1;
memcpy(z->decoded.payload.bytes, bcd, z->decoded.payload.size);

Once the packet is initialized simply send it over the mesh with service.sendToMesh(z, RX_SOURCE_LOCAL);

You can use LOG_DEBUG by opening up the serial port for debugging purposes. I am using MSYS for that. Just run tio -e -b 38400 -f none /dev/myserialport and it would open up the serial interface.

Make sure that whatever message you want to send is a string.

You can put this entire sensing and transmission in loop() of the main.cpp. There you should be able to control your sensing and transmission rates.