From 848b52a4377e9dacfd1a490cc1f2c72286b00ba1 Mon Sep 17 00:00:00 2001
From: geeksville
class StreamInterface
-(devPath=None, debugOut=None, noProto=False)
+(devPath=None, debugOut=None, noProto=False, connectNow=True)
Interface class for meshtastic devices over a stream link (serial, TCP, etc)
@@ -1073,7 +1095,7 @@ debugOut {stream} – If a stream is provided, any debug serial output fromclass StreamInterface(MeshInterface):
"""Interface class for meshtastic devices over a stream link (serial, TCP, etc)"""
- def __init__(self, devPath=None, debugOut=None, noProto=False):
+ def __init__(self, devPath=None, debugOut=None, noProto=False, connectNow=True):
"""Constructor, opens a connection to a specified serial port, or if unspecified try to
find one Meshtastic device by probing
@@ -1104,14 +1126,24 @@ debugOut {stream} – If a stream is provided, any debug serial output from
devPath, 921600, exclusive=True, timeout=0.5)
self._rxThread = threading.Thread(target=self.__reader, args=())
+ MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto)
+
+ # Start the reader thread after superclass constructor completes init
+ if connectNow:
+ self.connect()
+
+ def connect(self):
+ """Connect to our radio
+
+ Normally this is called automatically by the constructor, but if you passed in connectNow=False you can manually
+ start the reading thread later.
+ """
+
# Send some bogus UART characters to force a sleeping device to wake
self.stream.write(bytes([START1, START1, START1, START1]))
self.stream.flush()
time.sleep(0.1) # wait 100ms to give device time to start running
- MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto)
-
- # Start the reader thread after superclass constructor completes init
self._rxThread.start()
def _sendToRadio(self, toRadio):
@@ -1205,6 +1237,32 @@ debugOut {stream} – If a stream is provided, any debug serial output from
self._rxThread.join() # wait for it to exit
+
+def connect(self)
+Connect to our radio
+Normally this is called automatically by the constructor, but if you passed in connectNow=False you can manually +start the reading thread later.
def connect(self):
+ """Connect to our radio
+
+ Normally this is called automatically by the constructor, but if you passed in connectNow=False you can manually
+ start the reading thread later.
+ """
+
+ # Send some bogus UART characters to force a sleeping device to wake
+ self.stream.write(bytes([START1, START1, START1, START1]))
+ self.stream.flush()
+ time.sleep(0.1) # wait 100ms to give device time to start running
+
+ self._rxThread.start()
+StreamInterface
-def testSend(fromInterface, toInterface, isBroadcast=False)
+def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False)
Sends one test packet between two nodes and then returns success or failure
@@ -299,7 +313,7 @@ toInterface {[type]} – [description]def testSend(fromInterface, toInterface, isBroadcast=False):
+def testSend(fromInterface, toInterface, isBroadcast=False, asBinary=False):
"""
Sends one test packet between two nodes and then returns success or failure
@@ -320,7 +334,12 @@ toInterface {[type]} – [description]
toNode = toInterface.myInfo.my_node_num
logging.info(f"Sending test packet from {fromNode} to {toNode}")
- fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=True)
+ wantAck = True
+ if not asBinary:
+ fromInterface.sendText(f"Test {testNumber}", toNode, wantAck=wantAck)
+ else:
+ fromInterface.sendData((f"Binary {testNumber}").encode(
+ "utf-8"), toNode, wantAck=wantAck)
time.sleep(45)
return (len(receivedPackets) >= 1)
@@ -342,7 +361,8 @@ toInterface {[type]} – [description]
global testNumber
testNumber = testNumber + 1
isBroadcast = True
- success = testSend(interfaces[0], interfaces[1], isBroadcast)
+ success = testSend(
+ interfaces[0], interfaces[1], isBroadcast, asBinary=(i % 2 == 0))
if not success:
numFail = numFail + 1
logging.error(
diff --git a/setup.py b/setup.py
index 7b5f696..84f43e5 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ with open("README.md", "r") as fh:
# This call to setup() does all the work
setup(
name="meshtastic",
- version="0.9.1",
+ version="0.9.2",
description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description,
long_description_content_type="text/markdown",