Is the serial or I'm wrong?

import meshtastic
from pubsub import pub
import json
import time

def update(interface, packet):
    print("data Received")
    interface.showNodes()

if __name__ == '__main__':
    pub.subscribe(update, "meshtastic.receive")
    interface = meshtastic.SerialInterface()

    while True:
        time.sleep(1)

In this simple example I suppose that each time a new message arrives the nodes table is printed to the user screen. It seems to be ok but data in the table is update only at the first run. Next times the table is printed the data is always the same until the script is restarted and so updated again, what am I missing?

regards

Any Idea? same behaviour with api 1.2.33

It may be related to this:

At some point if we don’t figure it out here it would be good to file a bug on the projects git page so it isn’t forgotten.

I tried to debug a bit but I was not able to understand if the problem is at Device, serial or PubSub level.

Tomorrow I’ll try a raw serial approach.

Stay tuned and Thanks for the support.

Regards

Hmm. Sorry just noticed this thread. Possibly a bug in the code that updates the nodedb.

I’m afk today but if you search meshtastic/init.py for “position” you can see the function that is supposed to be doing that update.

Thanks for the hint Kevin, I’ll look.

Regards

It seems that the code that updates self.nodes is missing, I’ll dig a little bit deeper.

Hi @geeksville ,

I’ve found that the node list was updated but only for nodeInfo and not for lastHeard Snr and hoplimit.

I don’t know if is the correct solution but modifying the function _onNodeInfoReceive it seems to update

ORIGINAL

def _onNodeInfoReceive(iface, asDict):
    """Special auto parsing for received messages"""
    print("asdict:", asDict)
    p = asDict["decoded"]["user"]
    # decode user protobufs and update nodedb, provide decoded version as "position" in the published msg
    # update node DB as needed
    n = iface._getOrCreateByNum(asDict["from"])
    print("update Db on info")
    n["user"] = p
    # We now have a node ID, make sure it is uptodate in that table
    iface.nodes[p["id"]] = n

MODIFIED

def _onNodeInfoReceive(iface, asDict):
    """Special auto parsing for received messages"""
    print("asdict:", asDict)
    p = asDict["decoded"]["user"]
    # decode user protobufs and update nodedb, provide decoded version as "position" in the published msg
    # update node DB as needed
    n = iface._getOrCreateByNum(asDict["from"])
    print("update Db on info")
    n["user"] = p
    n["lastHeard"] = asDict["rxTime"]
    n["snr"] = asDict["rxSnr"]
    n["hopLimit"] = asDict["hopLimit"]
    # We now have a node ID, make sure it is uptodate in that table
    iface.nodes[p["id"]] = n

Please tell me if is ok or you prefer a different solution

Regards

1 Like

Hmm. Probably cleaner and more generally useful to instead just store the most recently received packet in the python nodedb. So how about this instead:

n["lastRecieved’]= asDict

This would allow you (and others) to get all that you want, and in the future when packets have more context it will have that as well.

cool? Could you send in a PR?

Hi Kevin,

yes, for sure is better your solution, I’ll make the PR tomorrow.

Tnx

1 Like

Hi Kevin,

I’ve done the modification, it seems to work but I have one question:

In this way we’ll have a lastreceived key with the last received message but the nodeDB is not updated consistently with data received. I mean, The SNR, LastHeard and hoplimit will not be updated in the nodeDB when new packet is received. Maybe this is correct and as intended when developed.
IMHO it makes some confusion because when the device receive a packet an it contains updated information I expect that the nodeDB entry is updated with these information. So why update only “user” and “position” and not lastHeard, SNR and hoplimit?

update:
The rationale of the text above is:

if the node receives a packet it’ll have an rxTime and so this is the last heard
if the node receives a packet it’ll have an rxSnr and so this is the last snr value

it would be great to have the nodeDb with all values updated

def _receiveInfoUpdate(iface, 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")

Regards

Your proposed method of updating snr/hopLimit/lastHeard sounds perfect!

1 Like

Hi, there are problem with the PR?

regards

1 Like

I haven’t had a chance to look at your PR, but I know @geeksville is taking things easy for a little. I haven’t done too much with python or I’d love to review your work. Thanks for contributing!

1 Like

Yeah that’s it I’ll log into GitHub tomorrow morning and catch up on prs though! :two_hearts:

1 Like

Thank you guys, I’ve missed taking things easy for a little

Regards

1 Like