mirror of
https://github.com/meshtastic/python.git
synced 2026-01-18 12:48:03 -05:00
make --sendtext command work
This commit is contained in:
@@ -111,11 +111,10 @@ class MeshInterface:
|
||||
|
||||
if isinstance(destinationId, int):
|
||||
nodeNum = destinationId
|
||||
elif nodeNum == BROADCAST_ADDR:
|
||||
elif destinationId == BROADCAST_ADDR:
|
||||
nodeNum = 255
|
||||
else:
|
||||
raise Exception(
|
||||
"invalid destination addr, we don't yet support nodeid lookup")
|
||||
nodeNum = self.nodes[destinationId].num
|
||||
|
||||
meshPacket.to = nodeNum
|
||||
toRadio.packet.CopyFrom(meshPacket)
|
||||
|
||||
@@ -19,28 +19,36 @@ def onReceive(packet):
|
||||
def onConnection(interface, topic=pub.AUTO_TOPIC):
|
||||
"""Callback invoked when we connect/disconnect from a radio"""
|
||||
print(f"Connection changed: {topic.getName()}")
|
||||
|
||||
|
||||
def onConnected(interface):
|
||||
"""Callback invoked when we connect to a radio"""
|
||||
global args
|
||||
if topic.getName() == "meshtastic.connection.established":
|
||||
try:
|
||||
if args.setpref:
|
||||
name = args.setpref[0]
|
||||
val = int(args.setpref[1])
|
||||
setattr(interface.radioConfig.preferences, name, val)
|
||||
print("Writing modified preferences to device...")
|
||||
interface.writeConfig()
|
||||
print("Connected to radio...")
|
||||
try:
|
||||
if args.sendtext:
|
||||
print(f"Sending text message {args.sendtext} to {args.dest}")
|
||||
interface.sendText(args.sendtext, args.dest)
|
||||
|
||||
if args.info:
|
||||
print(interface.myInfo)
|
||||
print(interface.radioConfig)
|
||||
print("Nodes in mesh:")
|
||||
for n in interface.nodes.values():
|
||||
asDict = google.protobuf.json_format.MessageToJson(n)
|
||||
print(asDict)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
if args.setpref:
|
||||
name = args.setpref[0]
|
||||
val = int(args.setpref[1])
|
||||
setattr(interface.radioConfig.preferences, name, val)
|
||||
print("Writing modified preferences to device...")
|
||||
interface.writeConfig()
|
||||
|
||||
if args.info or args.setpref:
|
||||
interface.close() # after running command then exit
|
||||
if args.info:
|
||||
print(interface.myInfo)
|
||||
print(interface.radioConfig)
|
||||
print("Nodes in mesh:")
|
||||
for n in interface.nodes.values():
|
||||
asDict = google.protobuf.json_format.MessageToJson(n)
|
||||
print(asDict)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
if args.info or args.setpref or args.sendtext:
|
||||
interface.close() # after running command then exit
|
||||
|
||||
|
||||
def onNode(node):
|
||||
@@ -51,7 +59,8 @@ def onNode(node):
|
||||
def subscribe():
|
||||
"""Subscribe to the topics the user probably wants to see, prints output to stdout"""
|
||||
pub.subscribe(onReceive, "meshtastic.receive")
|
||||
pub.subscribe(onConnection, "meshtastic.connection")
|
||||
# pub.subscribe(onConnection, "meshtastic.connection")
|
||||
pub.subscribe(onConnected, "meshtastic.connection.established")
|
||||
pub.subscribe(onNode, "meshtastic.node")
|
||||
|
||||
|
||||
@@ -74,6 +83,12 @@ def main():
|
||||
|
||||
parser.add_argument("--setpref", help="Set a preferences field", nargs=2)
|
||||
|
||||
parser.add_argument(
|
||||
"--dest", help="The destination node id for the --send commands, if not set 'all' is assumed", default="all")
|
||||
|
||||
parser.add_argument(
|
||||
"--sendtext", help="Send a text message")
|
||||
|
||||
parser.add_argument("--debug", help="Show API library debug log messages",
|
||||
action="store_true")
|
||||
|
||||
@@ -84,7 +99,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
if args.info or args.setpref:
|
||||
if args.info or args.setpref or args.sendtext:
|
||||
args.seriallog = "none" # assume no debug output in this case
|
||||
|
||||
if args.test:
|
||||
|
||||
Reference in New Issue
Block a user