1212 Timeout ,
1313 camel_to_snake ,
1414 fromPSK ,
15+ genPSK256 ,
1516 our_exit ,
1617 pskToString ,
1718 stripnl ,
@@ -337,14 +338,19 @@ def getURL(self, includeAll: bool = True):
337338 s = s .replace ("=" , "" ).replace ("+" , "-" ).replace ("/" , "_" )
338339 return f"https://meshtastic.org/e/#{ s } "
339340
340- def setURL (self , url ):
341+ def setURL (self , url , addOnly : bool = False ):
341342 """Set mesh network URL"""
342343 if self .localConfig is None :
343344 our_exit ("Warning: No Config has been read" )
344345
345346 # URLs are of the form https://meshtastic.org/d/#{base64_channel_set}
346347 # Split on '/#' to find the base64 encoded channel settings
347- splitURL = url .split ("/#" )
348+ if addOnly :
349+ splitURL = url .split ("/?add=true#" )
350+ else :
351+ splitURL = url .split ("/#" )
352+ if len (splitURL ) == 1 :
353+ our_exit (f"Warning: Invalid URL '{ url } '" )
348354 b64 = splitURL [- 1 ]
349355
350356 # We normally strip padding to make for a shorter URL, but the python parser doesn't like
@@ -361,20 +367,40 @@ def setURL(self, url):
361367 if len (channelSet .settings ) == 0 :
362368 our_exit ("Warning: There were no settings." )
363369
364- i = 0
365- for chs in channelSet .settings :
366- ch = channel_pb2 .Channel ()
367- ch .role = (
368- channel_pb2 .Channel .Role .PRIMARY
369- if i == 0
370- else channel_pb2 .Channel .Role .SECONDARY
371- )
372- ch .index = i
373- ch .settings .CopyFrom (chs )
374- self .channels [ch .index ] = ch
375- logging .debug (f"Channel i:{ i } ch:{ ch } " )
376- self .writeChannel (ch .index )
377- i = i + 1
370+ if addOnly :
371+ # Add new channels with names not already present
372+ # Don't change existing channels
373+ for ch in channelSet .settings :
374+ channelExists = self .getChannelByName (ch .name )
375+ if channelExists or ch .name == "" :
376+ print ("Ignoring existing channel from add URL" )
377+ next
378+ else :
379+ newChannel = self .getDisabledChannel ()
380+ if not newChannel :
381+ our_exit ("Warning: No free channels were found" )
382+ chs = channel_pb2 .ChannelSettings ()
383+ chs .name = ch .name
384+ chs .psk = ch .psk
385+ newChannel .settings .CopyFrom (chs )
386+ newChannel .role = channel_pb2 .Channel .Role .SECONDARY
387+ print (f"Adding new channel '{ ch .name } ' to device" )
388+ self .writeChannel (newChannel .index )
389+ else :
390+ i = 0
391+ for chs in channelSet .settings :
392+ ch = channel_pb2 .Channel ()
393+ ch .role = (
394+ channel_pb2 .Channel .Role .PRIMARY
395+ if i == 0
396+ else channel_pb2 .Channel .Role .SECONDARY
397+ )
398+ ch .index = i
399+ ch .settings .CopyFrom (chs )
400+ self .channels [ch .index ] = ch
401+ logging .debug (f"Channel i:{ i } ch:{ ch } " )
402+ self .writeChannel (ch .index )
403+ i = i + 1
378404
379405 p = admin_pb2 .AdminMessage ()
380406 p .set_config .lora .CopyFrom (channelSet .lora_config )
0 commit comments