Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_pb2.py,deviceonly_pb2.py,apponly_pb2.py,remote_hardware_pb2.py,portnums_pb2.py,mesh_pb2.py,storeforward_pb2.py,cannedmessages_pb2.py,module_config_pb2.py,localonly_pb2.py,node.py
ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_pb2.py,deviceonly_pb2.py,apponly_pb2.py,remote_hardware_pb2.py,portnums_pb2.py,mesh_pb2.py,storeforward_pb2.py,cannedmessages_pb2.py,module_config_pb2.py,localonly_pb2.py,node.py,device_metadata_pb2.py



Expand All @@ -23,7 +23,7 @@ ignore-patterns=mqtt_pb2.py,channel_pb2.py,telemetry_pb2.py,admin_pb2.py,config_
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
#
disable=invalid-name,fixme,logging-fstring-interpolation,too-many-statements,too-many-branches,too-many-locals,no-member,f-string-without-interpolation,protected-access,no-self-use,pointless-string-statement,too-few-public-methods,broad-except,no-else-return,no-else-raise,bare-except,too-many-public-methods
disable=invalid-name,fixme,logging-fstring-interpolation,too-many-statements,too-many-branches,too-many-locals,no-member,f-string-without-interpolation,protected-access,pointless-string-statement,too-few-public-methods,broad-except,no-else-return,no-else-raise,bare-except,too-many-public-methods

[BASIC]

Expand Down
2 changes: 1 addition & 1 deletion meshtastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _receiveInfoUpdate(iface, asDict):
portnums_pb2.PortNum.ADMIN_APP: KnownProtocol("admin", admin_pb2.AdminMessage),
portnums_pb2.PortNum.ROUTING_APP: KnownProtocol("routing", mesh_pb2.Routing),
portnums_pb2.PortNum.TELEMETRY_APP: KnownProtocol("telemetry", telemetry_pb2.Telemetry),
portnums_pb2.PortNum.REMOTE_HARDWARE_APP: KnownProtocol("remotehw", remote_hardware_pb2.HardwareMessage),
portnums_pb2.PortNum.REMOTE_HARDWARE_APP: KnownProtocol("remotehw", remote_hardware_pb2.HardwareMessage),
portnums_pb2.PortNum.SIMULATOR_APP: KnownProtocol("simulator", mesh_pb2.Compressed),
portnums_pb2.PortNum.TRACEROUTE_APP: KnownProtocol("traceroute", mesh_pb2.RouteDiscovery)
}
21 changes: 11 additions & 10 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def onConnected(interface):
alt = 0
lat = 0.0
lon = 0.0
# TODO: use getNode(args.dest) to be able to set it for a remote node
# TODO: use getNode(args.dest) to be able to set it for a remote node
localConfig = interface.localNode.localConfig
if args.setalt:
alt = int(args.setalt)
Expand Down Expand Up @@ -282,17 +282,17 @@ def onConnected(interface):
if args.reboot_ota:
closeNow = True
waitForAckNak = True
interface.getNode(args.dest, False).rebootOTA();
interface.getNode(args.dest, False).rebootOTA()

if args.shutdown:
closeNow = True
waitForAckNak = True
interface.getNode(args.dest, False).shutdown()

if args.device_metadata:
closeNow = True
interface.getNode(args.dest).getMetadata()

if args.begin_edit:
closeNow = True
interface.getNode(args.dest, False).beginSettingsTransaction()
Expand Down Expand Up @@ -336,7 +336,7 @@ def onConnected(interface):
dest = str(args.traceroute)
print(f"Sending traceroute request to {dest} (this could take a while)")
interface.sendTraceRoute(dest, hopLimit)

if args.gpio_wrb or args.gpio_rd or args.gpio_watch:
if args.dest == BROADCAST_ADDR:
meshtastic.util.our_exit("Warning: Must use a destination node ID.")
Expand Down Expand Up @@ -454,7 +454,7 @@ def onConnected(interface):
for pref in configuration['config'][section]:
setPref(localConfig, f"{section}.{pref}", str(configuration['config'][section][pref]))
interface.getNode(args.dest).writeConfig(section)

if 'module_config' in configuration:
moduleConfig = interface.getNode(args.dest).moduleConfig
for section in configuration['module_config']:
Expand Down Expand Up @@ -648,6 +648,7 @@ def setSimpleConfig(modem_preset):
interface.close() # close the connection now, so that our app exits

def printConfig(config):
"""print configuration"""
objDesc = config.DESCRIPTOR
for config_section in objDesc.fields:
if config_section.name != "version":
Expand Down Expand Up @@ -720,7 +721,7 @@ def export_config(interface):
configObj["config"] = config
else:
configObj["config"] = config

module_config = MessageToDict(interface.localNode.moduleConfig)
if module_config:
# Convert inner keys to correct snake/camelCase
Expand Down Expand Up @@ -946,7 +947,7 @@ def initParser():
"--traceroute", help="Traceroute from connected node to a destination. " \
"You need pass the destination ID as argument, like " \
"this: '--traceroute !ba4bf9d0' " \
"Only nodes that have the encryption key can be traced.")
"Only nodes that have the encryption key can be traced.")

