Error while executing the code given in github README.md

import meshtastic
interface = meshtastic.SerialInterface() # By default will try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0
interface.sendText(“hello mesh”) # or sendData to send binary data, see documentations for other options.

*** I am getting the following error, when I am running this code on my Ubuntu 20.04 terminal. Although I installed meshtastic library correctly. Meshtastic device is also connected with my Laptop***

Here is the error message:

Traceback (most recent call last):
File “mesh.py”, line 3, in
interface.sendText(“hello mesh”)
File “/usr/local/lib/python3.8/dist-packages/meshtastic/init.py”, line 130, in sendText
return self.sendData(text.encode(“utf-8”), destinationId,
File “/usr/local/lib/python3.8/dist-packages/meshtastic/init.py”, line 146, in sendData
return self.sendPacket(meshPacket, destinationId, wantAck=wantAck)
File “/usr/local/lib/python3.8/dist-packages/meshtastic/init.py”, line 198, in sendPacket
meshPacket.id = self._generatePacketId()
File “/usr/local/lib/python3.8/dist-packages/meshtastic/init.py”, line 294, in _generatePacketId
raise Exception(“Not connected yet, can not generate packet”)
Exception: Not connected yet, can not generate packet

1 Like

Welcome to this forum aricric!
Together with the python package there is a command line executable called meshtastic installed. Can that find your device?
You can use
meshtastic --help
for options
If you run meshtastic without parameters it will print the serial log from your device and show all messages received by the device.
If meshtastic fails to locate your device you need to specify which usbport to use both in your python code and/or as a parameter to the meshtastic binary.

1 Like

ooh - I just took a look and you are correct. You’ve found a side effect of a bit of sloppy threading on my part. If the user is lucky (apparently most are lucky), the thread doing the serial reading would get in and do the initial node db download from the device before the call to sendText.

For a quick hack of a fix, add “time.sleep(1)” after the interface creation. I’m making a real fix now and it will be in the meshtastic-python release I make later today. I’m also adding this example as a sanity test before each new release.

btw: if you are curious, this is the fix:

Now it is giving the following error, please tell me the remedy

ERROR:root:The device firmware is too old to work with this version of the python library. Please update firmware to 1.20 or later

1 Like

you can ignore that message, I should have made it only a warning. A new version of the device code is coming today or tomorrow and there are some new features the python api checks for.

2 Likes

Thanks a lot Kevin

2 Likes