MeshDD-Bot/main.py
ppfeiffer 15955cf8d7 feat: Add Meshtastic bot with web dashboard and live map
Implements full MeshDD-Bot with TCP connection to Meshtastic devices,
SQLite storage for nodes/messages, aiohttp web dashboard with WebSocket
live updates, and Leaflet.js map view with color-coded node markers.
Includes bot commands (!ping, !nodes, !info, !help, !weather, !stats,
!uptime) and automatic version bumping via pre-commit hook.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 12:46:32 +01:00

63 lines
1.5 KiB
Python

import asyncio
import logging
import signal
import threading
from meshbot import config, VERSION
from meshbot.database import Database
from meshbot.bot import MeshBot
from meshbot.webserver import WebServer, WebSocketManager
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
async def main():
logger.info("Starting %s v%s", config.BOT_NAME, VERSION)
# Database
db = Database(config.DB_PATH)
await db.connect()
# WebSocket Manager
ws_manager = WebSocketManager()
# Bot
loop = asyncio.get_event_loop()
bot = MeshBot(db, loop)
bot.ws_manager = ws_manager
# Webserver
webserver = WebServer(db, ws_manager)
runner = await webserver.start(config.WEB_HOST, config.WEB_PORT)
# Connect Meshtastic in a thread (blocking call)
connect_thread = threading.Thread(target=bot.connect, daemon=True)
connect_thread.start()
# Wait for shutdown
stop_event = asyncio.Event()
def _signal_handler():
logger.info("Shutdown signal received")
stop_event.set()
for sig in (signal.SIGINT, signal.SIGTERM):
loop.add_signal_handler(sig, _signal_handler)
try:
await stop_event.wait()
finally:
logger.info("Shutting down...")
bot.disconnect()
await runner.cleanup()
await db.close()
logger.info("Shutdown complete")
if __name__ == "__main__":
asyncio.run(main())