Hi Paul,
I’ll ask @geeksville what he think about that, this is the project of him. In my opinion the best option is to write a custom script that will accomplish your needs using the python API, Code Below:
from datetime import datetime
import timeago
from easy_table import EasyTable
import meshtastic
from OSGridConverter import latlong2grid
#Returns formatted value
def formatFloat(value, formatStr="{:.2f}", unit="", default="N/A"):
return formatStr.format(value)+unit if value else default
#Returns OSG coordinates
def getOSG(lat, lon):
try:
out = str(latlong2grid(lat,lon))
except:
out = ""
if len(out)==14:
return out
else:
return "Conversion Error"
#Returns Last Heard Time in human readable format
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 if ts else default
#Print Nodes
def printNodes(nodes, osg=False):
#Create the table and define the structure
table = EasyTable("Nodes")
table.setCorners("/", "\\", "\\", "/")
table.setOuterStructure("|", "-")
table.setInnerStructure("|", "-", "+")
tableData = []
i = 1
for node in nodes:
#aux var to get not defined keys
lat=formatFloat(node['position'].get("latitude"), "{:.4f}", "°")
lon=formatFloat(node['position'].get("longitude"), "{:.4f}", "°")
alt=formatFloat(node['position'].get("altitude"), "{:.0f}", " m")
if osg:
pos = getOSG(node['position'].get("latitude"),node['position'].get("longitude"))
else:
pos = lat+", "+lon+", "+alt
batt=formatFloat(node['position'].get("batteryLevel"), "{:.2f}", "%")
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'],
"AKA":node['user']['shortName'], "ID":node['user']['id'],
"Position":pos,
"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()
interface = meshtastic.SerialInterface()
interface.close()
printNodes(interface.nodes.values(),True)