From 56ad4d13e74509d99927ea07a64c6d14fcd53dc3 Mon Sep 17 00:00:00 2001 From: iz1kga Date: Thu, 18 Feb 2021 10:16:31 +0100 Subject: [PATCH 1/4] Removed lat, lon , alt --- meshtastic/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index dc10406..ca4a58d 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -161,7 +161,7 @@ def printNodes(nodes): batt=formatFloat(node['position'].get("batteryLevel"), "{:.2f}", "%") snr=formatFloat(node.get("snr"), "{:.2f}", " dB") tableData.append({"User":node['user']['longName'], - "Position":"Lat:"+lat+", Lon:"+lon+", Alt:"+alt, + "Position":lat+", "+lon+", "+alt, "Battery":batt, "SNR":snr, "LastHeard":LH}) table.setData(tableData) table.displayTable() From 3d2913a5251571172fee53662749e1f773c3bf37 Mon Sep 17 00:00:00 2001 From: iz1kga Date: Thu, 18 Feb 2021 14:41:37 +0100 Subject: [PATCH 2/4] added Number, AKA, ID, and TimeAgo --- meshtastic/__main__.py | 21 +++++++++++++++++---- setup.py | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index ca4a58d..f1e7ecc 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -9,6 +9,7 @@ import pyqrcode import traceback import pkg_resources from datetime import datetime +import timeago from easy_table import EasyTable """We only import the tunnel code if we are on a platform that can run it""" @@ -143,6 +144,10 @@ def formatFloat(value, formatStr="{:.2f}", unit="", default="N/A"): def getLH(ts, default="N/A"): return datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') if ts else default +#Returns time ago for the last heard +def getTimeAgo(ts, default="N/A"): + return timeago.format(datetime.fromtimestamp(ts), datetime.now()) if ts else default + #Print Nodes def printNodes(nodes): #Create the table and define the structure @@ -152,18 +157,26 @@ def printNodes(nodes): table.setInnerStructure("|", "-", "+") tableData = [] + i = 1 for node in nodes: #aux var to get not defined keys - LH= getLH(node['position'].get("time")) lat=formatFloat(node['position'].get("latitude"), "{:.4f}", "°") lon=formatFloat(node['position'].get("longitude"), "{:.4f}", "°") alt=formatFloat(node['position'].get("altitude"), "{:.0f}", " m") batt=formatFloat(node['position'].get("batteryLevel"), "{:.2f}", "%") snr=formatFloat(node.get("snr"), "{:.2f}", " dB") - tableData.append({"User":node['user']['longName'], + LH= getLH(node['position'].get("time")) + timeAgo = getTimeAgo(node['position'].get("time")) + tableData.append({"N":i, "User":node['user']['longName'], + "AKA":node['user']['shortName'], "ID":node['user']['id'], "Position":lat+", "+lon+", "+alt, - "Battery":batt, "SNR":snr, "LastHeard":LH}) - table.setData(tableData) + "Battery":batt, "SNR":snr, + "LastHeard":LH, "Since":timeAgo}) + i = i+1 + Rows = sorted(tableData, key=lambda k: k['LastHeard'], reverse=True) + RowsOk = sorted(Rows, key=lambda k:k ['LastHeard'].startswith("N/A")) + table.setData(RowsOk) + table.displayTable() def onConnected(interface): diff --git a/setup.py b/setup.py index 1290742..bff8260 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( include_package_data=True, install_requires=["pyserial>=3.4", "protobuf>=3.13.0", "pypubsub>=4.0.3", "dotmap>=1.3.14", "pexpect>=4.6.0", "pyqrcode>=1.2.1", - "pygatt>=4.0.5", "easy-table==0.0.4"], + "pygatt>=4.0.5", "easy-table==0.0.4", "timeago==1.0.15"], extras_require={ 'tunnel': ["pytap2>=2.0.0"] }, From 22ca6d567debc1eea57f98530f0c6a5efb0c9794 Mon Sep 17 00:00:00 2001 From: iz1kga Date: Thu, 18 Feb 2021 21:46:58 +0100 Subject: [PATCH 3/4] fix Number order --- meshtastic/__main__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index f1e7ecc..98208c0 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -157,7 +157,6 @@ def printNodes(nodes): table.setInnerStructure("|", "-", "+") tableData = [] - i = 1 for node in nodes: #aux var to get not defined keys lat=formatFloat(node['position'].get("latitude"), "{:.4f}", "°") @@ -167,14 +166,16 @@ def printNodes(nodes): snr=formatFloat(node.get("snr"), "{:.2f}", " dB") LH= getLH(node['position'].get("time")) timeAgo = getTimeAgo(node['position'].get("time")) - tableData.append({"N":i, "User":node['user']['longName'], + tableData.append({"N":0, "User":node['user']['longName'], "AKA":node['user']['shortName'], "ID":node['user']['id'], "Position":lat+", "+lon+", "+alt, "Battery":batt, "SNR":snr, "LastHeard":LH, "Since":timeAgo}) - i = i+1 + Rows = sorted(tableData, key=lambda k: k['LastHeard'], reverse=True) RowsOk = sorted(Rows, key=lambda k:k ['LastHeard'].startswith("N/A")) + for i in range(1, len(RowsOk)): + RowsOk[i]['N'] = i table.setData(RowsOk) table.displayTable() From ec3e059c35ccedab907dac62092eff840f66a373 Mon Sep 17 00:00:00 2001 From: iz1kga Date: Fri, 19 Feb 2021 09:51:15 +0100 Subject: [PATCH 4/4] Fix entry number startinf from 1 - Removed Self Id from list --- meshtastic/__main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 98208c0..5dd86a6 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -149,7 +149,7 @@ def getTimeAgo(ts, default="N/A"): return timeago.format(datetime.fromtimestamp(ts), datetime.now()) if ts else default #Print Nodes -def printNodes(nodes): +def printNodes(nodes, myId): #Create the table and define the structure table = EasyTable("Nodes") table.setCorners("/", "\\", "\\", "/") @@ -158,6 +158,8 @@ def printNodes(nodes): tableData = [] for node in nodes: + if node['user']['id'] == myId: + continue #aux var to get not defined keys lat=formatFloat(node['position'].get("latitude"), "{:.4f}", "°") lon=formatFloat(node['position'].get("longitude"), "{:.4f}", "°") @@ -174,8 +176,8 @@ def printNodes(nodes): Rows = sorted(tableData, key=lambda k: k['LastHeard'], reverse=True) RowsOk = sorted(Rows, key=lambda k:k ['LastHeard'].startswith("N/A")) - for i in range(1, len(RowsOk)): - RowsOk[i]['N'] = i + for i in range(len(RowsOk)): + RowsOk[i]['N'] = i+1 table.setData(RowsOk) table.displayTable() @@ -322,7 +324,7 @@ def onConnected(interface): if args.nodes: closeNow = True - printNodes(interface.nodes.values()) + printNodes(interface.nodes.values(), interface.getMyNodeInfo()['user']['id']) if args.qr: closeNow = True