Output of --info "Nodes in mesh" to JSON Format

This commit is contained in:
Manuel Verch
2023-03-30 14:37:01 +02:00
committed by Thomas Göttgens
parent 62843ea39c
commit c28b61fbb1

View File

@@ -3,6 +3,7 @@
import sys
import random
import time
import json
import logging
import collections
from typing import AnyStr
@@ -82,8 +83,8 @@ class MeshInterface:
myinfo = ''
if self.myInfo:
myinfo = f"\nMy info: {stripnl(MessageToJson(self.myInfo))}"
mesh = "\nNodes in mesh:"
nodes = ""
mesh = "\n\nNodes in mesh: "
nodes = {}
if self.nodes:
for n in self.nodes.values():
# when the TBeam is first booted, it sometimes shows the raw data
@@ -98,8 +99,11 @@ class MeshInterface:
addr = convert_mac_addr(val)
n2['user']['macaddr'] = addr
nodes = nodes + f" {stripnl(n2)}"
infos = owner + myinfo + mesh + nodes
# use id as dictionary key for correct json format in list of nodes
nodeid = n2['user']['id']
n2['user'].pop('id')
nodes[nodeid] = n2
infos = owner + myinfo + mesh + json.dumps(nodes)
print(infos)
return infos