parser.add_argument(
"--reboot", help="Tell the destination node to reboot", action="store_true")
Expand All @@ -959,7 +960,7 @@ def initParser():

parser.add_argument(
"--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")

Expand All @@ -968,7 +969,7 @@ def initParser():

parser.add_argument(
"--factory-reset", help="Tell the destination node to install the default config", action="store_true")

parser.add_argument(
"--reset-nodedb", help="Tell the destination node clear its list of nodes", action="store_true")

Expand Down
22 changes: 13 additions & 9 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def getNode(self, nodeId, requestConfig=True):
n = meshtastic.node.Node(self, nodeId)
# Only request device settings and channel info when necessary
if requestConfig:
logging.debug("About to requestConfig")
n.requestConfig()
if not n.waitForConfig():
our_exit("Error: Timed out waiting for node config")
logging.debug("About to requestConfig")
n.requestConfig()
if not n.waitForConfig():
our_exit("Error: Timed out waiting for node config")
return n

def sendText(self, text: AnyStr,
Expand Down Expand Up @@ -291,25 +291,27 @@ def sendPosition(self, latitude=0.0, longitude=0.0, altitude=0, timeSec=0,
portNum=portnums_pb2.PortNum.POSITION_APP,
wantAck=wantAck,
wantResponse=wantResponse)

def sendTraceRoute(self, dest, hopLimit):
"""Send the trace route"""
r = mesh_pb2.RouteDiscovery()
self.sendData(r, destinationId=dest, portNum=portnums_pb2.PortNum.TRACEROUTE_APP,
wantResponse=True, onResponse=self.onResponseTraceRoute)
# extend timeout based on number of nodes, limit by configured hopLimit
waitFactor = min(len(self.nodes)-1, hopLimit)
waitFactor = min(len(self.nodes)-1, hopLimit)
self.waitForTraceRoute(waitFactor)

def onResponseTraceRoute(self, p):
"""on response for trace route"""
routeDiscovery = mesh_pb2.RouteDiscovery()
routeDiscovery.ParseFromString(p["decoded"]["payload"])
asDict = google.protobuf.json_format.MessageToDict(routeDiscovery)

print("Route traced:")
routeStr = self._nodeNumToId(p["to"])
if "route" in asDict:
for nodeNum in asDict["route"]:
routeStr += " --> " + self._nodeNumToId(nodeNum)
for nodeNum in asDict["route"]:
routeStr += " --> " + self._nodeNumToId(nodeNum)
routeStr += " --> " + self._nodeNumToId(p["from"])
print(routeStr)

Expand Down Expand Up @@ -384,11 +386,13 @@ def waitForConfig(self):
raise Exception("Timed out waiting for interface config")

def waitForAckNak(self):
"""Wait for the ack/nak"""
success = self._timeout.waitForAckNak(self._acknowledgment)
if not success:
raise Exception("Timed out waiting for an acknowledgment")

def waitForTraceRoute(self, waitFactor):
"""Wait for trace route"""
success = self._timeout.waitForTraceRoute(waitFactor, self._acknowledgment)
if not success:
raise Exception("Timed out waiting for traceroute")
Expand Down Expand Up @@ -745,7 +749,7 @@ def _handlePacketFromRadio(self, meshPacket, hack=False):
handler = self.responseHandlers.pop(requestId, None)
if handler is not None:
if not isAck or (isAck and handler.__name__ == "onAckNak"):
handler.callback(asDict)
handler.callback(asDict)

logging.debug(f"Publishing {topic}: packet={stripnl(asDict)} ")
publishingThread.queueWork(lambda: pub.sendMessage(
Expand Down
20 changes: 11 additions & 9 deletions meshtastic/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def waitForAckNak(self, acknowledgment, attrs=('receivedAck', 'receivedNak', 're
def waitForTraceRoute(self, waitFactor, acknowledgment, attr='receivedTraceRoute'):
"""Block until traceroute response is received. Returns True if traceroute response has been received."""
self.expireTimeout *= waitFactor
self.reset()
self.reset()
while time.time() < self.expireTime:
if getattr(acknowledgment, attr, None):
acknowledgment.reset()
Expand All @@ -183,16 +183,18 @@ def waitForTraceRoute(self, waitFactor, acknowledgment, attr='receivedTraceRoute
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
self.receivedTraceRoute = False
"""initialize"""
self.receivedAck = False
self.receivedNak = False
self.receivedImplAck = False
self.receivedTraceRoute = False

def reset(self):
self.receivedAck = False
self.receivedNak = False
self.receivedImplAck = False
self.receivedTraceRoute = False
"""reset"""
self.receivedAck = False
self.receivedNak = False
self.receivedImplAck = False
self.receivedTraceRoute = False

class DeferredExecution():
"""A thread that accepts closures to run, and runs them as they are received"""
Expand Down