diff --git a/common/watcher.py b/common/watcher.py index 5fcab2d..6ebb60c 100644 --- a/common/watcher.py +++ b/common/watcher.py @@ -5,6 +5,7 @@ import json watcher_sock = None class Watcher: + @staticmethod def ensure_socket_connected(): global watcher_sock if watcher_sock is None or watcher_sock.fileno() == -1: # Checks if socket is not initialized or closed @@ -16,19 +17,17 @@ class Watcher: # If connection fails, set sock to None and do nothing watcher_sock = None + @staticmethod def log_watch(var_name, message): global watcher_sock - self.ensure_socket_connected() # Ensure the socket is connected before attempting to log + Watcher.ensure_socket_connected() # Ensure the socket is connected before attempting to log if watcher_sock: # Proceed only if sock is not None (i.e., is connected) - message_json = json.dumps(message) + message_json = json.dumps({var_name: message}) try: watcher_sock.sendall(message_json.encode('utf-8') + b'\n') except socket.error: - nothing=False # Handle potential error in sending (e.g., if connection was lost) - watcher_sock.close() # Close the current socket to clean up resources - watcher_sock = None # Reset sock to ensure reconnection attempt on next call - -#message = {"variable": "car_stats", "value": {"car_lights_on": [3, 5, 7], "car_state": "on"}} -#log_watch(sock, message) - + watcher_sock = None # Ensure that the next attempt will try to reconnect + finally: + watcher_sock.close() # Close the current socket to clean up resources + watcher_sock = None # Reset sock to ensure reconnection attempt on next call diff --git a/shell/watcher.js b/shell/watcher.js index 7715219..d1a3c95 100644 --- a/shell/watcher.js +++ b/shell/watcher.js @@ -44,6 +44,7 @@ unix_socket_server.listen(socketPath, () => { }); function processMessage(message) { + console.log(message); try { const { variable, value } = JSON.parse(message); const diff = calculateDiff(progvars[variable], value); diff --git a/system/timezoned.py b/system/timezoned.py index b46c6e0..9b1d2be 100755 --- a/system/timezoned.py +++ b/system/timezoned.py @@ -16,7 +16,6 @@ from openpilot.common.watcher import Watcher REQUEST_HEADERS = {'User-Agent': "openpilot-" + get_version()} - def set_timezone(valid_timezones, timezone): if timezone not in valid_timezones: cloudlog.error(f"Timezone not supported {timezone}") @@ -48,6 +47,8 @@ def main() -> NoReturn: set_timezone(valid_timezones, timezone) while True: + Watcher.log_watch("location", "starting") + time.sleep(60) location = params.get("LastGPSPosition", encoding='utf8')