Python API setup issues

Hi Guys,

I have a T-BEAM V1.0 w/NEO-6M running Meshtastic 0.6.8 and the Python API 0.6.7

As I seem to have been caught out by the current bluetooth issue where by it constantly shows a connected but sleeping in the App I thought I’d try out the python API but I get the following (same issue if I run a sudo)

pi@pi-nas:~/meshtastic $  meshtastic --debug
WARNING: No module named 'pexpect'
DEBUG:root:Connecting to /dev/ttyUSB0
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/serial/", line 310, in _reconfigure_port
    fcntl.flock(self.fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
BlockingIOError: [Errno 11] Resource temporarily unavailable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/.local/bin/meshtastic", line 10, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/meshtastic/", line 128, in main
    client = StreamInterface(args.device, debugOut=logfile)
  File "/home/pi/.local/lib/python3.7/site-packages/meshtastic/", line 345, in __init__
    devPath, 921600, exclusive=True, timeout=0.5)
  File "/usr/lib/python3/dist-packages/serial/", line 240, in __init__
  File "/usr/lib/python3/dist-packages/serial/", line 272, in open
  File "/usr/lib/python3/dist-packages/serial/", line 312, in _reconfigure_port
    raise SerialException(msg.errno, "Could not exclusively lock port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 11] Could not exclusively lock port /dev/ttyUSB0: [Errno 11] Resource temporarily unavailable
pi@pi-nas:~/meshtastic $ 

Any ideas or suggestions?


1 Like

hmm two things.

Not your problem but your error message makes me realize we’re forgetting to ask for a library one of our libs need:

for the time being can you run “pip install pexpect”? I’ll update the next release of the lib to include that dependency automatically.

For the real problem it sounds like your user account might not have permissions to access /dev/ttyUSB0. Is it possible some other thread already has that port open? Can you try “sudo meshtastic --debug” and see what happens?

OK so this was user error!!

“pip install pexpect” solved part 1 and part 2 was because I had IDE open that was hogging the port; although it should not have been.


1 Like

Making some progress… Messages are sometimes sent via the meshtastic executable but basit pythin has some issues:

pi@pi-nas:~/meshtastic $ python3 
ERROR:root:Node not found for fromId
ERROR:root:Error handling FromRadio, possibly corrupted? 40
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/meshtastic/", line 404, in __reader
  File "/home/pi/.local/lib/python3.7/site-packages/meshtastic/", line 194, in _handleFromRadio
  File "/home/pi/.local/lib/python3.7/site-packages/meshtastic/", line 252, in _handlePacketFromRadio
    self._nodesByNum[asDict["from"]]["position"] = p
KeyError: 40
ERROR:root:Node not found for fromId
ERROR:root:Node not found for fromId
ERROR:root:Error handling FromRadio, possibly corrupted? 40

Python code:

import meshtastic
import time

import meshtastic
interface = meshtastic.StreamInterface() # 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.

for i in range(20):
        interface.sendText("hello mesh "+str(i)) # or sendData to send binary data, see documentations for other options.

re: messages sometimes don’t arrive
I think you’ll be happier if you change to:

interface.sendText("hello mesh "+str(i), wantAck=True)

(That requests reliable datagram send. Though perhaps I should change that to be the default?)

ERROR:root:Node not found for fromId
Hmm - I’m trying to think of why this could occur. When the client starts it asks the node for its node db. Is it possible you woke the node only after connecting it to the computer? If that’s the case, I think there is a device improvement we should make:

I appear to be having the same error issue, although the message was sent.

Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license()” for more information.

import meshtastic
interface = meshtastic.StreamInterface()
interface.sendText(“hello mesh”)
ERROR:root:Node not found for fromId
ERROR:root:Error handling FromRadio, possibly corrupted? 2883442996
Traceback (most recent call last):
File “C:\Python\Python37\lib\site-packages\”, line 407, in __reader
File "C:\Python\Python37\lib\site-packages\meshtastic_init
.py", line 197, in _handleFromRadio
File "C:\Python\Python37\lib\site-packages\meshtastic_init
.py", line 261, in _handlePacketFromRadio
self._nodesByNum[asDict[“from”]][“user”] = u
KeyError: 2883442996

Just speculating. Based on my findings with the debugger I think this is when the remote node sends a message and it is the first time the api has seen this fromId. I guess a quick reset of the remote node would trigger a ‘here I am’ message to all other nodes and the api would get to know the remoteId and add it to the internal datastructure.

For me I have updated my python to use:

interface.sendText("hello mesh "+str(i), wantAck=True)

But I don’t see the message being recieved by the second device

Thanks. I’m still slowly working on it, but the reset didn’t help.