From 5c1e5ee60d6c8d586fcb7a6e6365ac1dcad0508d Mon Sep 17 00:00:00 2001 From: acidvegas Date: Fri, 29 Nov 2024 22:56:16 -0500 Subject: [PATCH] Prepair for release --- .gitignore | 24 +++++++++++ README.md | 16 +++++-- pyproject.toml | 6 +++ setup.py | 43 +++++++++++++++++++ src/meshtastic_mqtt/__init__.py | 9 ++++ .../meshtastic_mqtt/client.py | 40 +++++++++-------- 6 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 .gitignore create mode 100644 pyproject.toml create mode 100644 setup.py create mode 100644 src/meshtastic_mqtt/__init__.py rename meshtastic_mqtt.py => src/meshtastic_mqtt/client.py (90%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcf6d95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Build artifacts +__pycache__/ +*.py[cod] +build/ +dist/ +*.egg-info/ +.eggs/ + +# Virtual environments +venv/ +env/ + +# Testing +.pytest_cache/ +.coverage +coverage.xml + +# IDE +.vscode/ +.idea/ + +# OS +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/README.md b/README.md index ef57709..67cd576 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ A lightweight Python library for parsing Meshtastic MQTT messages into JSON form This library connects to a Meshtastic MQTT broker and decodes various message types into JSON format, making it simple to process Meshtastic mesh network data in your Python applications. - ## Features - Connects to any Meshtastic MQTT broker @@ -16,16 +15,25 @@ This library connects to a Meshtastic MQTT broker and decodes various message ty - Message type filtering support - Simple command-line interface -## Installation +## Installation + +Install from PyPI: + ```bash -pip install cryptography protobuf meshtastic paho-mqtt +pip install pip install meshtastic-mqtt + ``` ## usage ```bash -python meshtastic_mqtt.py [options] +python meshtastic_mqtt [options] ``` +```python +from meshtastic_mqtt import MeshtasticMQTT +client = MeshtasticMQTT() +client.connect(broker='mqtt.meshtastic.org', port=1883, root='msh/US/2/e/', channel='LongFast', username='meshdev', password='large4cats', key='AQ==') +``` ### Command Line Options | Option | Description | Default | diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..aa9bc34 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = ["setuptools>=45", "wheel", "setuptools_scm>=6.2"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "src/meshtastic_mqtt/_version.py" \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..83e7daf --- /dev/null +++ b/setup.py @@ -0,0 +1,43 @@ +from setuptools import setup, find_packages + +setup( + name="meshtastic_mqtt", + version='0.1.0', + author='acidvegas', + author_email='acid.vegas@acid.vegas', + description='A lightweight Python library for parsing Meshtastic MQTT messages', + long_description=open('README.md').read(), + long_description_content_type='text/markdown', + url='https://github.com/acidvegas/meshtastic_mqtt', + project_urls={ + 'Bug Tracker' : 'https://github.com/acidvegas/meshtastic_mqtt/issues', + 'Documentation' : 'https://github.com/acidvegas/meshtastic_mqtt#readme', + 'Source Code' : 'https://github.com/acidvegas/meshtastic_mqtt', + }, + packages=find_packages(where='src'), + package_dir={'': 'src'}, + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: ISC License (ISCL)', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Topic :: Communications', + ], + python_requires='>=3.6', + install_requires=[ + 'cryptography', + 'protobuf', + 'meshtastic', + 'paho-mqtt', + ], + entry_points={ + 'console_scripts': [ + 'meshtastic-mqtt=meshtastic_mqtt.client:main', + ], + }, +) \ No newline at end of file diff --git a/src/meshtastic_mqtt/__init__.py b/src/meshtastic_mqtt/__init__.py new file mode 100644 index 0000000..f0f5c40 --- /dev/null +++ b/src/meshtastic_mqtt/__init__.py @@ -0,0 +1,9 @@ +""" +Meshtastic MQTT Interface - A lightweight Python library for parsing Meshtastic MQTT messages +""" + +from .client import MeshtasticMQTT + +__version__ = "0.1.0" +__author__ = "acidvegas" +__license__ = "ISC" \ No newline at end of file diff --git a/meshtastic_mqtt.py b/src/meshtastic_mqtt/client.py similarity index 90% rename from meshtastic_mqtt.py rename to src/meshtastic_mqtt/client.py index 2ab943c..f8434c5 100644 --- a/meshtastic_mqtt.py +++ b/src/meshtastic_mqtt/client.py @@ -26,6 +26,7 @@ try: except ImportError: raise ImportError('missing the paho-mqtt module (pip install paho-mqtt)') + class MeshtasticMQTT(object): def __init__(self): '''Initialize the Meshtastic MQTT client''' @@ -301,21 +302,26 @@ class MeshtasticMQTT(object): print(mp) -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Meshtastic MQTT Interface') - parser.add_argument('--broker', default='mqtt.meshtastic.org', help='MQTT broker address') - parser.add_argument('--port', default=1883, type=int, help='MQTT broker port') - parser.add_argument('--root', default='msh/US/2/e/', help='Root topic') - parser.add_argument('--channel', default='LongFast', help='Channel name') - parser.add_argument('--username', default='meshdev', help='MQTT username') - parser.add_argument('--password', default='large4cats', help='MQTT password') - parser.add_argument('--key', default='AQ==', help='Encryption key') - parser.add_argument('--filter', help='Filter message types (comma-separated). Example: NODEINFO,POSITION,TEXT_MESSAGE') - args = parser.parse_args() +def main(): + parser = argparse.ArgumentParser(description='Meshtastic MQTT Interface') + parser.add_argument('--broker', default='mqtt.meshtastic.org', help='MQTT broker address') + parser.add_argument('--port', default=1883, type=int, help='MQTT broker port') + parser.add_argument('--root', default='msh/US/2/e/', help='Root topic') + parser.add_argument('--channel', default='LongFast', help='Channel name') + parser.add_argument('--username', default='meshdev', help='MQTT username') + parser.add_argument('--password', default='large4cats', help='MQTT password') + parser.add_argument('--key', default='AQ==', help='Encryption key') + parser.add_argument('--filter', help='Filter message types (comma-separated). Example: NODEINFO,POSITION,TEXT_MESSAGE') + args = parser.parse_args() - client = MeshtasticMQTT() - if args.filter: - client.filters = [f'{f.strip()}_APP' for f in args.filter.upper().split(',')] - else: - client.filters = None - client.connect(args.broker, args.port, args.root, args.channel, args.username, args.password, args.key) + client = MeshtasticMQTT() + if args.filter: + client.filters = [f'{f.strip()}_APP' for f in args.filter.upper().split(',')] + else: + client.filters = None + client.connect(args.broker, args.port, args.root, args.channel, args.username, args.password, args.key) + + + +if __name__ == '__main__': + main() \ No newline at end of file