Skip to content

Commit e76c985

Browse files
committed
2.2 changes and added device_metadata
1 parent 0788c1f commit e76c985

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

meshtastic/mesh_interface.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"""
33

44
import collections
5+
import json
56
import logging
67
import random
78
import sys
89
import threading
910
import time
10-
import json
1111
from datetime import datetime
1212
from 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"\nMy info: {stripnl(MessageToJson(self.myInfo))}"
106+
metadata = ""
107+
if self.metadata:
108+
metadata = f"\nMetadata: {stripnl(MessageToJson(self.metadata))}"
105109
mesh = "\n\nNodes 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")

meshtastic/node.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def showChannels(self):
5050
# print('c.settings.psk:', c.settings.psk)
5151
cStr = stripnl(MessageToJson(c.settings))
5252
# don't show disabled channels
53-
if channel_pb2.Channel.Role.Name(c.role)!="DISABLED":
53+
if channel_pb2.Channel.Role.Name(c.role) != "DISABLED":
5454
print(
5555
f" {channel_pb2.Channel.Role.Name(c.role)} psk={pskToString(c.settings.psk)} {cStr}"
5656
)
@@ -189,9 +189,7 @@ def writeConfig(self, config_name):
189189
self.moduleConfig.remote_hardware
190190
)
191191
elif config_name == "neighbor_info":
192-
p.set_module_config.neighbor_info.CopyFrom(
193-
self.moduleConfig.neighbor_info
194-
)
192+
p.set_module_config.neighbor_info.CopyFrom(self.moduleConfig.neighbor_info)
195193
else:
196194
our_exit(f"Error: No valid config with name {config_name}")
197195

@@ -237,7 +235,7 @@ def deleteChannel(self, channelIndex):
237235
self._fixupChannels() # expand back to 8 channels
238236

239237
index = channelIndex
240-
while index < self.iface.myInfo.max_channels:
238+
while index < 8:
241239
self.writeChannel(index, adminIndex=adminIndex)
242240
index += 1
243241

@@ -629,7 +627,7 @@ def _fillChannels(self):
629627

630628
# Add extra disabled channels as needed
631629
index = len(self.channels)
632-
while index < self.iface.myInfo.max_channels:
630+
while index < 8:
633631
ch = channel_pb2.Channel()
634632
ch.role = channel_pb2.Channel.Role.DISABLED
635633
ch.index = index
@@ -694,7 +692,7 @@ def onResponseRequestChannel(self, p):
694692
c.role == channel_pb2.Channel.Role.DISABLED
695693
) and fastChannelDownload
696694

697-
if quitEarly or index >= self.iface.myInfo.max_channels - 1:
695+
if quitEarly or index >= 8 - 1:
698696
logging.debug("Finished downloading channels")
699697

700698
self.channels = self.partialChannels

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# This call to setup() does all the work
1414
setup(
1515
name="meshtastic",
16-
version="2.1.14",
16+
version="2.2.0",
1717
description="Python API & client shell for talking to Meshtastic devices",
1818
long_description=long_description,
1919
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)