Merge pull request #32 from timgunter/add_set_url

Add setURL() method to MeshInterface
This commit is contained in:
Kevin Hester
2020-10-28 18:42:52 -07:00
committed by GitHub
2 changed files with 14 additions and 5 deletions

View File

@@ -267,6 +267,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

@@ -180,11 +180,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()