Texts to and from arduino via serial

Ok here is the gist if what im hoping to do. Ive tried looking through the forum, and ive gotten topics that were close, but i didnt see anything exactly like what i was looking for:

So i want my arduino to be able to send a message (text string) to an attached node and have it sent through the mesh and have it appear as a normal text message to that node.

Is there a way to have the arduino define the specific node it is going to send to? Or can it only send to “broadcast all”?

Then i want whatever text messages that are sent to the node that the arduino is attached to, to be sent to the arduino as a string (to be displayed or used for whatever purpose).

Is this possible?

Ok, maybe i sort of just have a fundamental lack of understanding about what some of those mean. For example “protobuff” and “admin commands”.

I’m fairly mid-level when it comes to arduino programming, but im very new to meshtastic.

Take a look at the examples, it’s essentially what you want to do. You can interface your Arduino with your node utilizing the serial module. If you have the mode set to TXTMSG, the node will transmit the message received over serial from your arduino as a text message over the mesh (on the default channel).

1 Like

Ok, sounds good.
So where can i find these examples?

This might be a sort of “talk to me like i dont know what im doing” type of things. Well in some aspects.

Well actually i think i figured out how to have text from the arduino sent out to the mesh, and text from the mesh be sent to the arduino.

I just now want to be able to write an arduino program that essentially does:
“Send text string A to node 1, send text string B to node 2, and send text string C to Node 3”.

Im just not sure how to have the arduino essentially change the message destination. I know on both canned messaging and messaging through the phone, you can select individual nodes to send your messages to, but im not sure how to get the arduino to switch/choose the recipient. Is there a command string that i need to have the arduino send before it sends the message?

There are examples at the bottom of the docs link above.

As mentioned above, using the TXTMSG mode it will be broadcasted on the default channel. If you want to have full control, you need the PROTO mode, which exposes the full API as explained in the link above.
It seems there are not yet any examples for that mode, but this repository might give you a start. I think there’s not an example for constructing a text message, but here is how e.g. another packet is constructed and send to the radio: https://github.com/meshtastic/Meshtastic-arduino/blob/master/src/mt_protocol.cpp#L52.

1 Like

Ok, im trying hard on this one haha.

So i get this example here, and its almost exactly what i want (except i will input strings from different sensors or from pre-made messages):

But i want to send different messages to individual nodes.
Like for example, my dad, myself, and my brother each have a messanger i made for them with a cardKB and a heltec v3. We can decide who we are sending messages to by scrolling through using tab and the arrow keys. But i want the arduino to be able to essentially “scroll through” the contacts like i do with canned messaging.

It sounds like i need to do “protobuff” for that then?

I’m having some trouble looking through the examples and understanding what to do.

If i was to say edit that attached code to send to a certain node, it sounds like if i enabled protobuff on the node that is directly attached to my arduino, id have to edit the code like:

  1. Include protoBuffModule.h
  2. Include NodeInfoModule.h

But them im not 100% sure how to use those modules to set the message desitnation

You need a toRadio packet with a “packet” as payload variant. Probably something like this:

ToRadio toRadio = ToRadio_init_default;
toRadio.which_payloadVariant = ToRadio_packet_tag;

Then you want to set the “to” field to the node number of the destination, and all the other fields of the MeshPacket you want to set, see: https://github.com/meshtastic/protobufs/blob/master/meshtastic/mesh.proto#L747

I’ve never done this myself with an Arduino, so I’m afraid I can’t help you much further.

@Nikguy I opened a Pull Request to the Arduino client library with an example of how to send a text message to a certain destination using the SerialModule in PROTO mode. Can you maybe try this?

1 Like

Thanks, let me give it a try!

Im looking for that client example you said yoh added.

It’s the file examples/SendReceiveClient/SendReceiveClient.ino of that PR.

1 Like

Hi, Did you make it to work? Asking as I have the exact same need - to send a message to a specific node - at a specific channel.

@GUVWAF Thank you so much for providing example related to sending arduino message to a specific node and channel.

Just a quick question for you - to compensate for my incompetence:

Do I clone the entire library into "platformIO’ - to be able to build and run?

Yes, you can create a PlatformIO project that uses the library as dependency and put one of the example files in your src/ directory.

Alternatively, you can use the Arduino IDE, which would allow you to install the library and run an example directly.

OK. But using Arduino IDE then forces me to install nanodb?

Yes, and for PlatformIO you need the dependency as well.

Understood. Will try to get nanodb working then. Installation guide looked abit complicated. Will check again. Appreciate your support!