This commit is contained in:
Kevin Hester
2020-10-15 08:24:59 +08:00
parent 1546e6566f
commit 53fab9f838
3 changed files with 9421 additions and 147 deletions

View File

@@ -456,8 +456,17 @@ class MeshInterface:
# For text messages, we go ahead and decode the text to ascii for our users
if asDict["decoded"]["data"]["typ"] == "CLEAR_TEXT":
topic = "meshtastic.receive.text"
asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode(
"utf-8")
# We don't throw if the utf8 is invalid in the text message. Instead we just don't populate
# the decoded.data.text and we log an error message. This at least allows some delivery to
# the app and the app can deal with the missing decoded representation.
#
# Usually btw this problem is caused by apps sending binary data but setting the payload type to
# text.
try:
asDict["decoded"]["data"]["text"] = meshPacket.decoded.data.payload.decode("utf-8")
except Exception as ex:
logging.error(f"Malformatted utf8 in text message: {ex}")
pub.sendMessage(topic, packet=asDict, interface=self)
@@ -1141,8 +1150,17 @@ debugOut</p>
# For text messages, we go ahead and decode the text to ascii for our users
if asDict[&#34;decoded&#34;][&#34;data&#34;][&#34;typ&#34;] == &#34;CLEAR_TEXT&#34;:
topic = &#34;meshtastic.receive.text&#34;
asDict[&#34;decoded&#34;][&#34;data&#34;][&#34;text&#34;] = meshPacket.decoded.data.payload.decode(
&#34;utf-8&#34;)
# We don&#39;t throw if the utf8 is invalid in the text message. Instead we just don&#39;t populate
# the decoded.data.text and we log an error message. This at least allows some delivery to
# the app and the app can deal with the missing decoded representation.
#
# Usually btw this problem is caused by apps sending binary data but setting the payload type to
# text.
try:
asDict[&#34;decoded&#34;][&#34;data&#34;][&#34;text&#34;] = meshPacket.decoded.data.payload.decode(&#34;utf-8&#34;)
except Exception as ex:
logging.error(f&#34;Malformatted utf8 in text message: {ex}&#34;)
pub.sendMessage(topic, packet=asDict, interface=self)</code></pre>
</details>

View File

File diff suppressed because it is too large Load Diff

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.1.1",
version="1.1.6",
description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description,
long_description_content_type="text/markdown",