Add setURL() method to MeshInterface

This commit is contained in:
Gunter Tim
2020-10-25 11:24:09 -07:00
parent 53fab9f838
commit a7fbfcb948
2 changed files with 14 additions and 5 deletions

View File

@@ -208,6 +208,19 @@ class MeshInterface:
s = base64.urlsafe_b64encode(bytes).decode('ascii')
return f"https://www.meshtastic.org/c/#{s}"
def setURL(self, url, write=True):
"""Set mesh network URL"""
if self.radioConfig == None:
raise Exception("No RadioConfig has been read")
# URLs are of the form https://www.meshtastic.org/c/#{base64_channel_settings}
# Split on '/#' to find the base64 encoded channel settings
splitURL = url.split("/#")
decodedURL = base64.urlsafe_b64decode(splitURL[-1])
self.radioConfig.channel_settings.ParseFromString(decodedURL)
if write:
self.writeConfig()
def _generatePacketId(self):
"""Get a new unique packet ID"""
if self.currentPacketId is None:

View File

@@ -176,11 +176,7 @@ def onConnected(interface):
# Handle set URL
if args.seturl:
# URLs are of the form https://www.meshtastic.org/c/#{base64_channel_settings}
# Split on '/#' to find the base64 encoded channel settings
splitURL = args.seturl.split("/#")
bytes = base64.urlsafe_b64decode(splitURL[-1])
interface.radioConfig.channel_settings.ParseFromString(bytes)
interface.setURL(args.seturl, False)
print("Writing modified preferences to device")
interface.writeConfig()