mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Merge pull request #2 from madeofstown/configini
Merge configini branch into master
This commit is contained in:
38
README.md
38
README.md
@@ -1,19 +1,18 @@
|
||||
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
|
||||
-------
|
||||
Requires **`python3.12`** and **`graphviz`**.
|
||||
|
||||
## 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 +27,14 @@ You also need to install `graphviz`:
|
||||
``` bash
|
||||
sudo apt-get install graphviz
|
||||
```
|
||||
Edit `config.ini` to change the MQTT server, username, password, and topic(s) as necessary.
|
||||
|
||||
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
|
||||
|
||||
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/#`
|
||||
|
||||
Now you can hit http://localhost:8081/
|
||||
|
||||
@@ -6,7 +6,10 @@ acme_challenge =
|
||||
|
||||
[mqtt]
|
||||
server = mqtt.bayme.sh
|
||||
topics = msh/US/bayarea/#
|
||||
topics = ['msh/US/bayarea/#', 'msh/US/CA/mrymesh/#']
|
||||
port = 1883
|
||||
username = meshdev
|
||||
password = large4cats
|
||||
|
||||
[database]
|
||||
connection_string = sqlite+aiosqlite:///packets.db
|
||||
13
main.py
13
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"], mqtt_user, mqtt_passwd)
|
||||
)
|
||||
tg.create_task(
|
||||
web.run_server(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user