Compare commits

..

6 Commits

Author SHA1 Message Date
Kevin Hester
c11e3dd844 1.2.35 2021-05-24 10:17:41 +08:00
Kevin Hester
a5a14f3cfe Merge remote-tracking branch 'root/master' into dev 2021-05-24 10:16:50 +08:00
Kevin Hester
acaef40b08 Merge pull request #92 from iz1kga/nodeDB_Update
nodeDB Update, SNR, Hoplimit, LastHeard and added lastReceived
2021-05-20 07:39:07 +08:00
iz1kga
a69a8b460e nodeDB Update, SNR, Hoplimit, LastHeard and added lastReceived 2021-05-12 08:54:36 +02:00
Kevin Hester
7a63ce35f0 Merge pull request #89 from acabey/master
Implemented --get argument to get current parameter value
2021-05-11 17:26:26 +08:00
Andrew Cabey
4259211888 Implemented --get argument to get current parameter value 2021-05-03 19:21:07 -04:00
5 changed files with 68 additions and 1 deletions

8
.vscode/launch.json vendored
View File

@@ -93,5 +93,13 @@
"justMyCode": true,
"args": ["--debug", "--sendtext", "pytest"]
}
{
"name": "meshtastic showNodes",
"type": "python",
"request": "launch",
"module": "meshtastic",
"justMyCode": true,
"args": ["--debug", "--nodes"]
}
]
}

View File

@@ -1082,6 +1082,7 @@ def _onTextReceive(iface, asDict):
asDict["decoded"]["text"] = asBytes.decode("utf-8")
except Exception as ex:
logging.error(f"Malformatted utf8 in text message: {ex}")
_receiveInfoUpdate(iface, asDict)
def _onPositionReceive(iface, asDict):
@@ -1101,6 +1102,14 @@ def _onNodeInfoReceive(iface, asDict):
n["user"] = p
# We now have a node ID, make sure it is uptodate in that table
iface.nodes[p["id"]] = n
_receiveInfoUpdate(iface, asDict)
def _receiveInfoUpdate(iface, asDict):
iface._getOrCreateByNum(asDict["from"])["lastReceived"] = asDict
iface._getOrCreateByNum(asDict["from"])["lastHeard"] = asDict.get("rxTime")
iface._getOrCreateByNum(asDict["from"])["snr"] = asDict.get("rxSnr")
iface._getOrCreateByNum(asDict["from"])["hopLimit"] = asDict.get("hopLimit")
"""Well known message payloads can register decoders for automatic protobuf parsing"""

View File

@@ -995,6 +995,7 @@ def _onTextReceive(iface, asDict):
asDict["decoded"]["text"] = asBytes.decode("utf-8")
except Exception as ex:
logging.error(f"Malformatted utf8 in text message: {ex}")
_receiveInfoUpdate(iface, asDict)
def _onPositionReceive(iface, asDict):
@@ -1014,6 +1015,14 @@ def _onNodeInfoReceive(iface, asDict):
n["user"] = p
# We now have a node ID, make sure it is uptodate in that table
iface.nodes[p["id"]] = n
_receiveInfoUpdate(iface, asDict)
def _receiveInfoUpdate(iface, asDict):
iface._getOrCreateByNum(asDict["from"])["lastReceived"] = asDict
iface._getOrCreateByNum(asDict["from"])["lastHeard"] = asDict.get("rxTime")
iface._getOrCreateByNum(asDict["from"])["snr"] = asDict.get("rxSnr")
iface._getOrCreateByNum(asDict["from"])["hopLimit"] = asDict.get("hopLimit")
"""Well known message payloads can register decoders for automatic protobuf parsing"""

View File

@@ -118,6 +118,32 @@ never = 0xffffffff
oneday = 24 * 60 * 60
def getPref(attributes, name):
"""Get a channel or preferences value"""
objDesc = attributes.DESCRIPTOR
field = objDesc.fields_by_name.get(name)
if not field:
print(f"{attributes.__class__.__name__} doesn't have an attribute called {name}, so you can not get it.")
print(f"Choices are:")
for f in objDesc.fields:
print(f" {f.name}")
return
# okay - try to read the value
try:
try:
val = getattr(attributes, name)
except TypeError as ex:
# The getter didn't like our arg type guess try again as a string
val = getattr(attributes, name)
# succeeded!
print(f"{name}: {str(val)}")
except Exception as ex:
print(f"Can't get {name} due to {ex}")
def setPref(attributes, name, valStr):
"""Set a channel or preferences value"""
@@ -281,6 +307,7 @@ def onConnected(interface):
print("Writing modified preferences to device")
getNode().writeConfig()
if args.seturl:
closeNow = True
getNode().setURL(args.seturl)
@@ -372,6 +399,17 @@ def onConnected(interface):
closeNow = True # FIXME, for now we leave the link up while talking to remote nodes
print("")
if args.get:
closeNow = True
prefs = getNode().radioConfig.preferences
# Handle the int/float/bool arguments
for pref in args.get:
getPref(
prefs, pref[0])
print("Completed getting preferences")
if args.nodes:
closeNow = True
interface.showNodes()
@@ -507,6 +545,9 @@ def initParser():
parser.add_argument("--qr", help="Display the QR code that corresponds to the current channel",
action="store_true")
parser.add_argument(
"--get", help="Get a preferences field", nargs=1, action='append')
parser.add_argument(
"--set", help="Set a preferences field", nargs=2, action='append')

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