kopia lustrzana https://github.com/mate-dev/meshtastic-matrix-relay
Merge branch 'geoffwhittington:main' into main
commit
e0228ff4f0
|
@ -1,39 +1,34 @@
|
|||
import os
|
||||
import sys
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
from log_utils import get_logger
|
||||
from plugins.health_plugin import Plugin as HealthPlugin
|
||||
from plugins.map_plugin import Plugin as MapPlugin
|
||||
from plugins.mesh_relay_plugin import Plugin as MeshRelayPlugin
|
||||
from plugins.ping_plugin import Plugin as PingPlugin
|
||||
from plugins.telemetry_plugin import Plugin as TelemetryPlugin
|
||||
from plugins.weather_plugin import Plugin as WeatherPlugin
|
||||
|
||||
# Get the path to the PyInstaller script
|
||||
launch_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
from log_utils import get_logger
|
||||
|
||||
logger = get_logger(name="Plugins")
|
||||
|
||||
plugins = []
|
||||
active_plugins = []
|
||||
|
||||
|
||||
def load_plugins():
|
||||
global plugins
|
||||
if plugins:
|
||||
return plugins
|
||||
if active_plugins:
|
||||
return active_plugins
|
||||
|
||||
plugins = []
|
||||
plugin_dirs = [Path("plugins"), Path(launch_dir, "custom_plugins")]
|
||||
plugins = [
|
||||
HealthPlugin(),
|
||||
MapPlugin(),
|
||||
MeshRelayPlugin(),
|
||||
PingPlugin(),
|
||||
TelemetryPlugin(),
|
||||
WeatherPlugin(),
|
||||
]
|
||||
|
||||
for plugin_folder in plugin_dirs:
|
||||
sys.path.insert(0, str(plugin_folder.resolve()))
|
||||
for plugin in plugins:
|
||||
if plugin.config["active"]:
|
||||
logger.info(f"Loaded {plugin.plugin_name}")
|
||||
active_plugins.append(plugin)
|
||||
|
||||
for plugin_file in plugin_folder.glob("*.py"):
|
||||
plugin_name = plugin_file.stem
|
||||
if plugin_name == "__init__":
|
||||
continue
|
||||
plugin_module = importlib.import_module(plugin_name)
|
||||
if hasattr(plugin_module, "Plugin"):
|
||||
plugin = plugin_module.Plugin()
|
||||
if plugin.config["active"]:
|
||||
logger.info(
|
||||
f"Loaded {os.path.basename(plugin_folder)}/{plugin_name}"
|
||||
)
|
||||
plugins.append(plugin)
|
||||
|
||||
return plugins
|
||||
return active_plugins
|
||||
|
|
|
@ -7,7 +7,6 @@ from db_utils import (
|
|||
get_plugin_data_for_node,
|
||||
delete_plugin_data,
|
||||
)
|
||||
from matrix_utils import bot_command
|
||||
|
||||
|
||||
class BasePlugin(ABC):
|
||||
|
@ -44,6 +43,8 @@ class BasePlugin(ABC):
|
|||
return get_plugin_data(self.plugin_name)
|
||||
|
||||
def matches(self, payload):
|
||||
from matrix_utils import bot_command
|
||||
|
||||
if type(payload) == str:
|
||||
return bot_command(self.plugin_name, payload)
|
||||
return False
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
import re
|
||||
import statistics
|
||||
from base_plugin import BasePlugin
|
||||
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
from plugins.base_plugin import BasePlugin
|
||||
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
plugin_name = "health"
|
||||
|
||||
def generate_response(self):
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
meshtastic_client = connect_meshtastic()
|
||||
battery_levels = []
|
||||
air_util_tx = []
|
||||
|
@ -44,6 +43,8 @@ SNR: {avg_snr:.2f} / {mdn_snr:.2f} (avg / median)
|
|||
return False
|
||||
|
||||
async def handle_room_message(self, room, event, full_message):
|
||||
from matrix_utils import connect_matrix
|
||||
|
||||
full_message = full_message.strip()
|
||||
if not self.matches(full_message):
|
||||
return False
|
||||
|
|
|
@ -5,11 +5,7 @@ import io
|
|||
import re
|
||||
from PIL import Image
|
||||
from nio import AsyncClient, UploadResponse
|
||||
from base_plugin import BasePlugin
|
||||
|
||||
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
from plugins.base_plugin import BasePlugin
|
||||
|
||||
|
||||
def anonymize_location(lat, lon, radius=1000):
|
||||
|
@ -93,6 +89,9 @@ class Plugin(BasePlugin):
|
|||
if not self.matches(full_message):
|
||||
return False
|
||||
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
matrix_client = await connect_matrix()
|
||||
meshtastic_client = connect_meshtastic()
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@ from meshtastic import mesh_pb2
|
|||
|
||||
from plugins.base_plugin import BasePlugin
|
||||
from config import relay_config
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
matrix_rooms: List[dict] = relay_config["matrix_rooms"]
|
||||
|
||||
|
@ -57,6 +55,8 @@ class Plugin(BasePlugin):
|
|||
async def handle_meshtastic_message(
|
||||
self, packet, formatted_message, longname, meshnet_name
|
||||
):
|
||||
from matrix_utils import connect_matrix
|
||||
|
||||
packet = self.process(packet)
|
||||
matrix_client = await connect_matrix()
|
||||
|
||||
|
@ -121,6 +121,8 @@ class Plugin(BasePlugin):
|
|||
self.logger.error(f"Error processing embedded packet: {e}")
|
||||
return
|
||||
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
meshtastic_client = connect_meshtastic()
|
||||
meshPacket = mesh_pb2.MeshPacket()
|
||||
meshPacket.channel = channel
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import re
|
||||
|
||||
from plugins.base_plugin import BasePlugin
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
|
@ -22,6 +20,8 @@ class Plugin(BasePlugin):
|
|||
if f"!{self.plugin_name}" not in message:
|
||||
return
|
||||
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
meshtastic_client = connect_meshtastic()
|
||||
meshtastic_client.sendText(text="pong!", destinationId=packet["fromId"])
|
||||
return True
|
||||
|
@ -31,6 +31,8 @@ class Plugin(BasePlugin):
|
|||
if not self.matches(full_message):
|
||||
return False
|
||||
|
||||
from matrix_utils import connect_matrix
|
||||
|
||||
matrix_client = await connect_matrix()
|
||||
response = await matrix_client.room_send(
|
||||
room_id=room.room_id,
|
|
@ -6,13 +6,15 @@ from PIL import Image
|
|||
from datetime import datetime, timedelta
|
||||
|
||||
from plugins.base_plugin import BasePlugin
|
||||
from matrix_utils import bot_command, connect_matrix, upload_image, send_room_image
|
||||
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
plugin_name = "telemetry"
|
||||
max_data_rows_per_node = 50
|
||||
|
||||
def commands(self):
|
||||
return ["batteryLevel", "voltage", "airUtilTx"]
|
||||
|
||||
def _generate_timeperiods(self, hours=12):
|
||||
# Calculate the start and end times
|
||||
end_time = datetime.now()
|
||||
|
@ -55,6 +57,8 @@ class Plugin(BasePlugin):
|
|||
return False
|
||||
|
||||
def matches(self, payload):
|
||||
from matrix_utils import bot_command
|
||||
|
||||
if type(payload) == str:
|
||||
for option in ["batteryLevel", "voltage", "airUtilTx"]:
|
||||
if bot_command(option, payload):
|
||||
|
@ -73,6 +77,8 @@ class Plugin(BasePlugin):
|
|||
telemetry_option = match.group(1)
|
||||
|
||||
hourly_intervals = self._generate_timeperiods()
|
||||
from matrix_utils import connect_matrix
|
||||
|
||||
matrix_client = await connect_matrix()
|
||||
|
||||
# Compute the hourly averages for each node
|
||||
|
@ -131,6 +137,8 @@ class Plugin(BasePlugin):
|
|||
img = Image.open(buf)
|
||||
pil_image = Image.frombytes(mode="RGBA", size=img.size, data=img.tobytes())
|
||||
|
||||
from matrix_utils import upload_image, send_room_image
|
||||
|
||||
upload_response = await upload_image(matrix_client, pil_image, "graph.png")
|
||||
await send_room_image(matrix_client, room.room_id, upload_response)
|
||||
return True
|
|
@ -2,8 +2,6 @@ import re
|
|||
import requests
|
||||
|
||||
from plugins.base_plugin import BasePlugin
|
||||
from matrix_utils import connect_matrix
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
|
||||
class Plugin(BasePlugin):
|
||||
|
@ -80,6 +78,8 @@ class Plugin(BasePlugin):
|
|||
if f"!{self.plugin_name}" not in message:
|
||||
return False
|
||||
|
||||
from meshtastic_utils import connect_meshtastic
|
||||
|
||||
meshtastic_client = connect_meshtastic()
|
||||
if packet["fromId"] in meshtastic_client.nodes:
|
||||
weather_notice = "Cannot determine location"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
meshtastic==2.1.6
|
||||
py-staticmaps==0.4.0
|
||||
matrix-nio==0.20.2
|
||||
matplotlib==3.7.1
|
||||
matplotlib==3.7.1
|
||||
requests
|
Ładowanie…
Reference in New Issue