mirror of
https://github.com/meshtastic/python.git
synced 2025-12-28 18:37:52 -05:00
only require pytap if user tries to run 'mesh-tunnel'
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
# ncat -e /bin/cat -k -u -l 1235
|
||||
# ncat -u 10.115.64.152 1235
|
||||
# ping -c 1 -W 20 10.115.64.152
|
||||
# ping -i 30 -W 30 10.115.64.152
|
||||
|
||||
# FIXME: use a more optimal MTU
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import pkg_resources
|
||||
"""The command line arguments"""
|
||||
args = None
|
||||
|
||||
"""The parser for arguments"""
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
def onReceive(packet, interface):
|
||||
"""Callback invoked when a packet arrives"""
|
||||
@@ -300,9 +302,50 @@ def subscribe():
|
||||
# pub.subscribe(onNode, "meshtastic.node")
|
||||
|
||||
|
||||
def main():
|
||||
"""Perform command line meshtastic operations"""
|
||||
parser = argparse.ArgumentParser()
|
||||
def common():
|
||||
"""Shared code for all of our command line wrappers"""
|
||||
global args
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
# Some commands require dest to be set, so we now use destOrAll for more lenient commands
|
||||
args.destOrAll = args.dest
|
||||
if not args.destOrAll:
|
||||
args.destOrAll = "^all"
|
||||
|
||||
if not args.seriallog:
|
||||
if args.info or args.set or args.seturl or args.setowner or args.setlat or args.setlon or \
|
||||
args.settime or \
|
||||
args.setch_longslow or args.setch_shortfast or args.setstr or args.setchan or args.sendtext or \
|
||||
args.tunnel or args.router != None or args.qr:
|
||||
args.seriallog = "none" # assume no debug output in this case
|
||||
else:
|
||||
args.seriallog = "stdout" # default to stdout
|
||||
|
||||
if args.test:
|
||||
test.testAll()
|
||||
else:
|
||||
if args.seriallog == "stdout":
|
||||
logfile = sys.stdout
|
||||
elif args.seriallog == "none":
|
||||
args.seriallog = None
|
||||
logging.debug("Not logging serial output")
|
||||
logfile = None
|
||||
else:
|
||||
logging.info(f"Logging serial output to {args.seriallog}")
|
||||
logfile = open(args.seriallog, 'w+', buffering=1) # line buffering
|
||||
|
||||
subscribe()
|
||||
if args.ble:
|
||||
client = BLEInterface(args.ble, debugOut=logfile)
|
||||
elif args.host:
|
||||
client = TCPInterface(
|
||||
args.host, debugOut=logfile, noProto=args.noproto)
|
||||
else:
|
||||
client = SerialInterface(
|
||||
args.port, debugOut=logfile, noProto=args.noproto)
|
||||
|
||||
def initParser():
|
||||
global parser, args
|
||||
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
@@ -409,47 +452,19 @@ def main():
|
||||
|
||||
parser.add_argument('--version', action='version', version=f"{pkg_resources.require('meshtastic')[0].version}")
|
||||
|
||||
global args
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
# Some commands require dest to be set, so we now use destOrAll for more lenient commands
|
||||
args.destOrAll = args.dest
|
||||
if not args.destOrAll:
|
||||
args.destOrAll = "^all"
|
||||
|
||||
if not args.seriallog:
|
||||
if args.info or args.set or args.seturl or args.setowner or args.setlat or args.setlon or \
|
||||
args.settime or \
|
||||
args.setch_longslow or args.setch_shortfast or args.setstr or args.setchan or args.sendtext or \
|
||||
args.tunnel or args.router != None or args.qr:
|
||||
args.seriallog = "none" # assume no debug output in this case
|
||||
else:
|
||||
args.seriallog = "stdout" # default to stdout
|
||||
|
||||
if args.test:
|
||||
test.testAll()
|
||||
else:
|
||||
if args.seriallog == "stdout":
|
||||
logfile = sys.stdout
|
||||
elif args.seriallog == "none":
|
||||
args.seriallog = None
|
||||
logging.debug("Not logging serial output")
|
||||
logfile = None
|
||||
else:
|
||||
logging.info(f"Logging serial output to {args.seriallog}")
|
||||
logfile = open(args.seriallog, 'w+', buffering=1) # line buffering
|
||||
|
||||
subscribe()
|
||||
if args.ble:
|
||||
client = BLEInterface(args.ble, debugOut=logfile)
|
||||
elif args.host:
|
||||
client = TCPInterface(
|
||||
args.host, debugOut=logfile, noProto=args.noproto)
|
||||
else:
|
||||
client = SerialInterface(
|
||||
args.port, debugOut=logfile, noProto=args.noproto)
|
||||
def main():
|
||||
"""Perform command line meshtastic operations"""
|
||||
initParser()
|
||||
common()
|
||||
|
||||
def tunnelMain():
|
||||
"""Run a meshtastic IP tunnel"""
|
||||
global args
|
||||
initParser()
|
||||
args.tunnel = True
|
||||
common()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# ncat -e /bin/cat -k -u -l 1235
|
||||
# ncat -u 10.115.64.152 1235
|
||||
# ping -c 1 -W 20 10.115.64.152
|
||||
# ping -i 30 -W 30 10.115.64.152
|
||||
|
||||
# FIXME: use a more optimal MTU
|
||||
|
||||
|
||||
10
setup.py
10
setup.py
@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
|
||||
# This call to setup() does all the work
|
||||
setup(
|
||||
name="meshtastic",
|
||||
version="1.1.26",
|
||||
version="1.1.27",
|
||||
description="Python API & client shell for talking to Meshtastic devices",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
@@ -29,11 +29,15 @@ 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", "pytap2>=2.0.0"],
|
||||
"pygatt>=4.0.5"],
|
||||
extras_require={
|
||||
'tunnel': ["pytap2>=2.0.0"]
|
||||
},
|
||||
python_requires='>=3.6',
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"meshtastic=meshtastic.__main__:main"
|
||||
"meshtastic=meshtastic.__main__:main",
|
||||
"mesh-tunnel=meshtastic.__main__:tunnelMain [tunnel]"
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user