Python API via USB

SInce bluetooth/Android are a bit of a struggle to get & remain connected, I though that I would give the Python API a try - but I have very little experience with Python so the comment ```# By default will try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0 doesn’t help as I do not know how to change the path. Could anyone provide the alternative code to replace:

*import meshtastic*
*interface = meshtastic.StreamInterface()*
*interface.sendText("hello mesh")*
TTGO T-beam is connected OK at ttyUSB0 (CP2104 USB to UART).
Thanks in anticipation . . .
1 Like

I think what you’re looking for is something like this:

import meshtastic
interface = meshtastic.StreamInterface("/this/is/the/path/i/defined")
interface.sendText("hello mesh")

The documentation can be found on here: class StreamInterface

The Constructor code for that Class can be found here: StreamInterface init

1 Like

Thanks for the feedback, so now I’ve got past that difficulty.

But now __init__py is throwing up multiple syntax errors, of which this is just one of the reported code lines with a syntax error:
logging.error(“Subclass must provide toradio: {toRadio}”)

I have deleted all the logging.error lines, only to be greeted with an Exception error
"Multiple ports detected, you must specify a device, such as {ports[0].device}

I’m tempted to give up for now & come back in a few months time.

It looks like you might be trying to use this library with Python 2. It requires python3 (or later). pip will only install this on python 3 based systems, so I’m not sure why python 2 found it in its PYTHON_PATH.

(alternatively, can you post a longer log of the error messages - including the run of the python command and your code and I can help take a look)