mirror of
https://github.com/meshtastic/python.git
synced 2026-03-02 05:30:10 -05:00
0.5.4 optionally add want_response to text message sends (see example):
meshtastic --debug --sendtext hello attn @claesg
This commit is contained in:
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -35,6 +35,14 @@
|
||||
"module": "meshtastic",
|
||||
"justMyCode": true,
|
||||
"args": ["--test"]
|
||||
},
|
||||
{
|
||||
"name": "meshtastic sendtext",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"module": "meshtastic",
|
||||
"justMyCode": true,
|
||||
"args": ["--debug", "--sendtext", "pytest"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class MeshInterface:
|
||||
self.isConnected = False
|
||||
self._startConfig()
|
||||
|
||||
def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False):
|
||||
def sendText(self, text, destinationId=BROADCAST_ADDR, wantAck=False, wantResponse=False):
|
||||
"""Send a utf8 string to some other node, if the node has a display it will also be shown on the device.
|
||||
|
||||
Arguments:
|
||||
@@ -97,13 +97,14 @@ class MeshInterface:
|
||||
destinationId {nodeId or nodeNum} -- where to send this message (default: {BROADCAST_ADDR})
|
||||
"""
|
||||
self.sendData(text.encode("utf-8"), destinationId,
|
||||
dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck)
|
||||
dataType=mesh_pb2.Data.CLEAR_TEXT, wantAck=wantAck, wantResponse=wantResponse)
|
||||
|
||||
def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False):
|
||||
def sendData(self, byteData, destinationId=BROADCAST_ADDR, dataType=mesh_pb2.Data.OPAQUE, wantAck=False, wantResponse=False):
|
||||
"""Send a data packet to some other node"""
|
||||
meshPacket = mesh_pb2.MeshPacket()
|
||||
meshPacket.decoded.data.payload = byteData
|
||||
meshPacket.decoded.data.typ = dataType
|
||||
meshPacket.decoded.want_response = wantResponse
|
||||
self.sendPacket(meshPacket, destinationId, wantAck=wantAck)
|
||||
|
||||
def sendPacket(self, meshPacket, destinationId=BROADCAST_ADDR, wantAck=False):
|
||||
|
||||
@@ -11,10 +11,14 @@ import google.protobuf.json_format
|
||||
args = None
|
||||
|
||||
|
||||
def onReceive(packet):
|
||||
def onReceive(packet, interface):
|
||||
"""Callback invoked when a packet arrives"""
|
||||
print(f"Received: {packet}")
|
||||
|
||||
# Exit once we receive a reply
|
||||
if args.sendtext and packet["to"] == interface.myInfo.my_node_num:
|
||||
interface.close() # after running command then exit
|
||||
|
||||
|
||||
def onConnection(interface, topic=pub.AUTO_TOPIC):
|
||||
"""Callback invoked when we connect/disconnect from a radio"""
|
||||
@@ -28,7 +32,8 @@ def onConnected(interface):
|
||||
try:
|
||||
if args.sendtext:
|
||||
print(f"Sending text message {args.sendtext} to {args.dest}")
|
||||
interface.sendText(args.sendtext, args.dest)
|
||||
interface.sendText(args.sendtext, args.dest,
|
||||
wantAck=True, wantResponse=True)
|
||||
|
||||
if args.setpref:
|
||||
name = args.setpref[0]
|
||||
@@ -46,7 +51,7 @@ def onConnected(interface):
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
if args.info or args.setpref or args.sendtext:
|
||||
if args.info or args.setpref:
|
||||
interface.close() # after running command then exit
|
||||
|
||||
|
||||
|
||||
2
setup.py
2
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.5.3",
|
||||
version="0.5.4",
|
||||
description="Python API & client shell for talking to Meshtastic devices",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
Reference in New Issue
Block a user