mirror of
https://github.com/meshtastic/python.git
synced 2025-12-31 03:47:55 -05:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d12776bb5f | ||
|
|
7829f6afca | ||
|
|
4bd10bc102 | ||
|
|
3821e02f09 | ||
|
|
97689da0b4 | ||
|
|
5c75e74bf9 | ||
|
|
388a46abf4 | ||
|
|
6b89fc81a1 | ||
|
|
f1df14ca92 | ||
|
|
7aff5e9ee5 |
@@ -177,6 +177,7 @@ def setPref(config, comp_name, valStr):
|
|||||||
def onConnected(interface):
|
def onConnected(interface):
|
||||||
"""Callback invoked when we connect to a radio"""
|
"""Callback invoked when we connect to a radio"""
|
||||||
closeNow = False # Should we drop the connection after we finish?
|
closeNow = False # Should we drop the connection after we finish?
|
||||||
|
waitForAckNak = False # Should we wait for an acknowledgment if we send to a remote node?
|
||||||
try:
|
try:
|
||||||
our_globals = Globals.getInstance()
|
our_globals = Globals.getInstance()
|
||||||
args = our_globals.get_args()
|
args = our_globals.get_args()
|
||||||
@@ -191,6 +192,7 @@ def onConnected(interface):
|
|||||||
alt = 0
|
alt = 0
|
||||||
lat = 0.0
|
lat = 0.0
|
||||||
lon = 0.0
|
lon = 0.0
|
||||||
|
# TODO: use getNode(args.dest) to be able to set it for a remote node
|
||||||
localConfig = interface.localNode.localConfig
|
localConfig = interface.localNode.localConfig
|
||||||
if args.setalt:
|
if args.setalt:
|
||||||
alt = int(args.setalt)
|
alt = int(args.setalt)
|
||||||
@@ -215,19 +217,22 @@ def onConnected(interface):
|
|||||||
|
|
||||||
if args.set_owner:
|
if args.set_owner:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
waitForAckNak = True
|
||||||
print(f"Setting device owner to {args.set_owner}")
|
print(f"Setting device owner to {args.set_owner}")
|
||||||
interface.getNode(args.dest).setOwner(args.set_owner)
|
interface.getNode(args.dest, False).setOwner(args.set_owner)
|
||||||
|
|
||||||
if args.set_owner_short:
|
if args.set_owner_short:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
waitForAckNak = True
|
||||||
print(f"Setting device owner short to {args.set_owner_short}")
|
print(f"Setting device owner short to {args.set_owner_short}")
|
||||||
interface.getNode(args.dest).setOwner(long_name=None, short_name=args.set_owner_short)
|
interface.getNode(args.dest, False).setOwner(long_name=None, short_name=args.set_owner_short)
|
||||||
|
|
||||||
# TODO: add to export-config and configure
|
# TODO: add to export-config and configure
|
||||||
if args.set_canned_message:
|
if args.set_canned_message:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
waitForAckNak = True
|
||||||
print(f"Setting canned plugin message to {args.set_canned_message}")
|
print(f"Setting canned plugin message to {args.set_canned_message}")
|
||||||
interface.getNode(args.dest).set_canned_message(args.set_canned_message)
|
interface.getNode(args.dest, False).set_canned_message(args.set_canned_message)
|
||||||
|
|
||||||
if args.pos_fields:
|
if args.pos_fields:
|
||||||
# If --pos-fields invoked with args, set position fields
|
# If --pos-fields invoked with args, set position fields
|
||||||
@@ -271,27 +276,40 @@ def onConnected(interface):
|
|||||||
|
|
||||||
if args.reboot:
|
if args.reboot:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).reboot()
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).reboot()
|
||||||
|
|
||||||
if args.reboot_ota:
|
if args.reboot_ota:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).rebootOTA();
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).rebootOTA();
|
||||||
|
|
||||||
if args.shutdown:
|
if args.shutdown:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).shutdown()
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).shutdown()
|
||||||
|
|
||||||
if args.device_metadata:
|
if args.device_metadata:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).getMetadata()
|
interface.getNode(args.dest).getMetadata()
|
||||||
|
|
||||||
|
if args.begin_edit:
|
||||||
|
closeNow = True
|
||||||
|
interface.getNode(args.dest, False).beginSettingsTransaction()
|
||||||
|
|
||||||
|
if args.commit_edit:
|
||||||
|
closeNow = True
|
||||||
|
interface.getNode(args.dest, False).commitSettingsTransaction()
|
||||||
|
|
||||||
if args.factory_reset:
|
if args.factory_reset:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).factoryReset()
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).factoryReset()
|
||||||
|
|
||||||
if args.reset_nodedb:
|
if args.reset_nodedb:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
interface.getNode(args.dest).resetNodeDb()
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).resetNodeDb()
|
||||||
|
|
||||||
if args.sendtext:
|
if args.sendtext:
|
||||||
closeNow = True
|
closeNow = True
|
||||||
@@ -376,17 +394,22 @@ def onConnected(interface):
|
|||||||
configuration = yaml.safe_load(file)
|
configuration = yaml.safe_load(file)
|
||||||
closeNow = True
|
closeNow = True
|
||||||
|
|
||||||
|
interface.getNode(args.dest, False).beginSettingsTransaction()
|
||||||
|
|
||||||
if 'owner' in configuration:
|
if 'owner' in configuration:
|
||||||
print(f"Setting device owner to {configuration['owner']}")
|
print(f"Setting device owner to {configuration['owner']}")
|
||||||
interface.getNode(args.dest).setOwner(configuration['owner'])
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).setOwner(configuration['owner'])
|
||||||
|
|
||||||
if 'owner_short' in configuration:
|
if 'owner_short' in configuration:
|
||||||
print(f"Setting device owner short to {configuration['owner_short']}")
|
print(f"Setting device owner short to {configuration['owner_short']}")
|
||||||
interface.getNode(args.dest).setOwner(long_name=None, short_name=configuration['owner_short'])
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).setOwner(long_name=None, short_name=configuration['owner_short'])
|
||||||
|
|
||||||
if 'ownerShort' in configuration:
|
if 'ownerShort' in configuration:
|
||||||
print(f"Setting device owner short to {configuration['ownerShort']}")
|
print(f"Setting device owner short to {configuration['ownerShort']}")
|
||||||
interface.getNode(args.dest).setOwner(long_name=None, short_name=configuration['ownerShort'])
|
waitForAckNak = True
|
||||||
|
interface.getNode(args.dest, False).setOwner(long_name=None, short_name=configuration['ownerShort'])
|
||||||
|
|
||||||
if 'channel_url' in configuration:
|
if 'channel_url' in configuration:
|
||||||
print("Setting channel url to", configuration['channel_url'])
|
print("Setting channel url to", configuration['channel_url'])
|
||||||
@@ -432,6 +455,7 @@ def onConnected(interface):
|
|||||||
setPref(moduleConfig, f"{section}.{pref}", str(configuration['module_config'][section][pref]))
|
setPref(moduleConfig, f"{section}.{pref}", str(configuration['module_config'][section][pref]))
|
||||||
interface.getNode(args.dest).writeConfig(section)
|
interface.getNode(args.dest).writeConfig(section)
|
||||||
|
|
||||||
|
interface.getNode(args.dest, False).commitSettingsTransaction()
|
||||||
print("Writing modified configuration to device")
|
print("Writing modified configuration to device")
|
||||||
|
|
||||||
if args.export_config:
|
if args.export_config:
|
||||||
@@ -604,6 +628,10 @@ def onConnected(interface):
|
|||||||
else:
|
else:
|
||||||
tunnel.Tunnel(interface, subnet=args.tunnel_net)
|
tunnel.Tunnel(interface, subnet=args.tunnel_net)
|
||||||
|
|
||||||
|
if args.dest != BROADCAST_ADDR and waitForAckNak:
|
||||||
|
print(f"Waiting for an acknowledgment from remote node (this could take a while)")
|
||||||
|
interface.getNode(args.dest, False).iface.waitForAckNak()
|
||||||
|
|
||||||
# if the user didn't ask for serial debugging output, we might want to exit after we've done our operation
|
# if the user didn't ask for serial debugging output, we might want to exit after we've done our operation
|
||||||
if (not args.seriallog) and closeNow:
|
if (not args.seriallog) and closeNow:
|
||||||
interface.close() # after running command then exit
|
interface.close() # after running command then exit
|
||||||
@@ -919,6 +947,12 @@ def initParser():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--device-metadata", help="Get the device metadata from the node", action="store_true")
|
"--device-metadata", help="Get the device metadata from the node", action="store_true")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--begin-edit", help="Tell the node to open a transaction to edit settings", action="store_true")
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--commit-edit", help="Tell the node to commit open settings transaction", action="store_true")
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--factory-reset", help="Tell the destination node to install the default config", action="store_true")
|
"--factory-reset", help="Tell the destination node to install the default config", action="store_true")
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from . import mesh_pb2 as mesh__pb2
|
|||||||
from . import module_config_pb2 as module__config__pb2
|
from . import module_config_pb2 as module__config__pb2
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x61\x64min.proto\x1a\rchannel.proto\x1a\x0c\x63onfig.proto\x1a\x15\x64\x65vice_metadata.proto\x1a\nmesh.proto\x1a\x13module_config.proto\"\xfa\n\n\x0c\x41\x64minMessage\x12\x1d\n\x13get_channel_request\x18\x01 \x01(\rH\x00\x12(\n\x14get_channel_response\x18\x02 \x01(\x0b\x32\x08.ChannelH\x00\x12\x1b\n\x11get_owner_request\x18\x03 \x01(\x08H\x00\x12#\n\x12get_owner_response\x18\x04 \x01(\x0b\x32\x05.UserH\x00\x12\x36\n\x12get_config_request\x18\x05 \x01(\x0e\x32\x18.AdminMessage.ConfigTypeH\x00\x12&\n\x13get_config_response\x18\x06 \x01(\x0b\x32\x07.ConfigH\x00\x12\x43\n\x19get_module_config_request\x18\x07 \x01(\x0e\x32\x1e.AdminMessage.ModuleConfigTypeH\x00\x12\x33\n\x1aget_module_config_response\x18\x08 \x01(\x0b\x32\r.ModuleConfigH\x00\x12\x34\n*get_canned_message_module_messages_request\x18\n \x01(\x08H\x00\x12\x35\n+get_canned_message_module_messages_response\x18\x0b \x01(\tH\x00\x12%\n\x1bget_device_metadata_request\x18\x0c \x01(\x08H\x00\x12\x37\n\x1cget_device_metadata_response\x18\r \x01(\x0b\x32\x0f.DeviceMetadataH\x00\x12\x1a\n\tset_owner\x18 \x01(\x0b\x32\x05.UserH\x00\x12\x1f\n\x0bset_channel\x18! \x01(\x0b\x32\x08.ChannelH\x00\x12\x1d\n\nset_config\x18\" \x01(\x0b\x32\x07.ConfigH\x00\x12*\n\x11set_module_config\x18# \x01(\x0b\x32\r.ModuleConfigH\x00\x12,\n\"set_canned_message_module_messages\x18$ \x01(\tH\x00\x12\x1c\n\x12\x63onfirm_set_config\x18@ \x01(\x08H\x00\x12#\n\x19\x63onfirm_set_module_config\x18\x41 \x01(\x08H\x00\x12\x1d\n\x13\x63onfirm_set_channel\x18\x42 \x01(\x08H\x00\x12\x1b\n\x11\x63onfirm_set_radio\x18\x43 \x01(\x08H\x00\x12\x1c\n\x12reboot_ota_seconds\x18_ \x01(\x05H\x00\x12\x18\n\x0e\x65xit_simulator\x18` \x01(\x08H\x00\x12\x18\n\x0ereboot_seconds\x18\x61 \x01(\x05H\x00\x12\x1a\n\x10shutdown_seconds\x18\x62 \x01(\x05H\x00\x12\x17\n\rfactory_reset\x18\x63 \x01(\x05H\x00\x12\x16\n\x0cnodedb_reset\x18\x64 \x01(\x05H\x00\"\x95\x01\n\nConfigType\x12\x11\n\rDEVICE_CONFIG\x10\x00\x12\x13\n\x0fPOSITION_CONFIG\x10\x01\x12\x10\n\x0cPOWER_CONFIG\x10\x02\x12\x12\n\x0eNETWORK_CONFIG\x10\x03\x12\x12\n\x0e\x44ISPLAY_CONFIG\x10\x04\x12\x0f\n\x0bLORA_CONFIG\x10\x05\x12\x14\n\x10\x42LUETOOTH_CONFIG\x10\x06\"\xb8\x01\n\x10ModuleConfigType\x12\x0f\n\x0bMQTT_CONFIG\x10\x00\x12\x11\n\rSERIAL_CONFIG\x10\x01\x12\x13\n\x0f\x45XTNOTIF_CONFIG\x10\x02\x12\x17\n\x13STOREFORWARD_CONFIG\x10\x03\x12\x14\n\x10RANGETEST_CONFIG\x10\x04\x12\x14\n\x10TELEMETRY_CONFIG\x10\x05\x12\x14\n\x10\x43\x41NNEDMSG_CONFIG\x10\x06\x12\x10\n\x0c\x41UDIO_CONFIG\x10\x07\x42\x11\n\x0fpayload_variantBH\n\x13\x63om.geeksville.meshB\x0b\x41\x64minProtosH\x03Z\"github.com/meshtastic/go/generatedb\x06proto3')
|
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x61\x64min.proto\x1a\rchannel.proto\x1a\x0c\x63onfig.proto\x1a\x15\x64\x65vice_metadata.proto\x1a\nmesh.proto\x1a\x13module_config.proto\"\xf6\n\n\x0c\x41\x64minMessage\x12\x1d\n\x13get_channel_request\x18\x01 \x01(\rH\x00\x12(\n\x14get_channel_response\x18\x02 \x01(\x0b\x32\x08.ChannelH\x00\x12\x1b\n\x11get_owner_request\x18\x03 \x01(\x08H\x00\x12#\n\x12get_owner_response\x18\x04 \x01(\x0b\x32\x05.UserH\x00\x12\x36\n\x12get_config_request\x18\x05 \x01(\x0e\x32\x18.AdminMessage.ConfigTypeH\x00\x12&\n\x13get_config_response\x18\x06 \x01(\x0b\x32\x07.ConfigH\x00\x12\x43\n\x19get_module_config_request\x18\x07 \x01(\x0e\x32\x1e.AdminMessage.ModuleConfigTypeH\x00\x12\x33\n\x1aget_module_config_response\x18\x08 \x01(\x0b\x32\r.ModuleConfigH\x00\x12\x34\n*get_canned_message_module_messages_request\x18\n \x01(\x08H\x00\x12\x35\n+get_canned_message_module_messages_response\x18\x0b \x01(\tH\x00\x12%\n\x1bget_device_metadata_request\x18\x0c \x01(\x08H\x00\x12\x37\n\x1cget_device_metadata_response\x18\r \x01(\x0b\x32\x0f.DeviceMetadataH\x00\x12\x1a\n\tset_owner\x18 \x01(\x0b\x32\x05.UserH\x00\x12\x1f\n\x0bset_channel\x18! \x01(\x0b\x32\x08.ChannelH\x00\x12\x1d\n\nset_config\x18\" \x01(\x0b\x32\x07.ConfigH\x00\x12*\n\x11set_module_config\x18# \x01(\x0b\x32\r.ModuleConfigH\x00\x12,\n\"set_canned_message_module_messages\x18$ \x01(\tH\x00\x12\x1d\n\x13\x62\x65gin_edit_settings\x18@ \x01(\x08H\x00\x12\x1e\n\x14\x63ommit_edit_settings\x18\x41 \x01(\x08H\x00\x12\x1d\n\x13\x63onfirm_set_channel\x18\x42 \x01(\x08H\x00\x12\x1b\n\x11\x63onfirm_set_radio\x18\x43 \x01(\x08H\x00\x12\x1c\n\x12reboot_ota_seconds\x18_ \x01(\x05H\x00\x12\x18\n\x0e\x65xit_simulator\x18` \x01(\x08H\x00\x12\x18\n\x0ereboot_seconds\x18\x61 \x01(\x05H\x00\x12\x1a\n\x10shutdown_seconds\x18\x62 \x01(\x05H\x00\x12\x17\n\rfactory_reset\x18\x63 \x01(\x05H\x00\x12\x16\n\x0cnodedb_reset\x18\x64 \x01(\x05H\x00\"\x95\x01\n\nConfigType\x12\x11\n\rDEVICE_CONFIG\x10\x00\x12\x13\n\x0fPOSITION_CONFIG\x10\x01\x12\x10\n\x0cPOWER_CONFIG\x10\x02\x12\x12\n\x0eNETWORK_CONFIG\x10\x03\x12\x12\n\x0e\x44ISPLAY_CONFIG\x10\x04\x12\x0f\n\x0bLORA_CONFIG\x10\x05\x12\x14\n\x10\x42LUETOOTH_CONFIG\x10\x06\"\xb8\x01\n\x10ModuleConfigType\x12\x0f\n\x0bMQTT_CONFIG\x10\x00\x12\x11\n\rSERIAL_CONFIG\x10\x01\x12\x13\n\x0f\x45XTNOTIF_CONFIG\x10\x02\x12\x17\n\x13STOREFORWARD_CONFIG\x10\x03\x12\x14\n\x10RANGETEST_CONFIG\x10\x04\x12\x14\n\x10TELEMETRY_CONFIG\x10\x05\x12\x14\n\x10\x43\x41NNEDMSG_CONFIG\x10\x06\x12\x10\n\x0c\x41UDIO_CONFIG\x10\x07\x42\x11\n\x0fpayload_variantBH\n\x13\x63om.geeksville.meshB\x0b\x41\x64minProtosH\x03Z\"github.com/meshtastic/go/generatedb\x06proto3')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -38,9 +38,9 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
|||||||
DESCRIPTOR._options = None
|
DESCRIPTOR._options = None
|
||||||
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\013AdminProtosH\003Z\"github.com/meshtastic/go/generated'
|
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\013AdminProtosH\003Z\"github.com/meshtastic/go/generated'
|
||||||
_ADMINMESSAGE._serialized_start=101
|
_ADMINMESSAGE._serialized_start=101
|
||||||
_ADMINMESSAGE._serialized_end=1503
|
_ADMINMESSAGE._serialized_end=1499
|
||||||
_ADMINMESSAGE_CONFIGTYPE._serialized_start=1148
|
_ADMINMESSAGE_CONFIGTYPE._serialized_start=1144
|
||||||
_ADMINMESSAGE_CONFIGTYPE._serialized_end=1297
|
_ADMINMESSAGE_CONFIGTYPE._serialized_end=1293
|
||||||
_ADMINMESSAGE_MODULECONFIGTYPE._serialized_start=1300
|
_ADMINMESSAGE_MODULECONFIGTYPE._serialized_start=1296
|
||||||
_ADMINMESSAGE_MODULECONFIGTYPE._serialized_end=1484
|
_ADMINMESSAGE_MODULECONFIGTYPE._serialized_end=1480
|
||||||
# @@protoc_insertion_point(module_scope)
|
# @@protoc_insertion_point(module_scope)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from google.protobuf.json_format import MessageToJson
|
|||||||
|
|
||||||
import meshtastic.node
|
import meshtastic.node
|
||||||
from meshtastic import portnums_pb2, mesh_pb2
|
from meshtastic import portnums_pb2, mesh_pb2
|
||||||
from meshtastic.util import stripnl, Timeout, our_exit, remove_keys_from_dict, convert_mac_addr
|
from meshtastic.util import stripnl, Timeout, Acknowledgment, our_exit, remove_keys_from_dict, convert_mac_addr
|
||||||
from meshtastic.__init__ import LOCAL_ADDR, BROADCAST_NUM, BROADCAST_ADDR, ResponseHandler, publishingThread, OUR_APP_VERSION, protocols
|
from meshtastic.__init__ import LOCAL_ADDR, BROADCAST_NUM, BROADCAST_ADDR, ResponseHandler, publishingThread, OUR_APP_VERSION, protocols
|
||||||
|
|
||||||
class MeshInterface:
|
class MeshInterface:
|
||||||
@@ -47,6 +47,7 @@ class MeshInterface:
|
|||||||
self.responseHandlers = {} # A map from request ID to the handler
|
self.responseHandlers = {} # A map from request ID to the handler
|
||||||
self.failure = None # If we've encountered a fatal exception it will be kept here
|
self.failure = None # If we've encountered a fatal exception it will be kept here
|
||||||
self._timeout = Timeout()
|
self._timeout = Timeout()
|
||||||
|
self._acknowledgment = Acknowledgment()
|
||||||
self.heartbeatTimer = None
|
self.heartbeatTimer = None
|
||||||
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it
|
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it
|
||||||
self.currentPacketId = random.randint(0, 0xffffffff)
|
self.currentPacketId = random.randint(0, 0xffffffff)
|
||||||
@@ -157,16 +158,18 @@ class MeshInterface:
|
|||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
def getNode(self, nodeId):
|
def getNode(self, nodeId, requestConfig=True):
|
||||||
"""Return a node object which contains device settings and channel info"""
|
"""Return a node object which contains device settings and channel info"""
|
||||||
if nodeId in (LOCAL_ADDR, BROADCAST_ADDR):
|
if nodeId in (LOCAL_ADDR, BROADCAST_ADDR):
|
||||||
return self.localNode
|
return self.localNode
|
||||||
else:
|
else:
|
||||||
n = meshtastic.node.Node(self, nodeId)
|
n = meshtastic.node.Node(self, nodeId)
|
||||||
logging.debug("About to requestConfig")
|
# Only request device settings and channel info when necessary
|
||||||
n.requestConfig()
|
if requestConfig:
|
||||||
if not n.waitForConfig():
|
logging.debug("About to requestConfig")
|
||||||
our_exit("Error: Timed out waiting for node config")
|
n.requestConfig()
|
||||||
|
if not n.waitForConfig():
|
||||||
|
our_exit("Error: Timed out waiting for node config")
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def sendText(self, text: AnyStr,
|
def sendText(self, text: AnyStr,
|
||||||
@@ -366,6 +369,11 @@ class MeshInterface:
|
|||||||
if not success:
|
if not success:
|
||||||
raise Exception("Timed out waiting for interface config")
|
raise Exception("Timed out waiting for interface config")
|
||||||
|
|
||||||
|
def waitForAckNak(self):
|
||||||
|
success = self._timeout.waitForAckNak(self._acknowledgment)
|
||||||
|
if not success:
|
||||||
|
raise Exception("Timed out waiting for an acknowledgment")
|
||||||
|
|
||||||
def getMyNodeInfo(self):
|
def getMyNodeInfo(self):
|
||||||
"""Get info about my node."""
|
"""Get info about my node."""
|
||||||
if self.myInfo is None:
|
if self.myInfo is None:
|
||||||
@@ -717,7 +725,8 @@ class MeshInterface:
|
|||||||
# we keep the responseHandler in dict until we get a non ack
|
# we keep the responseHandler in dict until we get a non ack
|
||||||
handler = self.responseHandlers.pop(requestId, None)
|
handler = self.responseHandlers.pop(requestId, None)
|
||||||
if handler is not None:
|
if handler is not None:
|
||||||
handler.callback(asDict)
|
if not isAck or (isAck and handler.__name__ == "onAckNak"):
|
||||||
|
handler.callback(asDict)
|
||||||
|
|
||||||
logging.debug(f"Publishing {topic}: packet={stripnl(asDict)} ")
|
logging.debug(f"Publishing {topic}: packet={stripnl(asDict)} ")
|
||||||
publishingThread.queueWork(lambda: pub.sendMessage(
|
publishingThread.queueWork(lambda: pub.sendMessage(
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -330,7 +330,12 @@ class Node:
|
|||||||
logging.debug(f'p.set_owner.long_name:{p.set_owner.long_name}:')
|
logging.debug(f'p.set_owner.long_name:{p.set_owner.long_name}:')
|
||||||
logging.debug(f'p.set_owner.short_name:{p.set_owner.short_name}:')
|
logging.debug(f'p.set_owner.short_name:{p.set_owner.short_name}:')
|
||||||
logging.debug(f'p.set_owner.is_licensed:{p.set_owner.is_licensed}')
|
logging.debug(f'p.set_owner.is_licensed:{p.set_owner.is_licensed}')
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def getURL(self, includeAll: bool = True):
|
def getURL(self, includeAll: bool = True):
|
||||||
"""The sharable URL that describes the current channel"""
|
"""The sharable URL that describes the current channel"""
|
||||||
@@ -448,7 +453,12 @@ class Node:
|
|||||||
p.set_canned_message_module_messages = chunk
|
p.set_canned_message_module_messages = chunk
|
||||||
|
|
||||||
logging.debug(f"Setting canned message '{chunk}' part {i+1}")
|
logging.debug(f"Setting canned message '{chunk}' part {i+1}")
|
||||||
self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def exitSimulator(self):
|
def exitSimulator(self):
|
||||||
"""Tell a simulator node to exit (this message
|
"""Tell a simulator node to exit (this message
|
||||||
@@ -465,7 +475,38 @@ class Node:
|
|||||||
p.reboot_seconds = secs
|
p.reboot_seconds = secs
|
||||||
logging.info(f"Telling node to reboot in {secs} seconds")
|
logging.info(f"Telling node to reboot in {secs} seconds")
|
||||||
|
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
|
def beginSettingsTransaction(self):
|
||||||
|
"""Tell the node to open a transaction to edit settings."""
|
||||||
|
p = admin_pb2.AdminMessage()
|
||||||
|
p.begin_edit_settings = True
|
||||||
|
logging.info(f"Telling open a transaction to edit settings")
|
||||||
|
|
||||||
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
|
def commitSettingsTransaction(self):
|
||||||
|
"""Tell the node to commit the open transaction for editing settings."""
|
||||||
|
p = admin_pb2.AdminMessage()
|
||||||
|
p.commit_edit_settings = True
|
||||||
|
logging.info(f"Telling node to commit open transaction for editing settings")
|
||||||
|
|
||||||
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def rebootOTA(self, secs: int = 10):
|
def rebootOTA(self, secs: int = 10):
|
||||||
"""Tell the node to reboot into factory firmware."""
|
"""Tell the node to reboot into factory firmware."""
|
||||||
@@ -473,7 +514,12 @@ class Node:
|
|||||||
p.reboot_ota_seconds = secs
|
p.reboot_ota_seconds = secs
|
||||||
logging.info(f"Telling node to reboot to OTA in {secs} seconds")
|
logging.info(f"Telling node to reboot to OTA in {secs} seconds")
|
||||||
|
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def shutdown(self, secs: int = 10):
|
def shutdown(self, secs: int = 10):
|
||||||
"""Tell the node to shutdown."""
|
"""Tell the node to shutdown."""
|
||||||
@@ -481,7 +527,12 @@ class Node:
|
|||||||
p.shutdown_seconds = secs
|
p.shutdown_seconds = secs
|
||||||
logging.info(f"Telling node to shutdown in {secs} seconds")
|
logging.info(f"Telling node to shutdown in {secs} seconds")
|
||||||
|
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def getMetadata(self, secs: int = 10):
|
def getMetadata(self, secs: int = 10):
|
||||||
"""Tell the node to shutdown."""
|
"""Tell the node to shutdown."""
|
||||||
@@ -497,7 +548,12 @@ class Node:
|
|||||||
p.factory_reset = True
|
p.factory_reset = True
|
||||||
logging.info(f"Telling node to factory reset")
|
logging.info(f"Telling node to factory reset")
|
||||||
|
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def resetNodeDb(self):
|
def resetNodeDb(self):
|
||||||
"""Tell the node to reset its list of nodes."""
|
"""Tell the node to reset its list of nodes."""
|
||||||
@@ -505,7 +561,12 @@ class Node:
|
|||||||
p.nodedb_reset = True
|
p.nodedb_reset = True
|
||||||
logging.info(f"Telling node to reset the NodeDB")
|
logging.info(f"Telling node to reset the NodeDB")
|
||||||
|
|
||||||
return self._sendAdmin(p)
|
# If sending to a remote node, wait for ACK/NAK
|
||||||
|
if self == self.iface.localNode:
|
||||||
|
onResponse = None
|
||||||
|
else:
|
||||||
|
onResponse = self.onAckNak
|
||||||
|
return self._sendAdmin(p, onResponse=onResponse)
|
||||||
|
|
||||||
def _fixupChannels(self):
|
def _fixupChannels(self):
|
||||||
"""Fixup indexes and add disabled channels as needed"""
|
"""Fixup indexes and add disabled channels as needed"""
|
||||||
@@ -589,6 +650,18 @@ class Node:
|
|||||||
else:
|
else:
|
||||||
self._requestChannel(index + 1)
|
self._requestChannel(index + 1)
|
||||||
|
|
||||||
|
def onAckNak(self, p):
|
||||||
|
if p["decoded"]["routing"]["errorReason"] != "NONE":
|
||||||
|
print(f'Received a NAK, error reason: {p["decoded"]["routing"]["errorReason"]}')
|
||||||
|
self.iface._acknowledgment.receivedNak = True
|
||||||
|
else:
|
||||||
|
if int(p["from"]) == self.iface.localNode.nodeNum:
|
||||||
|
print(f'Received an implicit ACK. Packet will likely arrive, but cannot be guaranteed.')
|
||||||
|
self.iface._acknowledgment.receivedImplAck = True
|
||||||
|
else:
|
||||||
|
print(f'Received an ACK.')
|
||||||
|
self.iface._acknowledgment.receivedAck = True
|
||||||
|
|
||||||
def _requestChannel(self, channelNum: int):
|
def _requestChannel(self, channelNum: int):
|
||||||
"""Done with initial config messages, now send regular
|
"""Done with initial config messages, now send regular
|
||||||
MeshPackets to ask for settings"""
|
MeshPackets to ask for settings"""
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ _sym_db = _symbol_database.Default()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0ftelemetry.proto\"i\n\rDeviceMetrics\x12\x15\n\rbattery_level\x18\x01 \x01(\r\x12\x0f\n\x07voltage\x18\x02 \x01(\x02\x12\x1b\n\x13\x63hannel_utilization\x18\x03 \x01(\x02\x12\x13\n\x0b\x61ir_util_tx\x18\x04 \x01(\x02\"\x9b\x01\n\x12\x45nvironmentMetrics\x12\x13\n\x0btemperature\x18\x01 \x01(\x02\x12\x19\n\x11relative_humidity\x18\x02 \x01(\x02\x12\x1b\n\x13\x62\x61rometric_pressure\x18\x03 \x01(\x02\x12\x16\n\x0egas_resistance\x18\x04 \x01(\x02\x12\x0f\n\x07voltage\x18\x05 \x01(\x02\x12\x0f\n\x07\x63urrent\x18\x06 \x01(\x02\"\x82\x01\n\tTelemetry\x12\x0c\n\x04time\x18\x01 \x01(\x07\x12(\n\x0e\x64\x65vice_metrics\x18\x02 \x01(\x0b\x32\x0e.DeviceMetricsH\x00\x12\x32\n\x13\x65nvironment_metrics\x18\x03 \x01(\x0b\x32\x13.EnvironmentMetricsH\x00\x42\t\n\x07variant*\xa0\x01\n\x13TelemetrySensorType\x12\x10\n\x0cSENSOR_UNSET\x10\x00\x12\n\n\x06\x42ME280\x10\x01\x12\n\n\x06\x42ME680\x10\x02\x12\x0b\n\x07MCP9808\x10\x03\x12\n\n\x06INA260\x10\x04\x12\n\n\x06INA219\x10\x05\x12\n\n\x06\x42MP280\x10\x06\x12\t\n\x05SHTC3\x10\x07\x12\t\n\x05LPS22\x10\x08\x12\x0b\n\x07QMC6310\x10\t\x12\x0b\n\x07QMI8658\x10\nBL\n\x13\x63om.geeksville.meshB\x0fTelemetryProtosH\x03Z\"github.com/meshtastic/go/generatedb\x06proto3')
|
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0ftelemetry.proto\"i\n\rDeviceMetrics\x12\x15\n\rbattery_level\x18\x01 \x01(\r\x12\x0f\n\x07voltage\x18\x02 \x01(\x02\x12\x1b\n\x13\x63hannel_utilization\x18\x03 \x01(\x02\x12\x13\n\x0b\x61ir_util_tx\x18\x04 \x01(\x02\"\x9b\x01\n\x12\x45nvironmentMetrics\x12\x13\n\x0btemperature\x18\x01 \x01(\x02\x12\x19\n\x11relative_humidity\x18\x02 \x01(\x02\x12\x1b\n\x13\x62\x61rometric_pressure\x18\x03 \x01(\x02\x12\x16\n\x0egas_resistance\x18\x04 \x01(\x02\x12\x0f\n\x07voltage\x18\x05 \x01(\x02\x12\x0f\n\x07\x63urrent\x18\x06 \x01(\x02\"\x82\x01\n\tTelemetry\x12\x0c\n\x04time\x18\x01 \x01(\x07\x12(\n\x0e\x64\x65vice_metrics\x18\x02 \x01(\x0b\x32\x0e.DeviceMetricsH\x00\x12\x32\n\x13\x65nvironment_metrics\x18\x03 \x01(\x0b\x32\x13.EnvironmentMetricsH\x00\x42\t\n\x07variant*\xae\x01\n\x13TelemetrySensorType\x12\x10\n\x0cSENSOR_UNSET\x10\x00\x12\n\n\x06\x42ME280\x10\x01\x12\n\n\x06\x42ME680\x10\x02\x12\x0b\n\x07MCP9808\x10\x03\x12\n\n\x06INA260\x10\x04\x12\n\n\x06INA219\x10\x05\x12\n\n\x06\x42MP280\x10\x06\x12\t\n\x05SHTC3\x10\x07\x12\t\n\x05LPS22\x10\x08\x12\x0b\n\x07QMC6310\x10\t\x12\x0b\n\x07QMI8658\x10\n\x12\x0c\n\x08QMC5883L\x10\x0b\x42L\n\x13\x63om.geeksville.meshB\x0fTelemetryProtosH\x03Z\"github.com/meshtastic/go/generatedb\x06proto3')
|
||||||
|
|
||||||
_TELEMETRYSENSORTYPE = DESCRIPTOR.enum_types_by_name['TelemetrySensorType']
|
_TELEMETRYSENSORTYPE = DESCRIPTOR.enum_types_by_name['TelemetrySensorType']
|
||||||
TelemetrySensorType = enum_type_wrapper.EnumTypeWrapper(_TELEMETRYSENSORTYPE)
|
TelemetrySensorType = enum_type_wrapper.EnumTypeWrapper(_TELEMETRYSENSORTYPE)
|
||||||
@@ -30,6 +30,7 @@ SHTC3 = 7
|
|||||||
LPS22 = 8
|
LPS22 = 8
|
||||||
QMC6310 = 9
|
QMC6310 = 9
|
||||||
QMI8658 = 10
|
QMI8658 = 10
|
||||||
|
QMC5883L = 11
|
||||||
|
|
||||||
|
|
||||||
_DEVICEMETRICS = DESCRIPTOR.message_types_by_name['DeviceMetrics']
|
_DEVICEMETRICS = DESCRIPTOR.message_types_by_name['DeviceMetrics']
|
||||||
@@ -61,7 +62,7 @@ if _descriptor._USE_C_DESCRIPTORS == False:
|
|||||||
DESCRIPTOR._options = None
|
DESCRIPTOR._options = None
|
||||||
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\017TelemetryProtosH\003Z\"github.com/meshtastic/go/generated'
|
DESCRIPTOR._serialized_options = b'\n\023com.geeksville.meshB\017TelemetryProtosH\003Z\"github.com/meshtastic/go/generated'
|
||||||
_TELEMETRYSENSORTYPE._serialized_start=418
|
_TELEMETRYSENSORTYPE._serialized_start=418
|
||||||
_TELEMETRYSENSORTYPE._serialized_end=578
|
_TELEMETRYSENSORTYPE._serialized_end=592
|
||||||
_DEVICEMETRICS._serialized_start=19
|
_DEVICEMETRICS._serialized_start=19
|
||||||
_DEVICEMETRICS._serialized_end=124
|
_DEVICEMETRICS._serialized_end=124
|
||||||
_ENVIRONMENTMETRICS._serialized_start=127
|
_ENVIRONMENTMETRICS._serialized_start=127
|
||||||
|
|||||||
@@ -159,6 +159,27 @@ class Timeout:
|
|||||||
time.sleep(self.sleepInterval)
|
time.sleep(self.sleepInterval)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def waitForAckNak(self, acknowledgment, attrs=('receivedAck', 'receivedNak', 'receivedImplAck')):
|
||||||
|
"""Block until an ACK or NAK has been received. Returns True if ACK or NAK has been received."""
|
||||||
|
self.reset()
|
||||||
|
while time.time() < self.expireTime:
|
||||||
|
if any(map(lambda a: getattr(acknowledgment, a, None), attrs)):
|
||||||
|
acknowledgment.reset()
|
||||||
|
return True
|
||||||
|
time.sleep(self.sleepInterval)
|
||||||
|
return False
|
||||||
|
|
||||||
|
class Acknowledgment:
|
||||||
|
"A class that records which type of acknowledgment was just received, if any."
|
||||||
|
def __init__(self):
|
||||||
|
self.receivedAck = False
|
||||||
|
self.receivedNak = False
|
||||||
|
self.receivedImplAck = False
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.receivedAck = False
|
||||||
|
self.receivedNak = False
|
||||||
|
self.receivedImplAck = False
|
||||||
|
|
||||||
class DeferredExecution():
|
class DeferredExecution():
|
||||||
"""A thread that accepts closures to run, and runs them as they are received"""
|
"""A thread that accepts closures to run, and runs them as they are received"""
|
||||||
|
|||||||
Submodule protobufs updated: c82c15aac7...24874086e3
2
setup.py
2
setup.py
@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
|
|||||||
# This call to setup() does all the work
|
# This call to setup() does all the work
|
||||||
setup(
|
setup(
|
||||||
name="meshtastic",
|
name="meshtastic",
|
||||||
version="2.0.2",
|
version="2.0.3",
|
||||||
description="Python API & client shell for talking to Meshtastic devices",
|
description="Python API & client shell for talking to Meshtastic devices",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|||||||
Reference in New Issue
Block a user