From 0e6ad7632b829aafe86ec47da58a0bc2b45320cd Mon Sep 17 00:00:00 2001
From: Kevin Hester Given an array of PSK bytes, decode them into a human readable (but privacy protecting) string The sharable URL that describes the current channel The sharable URL that describes the current channel Show human readable description of our channelsFunctions
+
+def pskToString(psk: bytes)
+
+Expand source code
+
+
+def pskToString(psk: bytes):
+ """Given an array of PSK bytes, decode them into a human readable (but privacy protecting) string"""
+ if len(psk) == 0:
+ return "unencrypted"
+ elif len(psk) == 1:
+ b = psk[0]
+ if b == 0:
+ return "unencrypted"
+ elif b == 1:
+ return "default"
+ else:
+ return f"simple{b - 1}"
+ else:
+ return "secret"
def waitForSet(target, sleep=0.1, maxsecs=20, attrs=())
+ print(" " + stripnl(n))
def showInfo(self):
"""Show human readable summary about this object"""
- print(self.myInfo)
- print("Nodes in mesh:")
+ print(f"My info: {stripnl(MessageToJson(self.myInfo))}")
+ print("\nNodes in mesh:")
for n in self.nodes.values():
- print(stripnl(n))
@@ -2326,15 +2374,24 @@ wantResponse – True if you want the service on the other side to send an a
self.radioConfig = None
self.channels = None
- def showInfo(self):
- """Show human readable description of our node"""
- print(self.radioConfig)
+ def showChannels(self):
+ """Show human readable description of our channels"""
print("Channels:")
for c in self.channels:
if c.role != channel_pb2.Channel.Role.DISABLED:
- cStr = MessageToJson(c.settings).replace("\n", "")
- print(f" {channel_pb2.Channel.Role.Name(c.role)} {cStr}")
- print(f"\nChannel URL {self.channelURL}")
+ cStr = stripnl(MessageToJson(c.settings))
+ print(f" {channel_pb2.Channel.Role.Name(c.role)} psk={pskToString(c.settings.psk)} {cStr}")
+ publicURL = self.getURL(includeAll = False)
+ adminURL = self.getURL(includeAll = True)
+ print(f"\nPrimary channel URL: {publicURL}")
+ if adminURL != publicURL:
+ print(f"Complete URL (includes all channels): {adminURL}")
+
+ def showInfo(self):
+ """Show human readable description of our node"""
+ print(f"Preferences: {stripnl(MessageToJson(self.radioConfig.preferences))}\n")
+ self.showChannels()
+
def requestConfig(self):
"""
@@ -2444,14 +2501,13 @@ wantResponse – True if you want the service on the other side to send an a
return self._sendAdmin(p)
- @property
- def channelURL(self):
+ def getURL(self, includeAll: bool = True):
"""The sharable URL that describes the current channel
"""
# Only keep the primary/secondary channels, assume primary is first
channelSet = apponly_pb2.ChannelSet()
for c in self.channels:
- if c.role != channel_pb2.Channel.Role.DISABLED:
+ if c.role == channel_pb2.Channel.Role.PRIMARY or (includeAll and c.role == channel_pb2.Channel.Role.SECONDARY):
channelSet.settings.append(c.settings)
bytes = channelSet.SerializeToString()
s = base64.urlsafe_b64encode(bytes).decode('ascii')
@@ -2587,30 +2643,6 @@ wantResponse – True if you want the service on the other side to send an a
onResponse=onResponse,
channelIndex=adminIndex)
-Instance variables
-
-
var channelURL
-Expand source code
-
-
-@property
-def channelURL(self):
- """The sharable URL that describes the current channel
- """
- # Only keep the primary/secondary channels, assume primary is first
- channelSet = apponly_pb2.ChannelSet()
- for c in self.channels:
- if c.role != channel_pb2.Channel.Role.DISABLED:
- channelSet.settings.append(c.settings)
- bytes = channelSet.SerializeToString()
- s = base64.urlsafe_b64encode(bytes).decode('ascii')
- return f"https://www.meshtastic.org/d/#{s}".replace("=", "")Methods
@@ -2698,6 +2730,28 @@ def channelURL(self):
return None
+
+def getURL(self, includeAll: bool = True)
+
+Expand source code
+
+
+def getURL(self, includeAll: bool = True):
+ """The sharable URL that describes the current channel
+ """
+ # Only keep the primary/secondary channels, assume primary is first
+ channelSet = apponly_pb2.ChannelSet()
+ for c in self.channels:
+ if c.role == channel_pb2.Channel.Role.PRIMARY or (includeAll and c.role == channel_pb2.Channel.Role.SECONDARY):
+ channelSet.settings.append(c.settings)
+ bytes = channelSet.SerializeToString()
+ s = base64.urlsafe_b64encode(bytes).decode('ascii')
+ return f"https://www.meshtastic.org/d/#{s}".replace("=", "")
def requestConfig(self)
+def showChannels(self)
+
+Expand source code
+
+
+def showChannels(self):
+ """Show human readable description of our channels"""
+ print("Channels:")
+ for c in self.channels:
+ if c.role != channel_pb2.Channel.Role.DISABLED:
+ cStr = stripnl(MessageToJson(c.settings))
+ print(f" {channel_pb2.Channel.Role.Name(c.role)} psk={pskToString(c.settings.psk)} {cStr}")
+ publicURL = self.getURL(includeAll = False)
+ adminURL = self.getURL(includeAll = True)
+ print(f"\nPrimary channel URL: {publicURL}")
+ if adminURL != publicURL:
+ print(f"Complete URL (includes all channels): {adminURL}")
def showInfo(self)
+ print(f"Preferences: {stripnl(MessageToJson(self.radioConfig.preferences))}\n")
+ self.showChannels()
def showInfo(self):
"""Show human readable description of our node"""
- print(self.radioConfig)
- print("Channels:")
- for c in self.channels:
- if c.role != channel_pb2.Channel.Role.DISABLED:
- cStr = MessageToJson(c.settings).replace("\n", "")
- print(f" {channel_pb2.Channel.Role.Name(c.role)} {cStr}")
- print(f"\nChannel URL {self.channelURL}")
@@ -3332,6 +3404,7 @@ hostname {string} – Hostname/IP address of the device to connect to
NodechannelURLdeleteChannelexitSimulatorgetChannelByNamegetDisabledChannelgetURLrequestConfigsetOwnersetURLshowChannelsshowInfowaitForConfigwriteChannelremove newlines from a string
remove newlines from a string (and remove extra whitespace)
def stripnl(s):
- """remove newlines from a string"""
- return str(s).replace("\n", " ")
+ """remove newlines from a string (and remove extra whitespace)"""
+ s = str(s).replace("\n", " ")
+ return ' '.join(s.split())