Add lights
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
# ---> Python
|
# ---> Python
|
||||||
|
log_!*.json
|
||||||
config.json
|
config.json
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ class MeshtasticController:
|
|||||||
"mute_public_commands": True,
|
"mute_public_commands": True,
|
||||||
"print_all_packets": False,
|
"print_all_packets": False,
|
||||||
}
|
}
|
||||||
|
self.config_file = self.get_config_file_path()
|
||||||
|
if os.path.exists(self.config_file):
|
||||||
|
self.ollama_url = self.load_config(self.config_file, 'url')
|
||||||
|
self.light_url = self.load_config(self.config_file, 'lightwebhook')
|
||||||
self.ollama_host = "http://localhost:11434/api/chat"
|
self.ollama_host = "http://localhost:11434/api/chat"
|
||||||
self.ollama_url = ''
|
self.ollama_url = ''
|
||||||
self.ollama_model = 'qwen2.5-coder:0.5b'
|
self.ollama_model = 'qwen2.5-coder:0.5b'
|
||||||
@@ -75,11 +79,36 @@ class MeshtasticController:
|
|||||||
"!llm": self.handle_llm,
|
"!llm": self.handle_llm,
|
||||||
"hey": self.handle_hey,
|
"hey": self.handle_hey,
|
||||||
"\N{LIZARD}": self.handle_lizard,
|
"\N{LIZARD}": self.handle_lizard,
|
||||||
|
"!light": self.handle_light,
|
||||||
}
|
}
|
||||||
self.private_commands = set(self.commands.keys()) - self.public_commands
|
self.private_commands = set(self.commands.keys()) - self.public_commands
|
||||||
self.config_file = self.get_config_file_path()
|
|
||||||
if os.path.exists(self.config_file):
|
|
||||||
self.ollama_url = self.load_config(self.config_file, 'url')
|
|
||||||
|
def handle_light(self, message, from_node, packet):
|
||||||
|
"""Runs the message through ollama."""
|
||||||
|
try:
|
||||||
|
# URL to which the request will be sent
|
||||||
|
url = self.light_url
|
||||||
|
|
||||||
|
# Data payload for POST request (optional)
|
||||||
|
data = {
|
||||||
|
"key": "value",
|
||||||
|
"message": message
|
||||||
|
}
|
||||||
|
# Sending a GET request
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
#print("GET Request Successful")
|
||||||
|
#print(response.json())
|
||||||
|
self.schedule_command_message("Toggled light", from_node)
|
||||||
|
else:
|
||||||
|
error_message = f"Error: {response.status_code} - {response.text}"
|
||||||
|
self.schedule_command_message(error_message, from_node)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
# Handle any errors that occur during the subprocess execution
|
||||||
|
error_message = f"Error running LLM: {e.stderr}"
|
||||||
|
self.schedule_command_message(error_message, from_node)
|
||||||
|
|
||||||
def load_logs(self):
|
def load_logs(self):
|
||||||
# Load existing logs from files into memory
|
# Load existing logs from files into memory
|
||||||
@@ -193,12 +222,12 @@ class MeshtasticController:
|
|||||||
config_file = "config.json"
|
config_file = "config.json"
|
||||||
return os.path.join(current_dir, config_file)
|
return os.path.join(current_dir, config_file)
|
||||||
|
|
||||||
def load_config(self, file, key):
|
def load_config(self, file_path, key):
|
||||||
if os.path.exists(file):
|
if os.path.exists(file_path):
|
||||||
with open(file, 'r') as self.config_file:
|
with open(file_path, 'r') as config_file:
|
||||||
config = json.load(self.config_file)
|
config = json.load(config_file)
|
||||||
value = config[key]
|
value = config.get(key)
|
||||||
if self.config["debug"]: print(value)
|
if self.config.get("debug", False): print(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def handle_lizard(self, message, from_node, packet):
|
def handle_lizard(self, message, from_node, packet):
|
||||||
@@ -522,7 +551,7 @@ class MeshtasticController:
|
|||||||
"""Callback function for handling received packets and processing commands."""
|
"""Callback function for handling received packets and processing commands."""
|
||||||
try:
|
try:
|
||||||
if self.config["print_all_packets"]: print(f"\n{packet}")
|
if self.config["print_all_packets"]: print(f"\n{packet}")
|
||||||
if 'decoded' in packet and packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
|
if 'decoded' in packet and packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP' and packet['toId'] != '^all':
|
||||||
message_bytes = packet['decoded']['payload']
|
message_bytes = packet['decoded']['payload']
|
||||||
message_string = message_bytes.decode('utf-8')
|
message_string = message_bytes.decode('utf-8')
|
||||||
from_node = packet['fromId'] # Get the node ID of the sender
|
from_node = packet['fromId'] # Get the node ID of the sender
|
||||||
|
|||||||
Reference in New Issue
Block a user