diff --git a/.vscode/launch.json b/.vscode/launch.json index 6fecd89..9acb9dd 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": ["--debug", "--info"] + "args": ["--info"] }, { "name": "meshtastic debug", diff --git a/README.md b/README.md index fe9b755..7aa8e20 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ then run the following python3 code: 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. +interface.close() ``` For the rough notes/implementation plan see [TODO](https://github.com/meshtastic/Meshtastic-python/blob/master/TODO.md). diff --git a/bin/prerelease-tests.sh b/bin/prerelease-tests.sh new file mode 100755 index 0000000..b20380f --- /dev/null +++ b/bin/prerelease-tests.sh @@ -0,0 +1,7 @@ +set -e + +echo "Running (crude) prerelease tests to verify sanity" +python3 tests/hello_world.py +bin/run.sh --help +bin/run.sh --info +bin/run.sh --sendtext "Sanity complete" \ No newline at end of file diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 2d4f272..a5a2ac0 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -575,7 +575,8 @@ class StreamInterface(MeshInterface): self._rxBuf = bytes() # empty self._wantExit = False - self._rxThread = threading.Thread(target=self.__reader, args=(), daemon=True) + # FIXME, figure out why daemon=True causes reader thread to exit too early + self._rxThread = threading.Thread(target=self.__reader, args=()) MeshInterface.__init__(self, debugOut=debugOut, noProto=noProto) @@ -595,6 +596,7 @@ class StreamInterface(MeshInterface): time.sleep(0.1) # wait 100ms to give device time to start running self._rxThread.start() + self._waitConnected() def _disconnected(self): """We override the superclass implementation to close our port""" diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 063f268..df646b2 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -129,15 +129,18 @@ def onConnected(interface): closeNow = False # Should we drop the connection after we finish? try: if args.settime: + closeNow = True print("Setting device RTC time") # can include lat/long/alt etc: latitude = 37.5, longitude = -122.1 interface.sendPosition() if args.setowner: + closeNow = True print(f"Setting device owner to {args.setowner}") interface.setOwner(args.setowner) if args.sendtext: + closeNow = True print(f"Sending text message {args.sendtext} to {args.destOrAll}") interface.sendText(args.sendtext, args.destOrAll, wantAck=True, wantResponse=True) diff --git a/tests/hello_world.py b/tests/hello_world.py new file mode 100644 index 0000000..b938ec2 --- /dev/null +++ b/tests/hello_world.py @@ -0,0 +1,6 @@ +import meshtastic +import time + +interface = meshtastic.SerialInterface() # By default will try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0 +interface.sendText("hello mesh") +interface.close()