In a simple non-developer world, the Meshtastic python utility is great for simple integration to other IOT environments, but it would be even better if there was a command to allow us to retrieve the last known message (or messages).
This would allow a 3rd party app to easily be able to retrieve, respond to and reply to any messages, which is particularly useful where we are building IOT connected base stations.
Hmm. I think this might already be there. If before your app creates a SerialInterface instance, you subscribe for notification on new messages (via pub.subscribe(onReceive, “meshtastic.receive”)) you’ll be informed of any new received messages or any messages that arrived at the device before your app connected (up to a limit based on the amount of RAM on the device).
Ideally I’d like to be able to use the meshtastic command line to show me the last received message in a similar way it allows me to sendtext. for example, something like: meshtastic --gettext
to return the last message in the form of a json, showing sender, time sent and message.
That way it is easy to integrate with less open IOT systems where we can use meshtastic to pass data and react to data, just by using this command line tool.
To further clarify, I am a casual developer and still have no idea how to add “plug-ins” and every time someone mentions just using them, I shudder, so am staying well away from tweaking my own versions of meshtastic.
Instead I’m looking at the command line utility as a great tool for allowing connected devices to use meshtastic as a network to pass IOT data and react to inbound messages.
So, for me being able to use the meshtastic command line utility to sendtext works a treat, but I can’t look for and act on inbound messages and their content…
Understood. For a casual developer, I’d encourage you to try python and our python api (and we’ll help when you have questions). I’d bet it is even easier than parsing any text output from the command line tool.
In the meantime, I noticed there is a DeviceState field called rx_text_message that keeps the last received message. Is there a way we can let the Meshtastic CLI have a function to return that stored value?
If there is any way of voting this up - be a great feature to have. allow me to get messages easily off the devices and into a more useable environment.
I would love it as well. I have put my meshtastic device in a box with a small arm processor and have a permanent USB link between the two. The box is sitting on a remote pole to provide neighborhood coverage. Arm processor is POE powered so I can talk to it and run the python cli. What would be really useful is a way to get the messages off the meshtastic device, into my arm processor and then I can process them/ sort them as do as needed.
took a stab at this today from @mc-hamster advice and just exposing the messages as csv would be pretty simple. I may take another stab at cleaning this up here in the next week or so and implementing then fetching the file with python would be trivial. C++ is pretty new for me though so realistically idk how far out a releasable implementation from me would be
This would be really good. Being able to ask for last messages and getting few back would be great and allows the IoT service to regularly poll the meshtastic CLI and be able to work with those messages it knows it has not yet seen.
First post here. By the way, great job everyone. I’m trying to setup a Madison, WI wide network, and it’d be nice if a new node could request all the messages in memory from a neighboring node.
Also, I’m a big fan of the command line interface, so up-voting the get-all-messages from command line.
I still have lots of questions, but I am having good luck finding answers.
Thanks
Here’s what I came up with. I haven’t written any code since 25 years ago in a VisualBasic elective in college, so I’m sure it could be better.
import datetime
import meshtastic
from pubsub import pub
interface = meshtastic.SerialInterface()
def onReceive(packet, interface): # called when a packet arrives
sender = packet['fromId']
print(f"\nMessage from {interface.nodes[sender]['user']['longName']} ({interface.nodes[sender]['position']['latitude']}, {interface.nodes[sender]['position']['longitude']}) to {packet['toId']} at {datetime.datetime.fromtimestamp(packet['rxTime']).strftime('%Y-%m-%d %H:%M:%S')}:\n{packet['decoded']['text']}\n")
while True:
pub.subscribe(onReceive, "meshtastic.receive.text")
If you get rid of the while loop and run this code in the python shell, you can also type