mirror of
https://github.com/meshtastic/python.git
synced 2026-01-05 06:17:55 -05:00
Merge pull request #32 from timgunter/add_set_url
Add setURL() method to MeshInterface
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user