1.2.3 fix sendtext

This commit is contained in:
Kevin Hester
2021-03-05 08:27:13 +08:00
parent c63665650f
commit f96520bb97
3 changed files with 94 additions and 20 deletions

View File

@@ -218,7 +218,7 @@ class MeshInterface:
self.noProto = noProto
self.myInfo = None # We don't have device info yet
self.responseHandlers = {} # A map from request ID to the handler
self.failure = None # If we've encountered a fatal exception it will be kept here
self.failure = None # If we've encountered a fatal exception it will be kept here
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it
self.currentPacketId = random.randint(0, 0xffffffff)
self._startConfig()
@@ -377,10 +377,21 @@ class MeshInterface:
p.set_radio.CopyFrom(self.radioConfig)
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug("Wrote config")
def writeChannel(self, channelIndex):
"""Write the current (edited) channel to the device"""
p = admin_pb2.AdminMessage()
p.set_channel.CopyFrom(self.channels[channelIndex])
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug("Wrote channel {channelIndex}")
def getMyNodeInfo(self):
if self.myInfo is None:
return None
@@ -460,8 +471,16 @@ class MeshInterface:
decodedURL = base64.urlsafe_b64decode(splitURL[-1])
channelSet = apponly_pb2.ChannelSet()
channelSet.ParseFromString(decodedURL)
fixme("set self.channels, see https://developers.google.com/protocol-buffers/docs/reference/python-generated?csw=1#repeated-fields")
self._writeChannels()
i = 0
for chs in channelSet.settings:
ch = channel_pb2.Channel()
ch.role = channel_pb2.Channel.Role.PRIMARY if i == 0 else channel_pb2.Channel.Role.SECONDARY
ch.index = i
ch.settings.CopyFrom(chs)
self.channels[ch.index] = ch
self.writeChannel(ch.index)
i = i + 1
def _waitConnected(self):
"""Block until the initial node db download is complete, or timeout
@@ -596,7 +615,7 @@ class MeshInterface:
if failmsg:
self.failure = Exception(failmsg)
self.isConnected.set() # let waitConnected return this exception
self.isConnected.set() # let waitConnected return this exception
self.close()
elif fromRadio.HasField("node_info"):
@@ -1221,6 +1240,7 @@ noProto – If True, don't try to run our protocol on the link - just be a d
<li><code><a title="meshtastic.MeshInterface.setOwner" href="#meshtastic.MeshInterface.setOwner">setOwner</a></code></li>
<li><code><a title="meshtastic.MeshInterface.setURL" href="#meshtastic.MeshInterface.setURL">setURL</a></code></li>
<li><code><a title="meshtastic.MeshInterface.waitForConfig" href="#meshtastic.MeshInterface.waitForConfig">waitForConfig</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeChannel" href="#meshtastic.MeshInterface.writeChannel">writeChannel</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
</ul>
</li>
@@ -1304,7 +1324,7 @@ noProto &ndash; If True, don't try to run our protocol on the link - just be a d
self.noProto = noProto
self.myInfo = None # We don&#39;t have device info yet
self.responseHandlers = {} # A map from request ID to the handler
self.failure = None # If we&#39;ve encountered a fatal exception it will be kept here
self.failure = None # If we&#39;ve encountered a fatal exception it will be kept here
random.seed() # FIXME, we should not clobber the random seedval here, instead tell user they must call it
self.currentPacketId = random.randint(0, 0xffffffff)
self._startConfig()
@@ -1463,10 +1483,21 @@ noProto &ndash; If True, don't try to run our protocol on the link - just be a d
p.set_radio.CopyFrom(self.radioConfig)
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug(&#34;Wrote config&#34;)
def writeChannel(self, channelIndex):
&#34;&#34;&#34;Write the current (edited) channel to the device&#34;&#34;&#34;
p = admin_pb2.AdminMessage()
p.set_channel.CopyFrom(self.channels[channelIndex])
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug(&#34;Wrote channel {channelIndex}&#34;)
def getMyNodeInfo(self):
if self.myInfo is None:
return None
@@ -1546,8 +1577,16 @@ noProto &ndash; If True, don't try to run our protocol on the link - just be a d
decodedURL = base64.urlsafe_b64decode(splitURL[-1])
channelSet = apponly_pb2.ChannelSet()
channelSet.ParseFromString(decodedURL)
fixme(&#34;set self.channels, see https://developers.google.com/protocol-buffers/docs/reference/python-generated?csw=1#repeated-fields&#34;)
self._writeChannels()
i = 0
for chs in channelSet.settings:
ch = channel_pb2.Channel()
ch.role = channel_pb2.Channel.Role.PRIMARY if i == 0 else channel_pb2.Channel.Role.SECONDARY
ch.index = i
ch.settings.CopyFrom(chs)
self.channels[ch.index] = ch
self.writeChannel(ch.index)
i = i + 1
def _waitConnected(self):
&#34;&#34;&#34;Block until the initial node db download is complete, or timeout
@@ -1682,7 +1721,7 @@ noProto &ndash; If True, don't try to run our protocol on the link - just be a d
if failmsg:
self.failure = Exception(failmsg)
self.isConnected.set() # let waitConnected return this exception
self.isConnected.set() # let waitConnected return this exception
self.close()
elif fromRadio.HasField(&#34;node_info&#34;):
@@ -2121,8 +2160,16 @@ wantResponse &ndash; True if you want the service on the other side to send an a
decodedURL = base64.urlsafe_b64decode(splitURL[-1])
channelSet = apponly_pb2.ChannelSet()
channelSet.ParseFromString(decodedURL)
fixme(&#34;set self.channels, see https://developers.google.com/protocol-buffers/docs/reference/python-generated?csw=1#repeated-fields&#34;)
self._writeChannels()</code></pre>
i = 0
for chs in channelSet.settings:
ch = channel_pb2.Channel()
ch.role = channel_pb2.Channel.Role.PRIMARY if i == 0 else channel_pb2.Channel.Role.SECONDARY
ch.index = i
ch.settings.CopyFrom(chs)
self.channels[ch.index] = ch
self.writeChannel(ch.index)
i = i + 1</code></pre>
</details>
</dd>
<dt id="meshtastic.MeshInterface.waitForConfig"><code class="name flex">
@@ -2143,6 +2190,27 @@ wantResponse &ndash; True if you want the service on the other side to send an a
return False</code></pre>
</details>
</dd>
<dt id="meshtastic.MeshInterface.writeChannel"><code class="name flex">
<span>def <span class="ident">writeChannel</span></span>(<span>self, channelIndex)</span>
</code></dt>
<dd>
<div class="desc"><p>Write the current (edited) channel to the device</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def writeChannel(self, channelIndex):
&#34;&#34;&#34;Write the current (edited) channel to the device&#34;&#34;&#34;
p = admin_pb2.AdminMessage()
p.set_channel.CopyFrom(self.channels[channelIndex])
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug(&#34;Wrote channel {channelIndex}&#34;)</code></pre>
</details>
</dd>
<dt id="meshtastic.MeshInterface.writeConfig"><code class="name flex">
<span>def <span class="ident">writeConfig</span></span>(<span>self)</span>
</code></dt>
@@ -2161,8 +2229,8 @@ wantResponse &ndash; True if you want the service on the other side to send an a
p.set_radio.CopyFrom(self.radioConfig)
self.sendData(p, self.myInfo.my_node_num,
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
portNum=portnums_pb2.PortNum.ADMIN_APP,
wantAck=True)
logging.debug(&#34;Wrote config&#34;)</code></pre>
</details>
</dd>
@@ -2270,6 +2338,7 @@ debugOut {stream} &ndash; If a stream is provided, any debug serial output from
<li><code><a title="meshtastic.StreamInterface.setOwner" href="#meshtastic.MeshInterface.setOwner">setOwner</a></code></li>
<li><code><a title="meshtastic.StreamInterface.setURL" href="#meshtastic.MeshInterface.setURL">setURL</a></code></li>
<li><code><a title="meshtastic.StreamInterface.waitForConfig" href="#meshtastic.MeshInterface.waitForConfig">waitForConfig</a></code></li>
<li><code><a title="meshtastic.StreamInterface.writeChannel" href="#meshtastic.MeshInterface.writeChannel">writeChannel</a></code></li>
<li><code><a title="meshtastic.StreamInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
</ul>
</li>
@@ -2506,6 +2575,7 @@ start the reading thread later.</p></div>
<li><code><a title="meshtastic.MeshInterface.setOwner" href="#meshtastic.MeshInterface.setOwner">setOwner</a></code></li>
<li><code><a title="meshtastic.MeshInterface.setURL" href="#meshtastic.MeshInterface.setURL">setURL</a></code></li>
<li><code><a title="meshtastic.MeshInterface.waitForConfig" href="#meshtastic.MeshInterface.waitForConfig">waitForConfig</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeChannel" href="#meshtastic.MeshInterface.writeChannel">writeChannel</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
</ul>
</li>
@@ -2584,6 +2654,7 @@ hostname {string} &ndash; Hostname/IP address of the device to connect to</p></d
<li><code><a title="meshtastic.StreamInterface.setOwner" href="#meshtastic.MeshInterface.setOwner">setOwner</a></code></li>
<li><code><a title="meshtastic.StreamInterface.setURL" href="#meshtastic.MeshInterface.setURL">setURL</a></code></li>
<li><code><a title="meshtastic.StreamInterface.waitForConfig" href="#meshtastic.MeshInterface.waitForConfig">waitForConfig</a></code></li>
<li><code><a title="meshtastic.StreamInterface.writeChannel" href="#meshtastic.MeshInterface.writeChannel">writeChannel</a></code></li>
<li><code><a title="meshtastic.StreamInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
</ul>
</li>
@@ -2655,6 +2726,7 @@ hostname {string} &ndash; Hostname/IP address of the device to connect to</p></d
<li><code><a title="meshtastic.MeshInterface.setOwner" href="#meshtastic.MeshInterface.setOwner">setOwner</a></code></li>
<li><code><a title="meshtastic.MeshInterface.setURL" href="#meshtastic.MeshInterface.setURL">setURL</a></code></li>
<li><code><a title="meshtastic.MeshInterface.waitForConfig" href="#meshtastic.MeshInterface.waitForConfig">waitForConfig</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeChannel" href="#meshtastic.MeshInterface.writeChannel">writeChannel</a></code></li>
<li><code><a title="meshtastic.MeshInterface.writeConfig" href="#meshtastic.MeshInterface.writeConfig">writeConfig</a></code></li>
</ul>
</li>

View File

@@ -34,14 +34,16 @@ def onReceive(packet, interface):
logging.debug(f"Received: {packet}")
try:
d = packet.get('decoded')
# Exit once we receive a reply
if args.sendtext and packet["to"] == interface.myInfo.my_node_num:
if args.sendtext and packet["to"] == interface.myInfo.my_node_num and d["portnum"] == portnums_pb2.PortNum.TEXT_MESSAGE_APP:
interface.close() # after running command then exit
# Reply to every received message with some stats
if args.reply:
if packet['decoded']['data'] is not None:
msg = packet['decoded']['data']['text']
msg = d.get('text')
if msg:
#shortName = packet['decoded']['data']['shortName']
rxSnr = packet['rxSnr']
hopLimit = packet['hopLimit']

View File

@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
# This call to setup() does all the work
setup(
name="meshtastic",
version="1.2.2",
version="1.2.3",
description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description,
long_description_content_type="text/markdown",