From a78ddffb3ef10c4f687b900ef335740c916d05f0 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 27 Feb 2021 09:16:50 +0800 Subject: [PATCH] getting channel url works --- meshtastic/__init__.py | 5 ++++- meshtastic/__main__.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index b066240..2f1fd61 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -346,8 +346,11 @@ class MeshInterface: 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() - fixme("fill channelSet from self.channels") + for c in self.channels: + if c.role != mesh_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/c/#{s}" diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 1a0cc37..e3d1bab 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -15,6 +15,7 @@ import traceback import pkg_resources from datetime import datetime from easy_table import EasyTable +from google.protobuf.json_format import MessageToJson """We only import the tunnel code if we are on a platform that can run it""" have_tunnel = platform.system() == 'Linux' @@ -317,7 +318,12 @@ def onConnected(interface): closeNow = True print(interface.myInfo) print(interface.radioConfig) - print(f"Channel URL {interface.channelURL}") + print("Channels:") + for c in interface.channels: + if c.role != mesh_pb2.Channel.Role.DISABLED: + cStr = MessageToJson(c.settings).replace("\n", "") + print(f" {mesh_pb2.Channel.Role.Name(c.role)} {cStr}") + print(f"\nChannel URL {interface.channelURL}") print("Nodes in mesh:") for n in interface.nodes.values(): print(n)