From 0de71c9f1366bb0bff756b944c05e4fdbb5916db Mon Sep 17 00:00:00 2001 From: madeofstown <33820964+madeofstown@users.noreply.github.com> Date: Sun, 16 Feb 2025 17:37:34 -0800 Subject: [PATCH 1/5] Update README.md first mention of config.ini --- README.md | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bfb8c9b..b1d0bd3 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,17 @@ -Meshview -======== - -Now running at https://meshview.bayme.sh +# Meshview This project watches a MQTT topic for meshtastic messages, imports them to a database and has a web UI to view them. Requires Python 3.12 -Running -------- +## Preparing + Clone the repo from github with: ``` bash git clone --recurse-submodules https://github.com/pablorevilla-meshtastic/meshview.git ``` -It is important to include the `--recurse-submodules` flag or the meshtastic protobufs wont be included +> [!NOTE] +> It is important to include the `--recurse-submodules` flag or the meshtastic protobufs won't be included. Create a python virtual environment: ``` bash @@ -28,23 +26,16 @@ You also need to install `graphviz`: ``` bash sudo apt-get install graphviz ``` +Edit `config.ini` to change the MQTT server and topic + +Other Options: +* `port` + + Web server port, default is `8081` + +## Running Meshview -To run Meshview: ``` bash ./env/bin/python main.py ``` Now you can hit http://localhost/ - -Other Options: -* `--port` - - Web server port, default is `8081` - -* `--mqtt-server` - - MQTT Server, default is `mqtt.bayme.sh` - -* `--topic` - - MQTT Topic, default is `msh/US/bayarea/#` - From 076abb5811a592e5aea69e7306c55dca25f0cbcc Mon Sep 17 00:00:00 2001 From: madeofstown Date: Mon, 17 Feb 2025 13:04:42 -0800 Subject: [PATCH 2/5] First changes - pre test --- config.ini | 7 +++++-- main.py | 13 ++++++++++--- meshview/mqtt_reader.py | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config.ini b/config.ini index 6798a8e..c7d36b4 100644 --- a/config.ini +++ b/config.ini @@ -5,8 +5,11 @@ tls_cert = acme_challenge = [mqtt] -server = mqtt.bayme.sh -topics = msh/US/bayarea/# +server = 'mqtt.bayme.sh' +topics = ['msh/US/bayarea/#'] +port = 1883 +username = 'meshdev' +password = 'large4cats' [database] connection_string = sqlite+aiosqlite:///packets.db \ No newline at end of file diff --git a/main.py b/main.py index 05d4c61..908a165 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,8 @@ from meshview import web from meshview import http -async def load_database_from_mqtt(mqtt_server, topic): - async for topic, env in mqtt_reader.get_topic_envelopes(mqtt_server, topic): +async def load_database_from_mqtt(mqtt_server: str , mqtt_port: int, topic: str, mqtt_user: str | None = None, mqtt_passwd: str | None = None): + async for topic, env in mqtt_reader.get_topic_envelopes(mqtt_server, mqtt_port, topic, mqtt_user, mqtt_passwd): await store.process_envelope(topic, env) @@ -17,9 +17,16 @@ async def main(config): database.init_database(config["database"]["connection_string"]) await database.create_tables() + mqtt_user = None + mqtt_passwd = None + if config["mqtt"]["username"] != "": + mqtt_user: str = config["mqtt"]["username"] + if config["mqtt"]["password"] != "": + mqtt_passwd: str = config["mqtt"]["password"] + async with asyncio.TaskGroup() as tg: tg.create_task( - load_database_from_mqtt(config["mqtt"]["server"], config["mqtt"]["topics"].split(",")) + load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), config["mqtt"]["topics"].split(","), mqtt_user, mqtt_passwd) ) tg.create_task( web.run_server( diff --git a/meshview/mqtt_reader.py b/meshview/mqtt_reader.py index 5453f5c..5215f98 100644 --- a/meshview/mqtt_reader.py +++ b/meshview/mqtt_reader.py @@ -25,12 +25,12 @@ def decrypt(packet): pass -async def get_topic_envelopes(mqtt_server, topics): +async def get_topic_envelopes(mqtt_server, mqtt_port, topics, mqtt_user, mqtt_passwd): identifier = str(random.getrandbits(16)) while True: try: async with aiomqtt.Client( - mqtt_server, username="meshdev", password="large4cats" , identifier=identifier, + mqtt_server, port=mqtt_port , username=mqtt_user, password=mqtt_passwd , identifier=identifier, ) as client: for topic in topics: await client.subscribe(topic) From c9d65a078af5e71a6815c142dbb11e5868f8885b Mon Sep 17 00:00:00 2001 From: madeofstown Date: Mon, 17 Feb 2025 13:49:34 -0800 Subject: [PATCH 3/5] changes after testing --- config.ini | 8 ++++---- main.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config.ini b/config.ini index c7d36b4..693429b 100644 --- a/config.ini +++ b/config.ini @@ -5,11 +5,11 @@ tls_cert = acme_challenge = [mqtt] -server = 'mqtt.bayme.sh' -topics = ['msh/US/bayarea/#'] +server = mqtt.bayme.sh +topics = ['msh/US/bayarea/#', 'msh/US/CA/mrymesh/#'] port = 1883 -username = 'meshdev' -password = 'large4cats' +username = meshdev +password = large4cats [database] connection_string = sqlite+aiosqlite:///packets.db \ No newline at end of file diff --git a/main.py b/main.py index 908a165..7accc67 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,7 @@ async def main(config): async with asyncio.TaskGroup() as tg: tg.create_task( - load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), config["mqtt"]["topics"].split(","), mqtt_user, mqtt_passwd) + load_database_from_mqtt(config["mqtt"]["server"], int(config["mqtt"]["port"]), config["mqtt"]["topics"], mqtt_user, mqtt_passwd) ) tg.create_task( web.run_server( From c8567fec6e7a8f6b6a133076ba6e9b3cb4dd9000 Mon Sep 17 00:00:00 2001 From: madeofstown <33820964+madeofstown@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:24:51 -0800 Subject: [PATCH 4/5] Update README.md More changes to reflect the addition of `config.ini` --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b1d0bd3..0865e74 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,14 @@ You also need to install `graphviz`: ``` bash sudo apt-get install graphviz ``` -Edit `config.ini` to change the MQTT server and topic +Edit `config.ini` to change the MQTT server, username, password, and topic(s) as necessary. -Other Options: -* `port` - - Web server port, default is `8081` +You may also change the web server port from the ***default 8081***. +https://github.com/madeofstown/meshview/blob/c9d65a078af5e71a6815c142dbb11e5868f8885b/config.ini#L1-L15 ## Running Meshview ``` bash ./env/bin/python main.py ``` -Now you can hit http://localhost/ +Now you can hit http://localhost:8081/ From 6406efffe801ef75c7c99925fe402fe306a48b05 Mon Sep 17 00:00:00 2001 From: madeofstown <33820964+madeofstown@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:28:06 -0800 Subject: [PATCH 5/5] Update README.md Make python and graphviz requirements more clear --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0865e74..fae142f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ This project watches a MQTT topic for meshtastic messages, imports them to a database and has a web UI to view them. -Requires Python 3.12 + +Requires **`python3.12`** and **`graphviz`**. ## Preparing