From e59fe9af7293cac6ea588433ff0fa8f6c2e32239 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 23 Dec 2020 17:32:36 +0800 Subject: [PATCH] IP tunnel almost works #35 --- meshtastic/__main__.py | 2 +- meshtastic/tunnel.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 2e61290..df4c8e6 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -19,7 +19,7 @@ args = None def onReceive(packet, interface): """Callback invoked when a packet arrives""" - print(f"Received: {packet}") + logging.debug(f"Received: {packet}") try: # Exit once we receive a reply diff --git a/meshtastic/tunnel.py b/meshtastic/tunnel.py index 2720fc7..9e86763 100644 --- a/meshtastic/tunnel.py +++ b/meshtastic/tunnel.py @@ -3,11 +3,11 @@ # using pip3 install pytap2 # make sure to "sudo setcap cap_net_admin+eip /usr/bin/python3.8" so python can access tun device without being root # sudo ip tuntap del mode tun tun0 +# sudo bin/run.sh --port /dev/ttyUSB0 --setch-shortfast +# sudo bin/run.sh --port /dev/ttyUSB0 --tunnel --debug # FIXME: set MTU correctly -# select local ip address based on nodeid -# print known node ids as IP addresses -# change dev name to mesh +# allow setting arbitary IP addresses from . import portnums_pb2 from pubsub import pub @@ -143,8 +143,10 @@ class Tunnel: return "^all" for node in self.iface.nodes.values(): - if (node["num"] and 0xffff) == ipBits: - return node["id"] + nodeNum = node["num"] & 0xffff + logging.debug(f"Considering nodenum 0x{nodeNum:x} for ipBits 0x{ipBits:x}") + if (nodeNum) == ipBits: + return node["user"]["id"] return None def _nodeNumToIp(self, nodeNum):