22"""
33
44import collections
5+ import json
56import logging
67import random
78import sys
89import threading
910import time
10- import json
1111from datetime import datetime
1212from typing import AnyStr
1313
@@ -61,6 +61,7 @@ def __init__(self, debugOut=None, noProto=False):
6161 self .noProto = noProto
6262 self .localNode = meshtastic .node .Node (self , - 1 ) # We fixup nodenum later
6363 self .myInfo = None # We don't have device info yet
64+ self .metadata = None # We don't have device metadata yet
6465 self .responseHandlers = {} # A map from request ID to the handler
6566 self .failure = (
6667 None # If we've encountered a fatal exception it will be kept here
@@ -102,6 +103,9 @@ def showInfo(self, file=sys.stdout): # pylint: disable=W0613
102103 myinfo = ""
103104 if self .myInfo :
104105 myinfo = f"\n My info: { stripnl (MessageToJson (self .myInfo ))} "
106+ metadata = ""
107+ if self .metadata :
108+ metadata = f"\n Metadata: { stripnl (MessageToJson (self .metadata ))} "
105109 mesh = "\n \n Nodes in mesh: "
106110 nodes = {}
107111 if self .nodes :
@@ -119,10 +123,10 @@ def showInfo(self, file=sys.stdout): # pylint: disable=W0613
119123 n2 ["user" ]["macaddr" ] = addr
120124
121125 # use id as dictionary key for correct json format in list of nodes
122- nodeid = n2 [' user' ][ 'id' ]
123- n2 [' user' ].pop ('id' )
126+ nodeid = n2 [" user" ][ "id" ]
127+ n2 [" user" ].pop ("id" )
124128 nodes [nodeid ] = n2
125- infos = owner + myinfo + mesh + json .dumps (nodes )
129+ infos = owner + myinfo + metadata + mesh + json .dumps (nodes )
126130 print (infos )
127131 return infos
128132
@@ -703,6 +707,10 @@ def _handleFromRadio(self, fromRadioBytes):
703707 self .isConnected .set () # let waitConnected return this exception
704708 self .close ()
705709
710+ elif fromRadio .HasField ("metadata" ):
711+ self .metadata = fromRadio .metadata
712+ logging .debug (f"Received device metadata: { stripnl (fromRadio .metadata )} " )
713+
706714 elif fromRadio .HasField ("node_info" ):
707715 node = asDict ["nodeInfo" ]
708716 try :
@@ -788,7 +796,9 @@ def _handleFromRadio(self, fromRadioBytes):
788796 fromRadio .moduleConfig .remote_hardware
789797 )
790798 elif fromRadio .moduleConfig .HasField ("neighbor_info" ):
791- self .localNode .moduleConfig .neighbor_info .CopyFrom (fromRadio .moduleConfig .neighbor_info )
799+ self .localNode .moduleConfig .neighbor_info .CopyFrom (
800+ fromRadio .moduleConfig .neighbor_info
801+ )
792802
793803 else :
794804 logging .debug ("Unexpected FromRadio payload" )
0 commit comments