diff --git a/README.md b/README.md index 3ed50eb..d180c95 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,10 @@ This will start the server locally. To expose it to the internet, it's recommend - `/api/mesh/get_last_messages`: GET endpoint to retrieve the last cached messages. +- `/api/mesh/delete_message`: POST endpoint to delete a message from the local cache. + - Parameters: + - `message_id` (str): The messageid to be deleted. + - `/api/mesh/nodes`: GET endpoint to list all seen nodes. - `/api/mesh/status`: GET endpoint to check connection status. diff --git a/meshttpd.py b/meshttpd.py index 3cea511..70e7488 100644 --- a/meshttpd.py +++ b/meshttpd.py @@ -6,6 +6,8 @@ import meshtastic import meshtastic.tcp_interface import json import datetime +import hashlib +import random class MeshAPI(object): def __init__(self, hostname='meshtastic.local'): @@ -17,12 +19,12 @@ class MeshAPI(object): """ self.hostname = hostname self.iface = None - self.device_telemetry_cache = {} - self.environment_telemetry_cache = {} - self.message_cache = [] - self.seen_nodes = {} - self.connection_attempts = 0 - self.last_connection_time = None + self.device_telemetry_cache = {} # Cache to store device telemetry data + self.environment_telemetry_cache = {} # Cache to store environment telemetry data + self.message_cache = {} # Cache to store messages + self.seen_nodes = {} # Dictionary to store information about seen nodes + self.connection_attempts = 0 # Number of connection attempts made + self.last_connection_time = None # Time of the last successful connection self.connection_thread = threading.Thread(target=self.connect_to_mesh, daemon=True) def on_receive(self, packet, interface): @@ -64,7 +66,8 @@ class MeshAPI(object): if 'decoded' in packet and 'text' in packet['decoded']: node_id = packet['from'] message_data = packet['decoded']['text'] - self.message_cache.append({"node_id": node_id, "message": message_data}) + internal_message_id = self.generate_internal_message_id(node_id, message_data) + self.message_cache[internal_message_id] = {"node_id": node_id, "message": message_data} if len(self.message_cache) > 100: self.message_cache.pop(0) @@ -78,7 +81,6 @@ class MeshAPI(object): def on_connection(self, interface, topic=pub.AUTO_TOPIC): """ Callback function called when we (re)connect to the radio. - If you have poor wifi coverage like in my case this is essential. """ self.last_connection_time = time.time() self.connection_attempts += 1 @@ -87,7 +89,7 @@ class MeshAPI(object): @cherrypy.expose def index(self): """ - Exposed endpoint for the poors man swagger! + Exposed endpoint for the index page. """ html = """ @@ -140,6 +142,16 @@ class MeshAPI(object):
Made by luhf for Monocul.us Mesh
+Made by luhf for Monocul.us Mesh