mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
First changes - pre test
This commit is contained in:
@@ -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
|
||||
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"].split(","), 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