diff --git a/orchestrateur/device_api.txt b/orchestrateur/device_api.txt new file mode 100644 index 0000000..a2718d4 --- /dev/null +++ b/orchestrateur/device_api.txt @@ -0,0 +1 @@ +zeJlYcaW0dji4A88Q3OGfvqgqXUuUAm0 \ No newline at end of file diff --git a/orchestrateur/main.py b/orchestrateur/main.py index 569fd44..4daedec 100644 --- a/orchestrateur/main.py +++ b/orchestrateur/main.py @@ -72,7 +72,17 @@ def get_device_id(): pass return "RPI_Orchestrateur_Default" +def get_api_key(): + for path in ["api_key.txt", "/home/pi/SmartWave/orchestrateur/api_key.txt"]: + try: + with open(path, "r") as f: + return f.read().strip() + except Exception: + pass + return "" + DEVICE_ID = get_device_id() +API_KEY = get_api_key() # --- DISPLAY QUEUE & NOTIFICATION HELPERS --- display_update_queue = None @@ -310,6 +320,7 @@ def on_new_alert(alert: Alert): response = requests.post( "https://smartwave.matthiasg.dev/alert", + headers={"Content-Type": "application/json", "X-API-Key": API_KEY}, json=payload, ) @@ -447,6 +458,7 @@ async def request_cloud_cooking_plan(microwave_id, sensors_data): requests.post, URL, json=sensors_data, + headers={"Content-Type": "application/json", "X-API-Key": API_KEY}, timeout=HTTP_TIMEOUT ) @@ -666,7 +678,7 @@ async def handle_telemetry_request(endpoint: str, do_timeout=True): requests.post, endpoint, data=telemetry_payload, # <-- Changed from json=telemetry_payload - headers={"Content-Type": "application/json"}, + headers={"Content-Type": "application/json", "X-API-Key": API_KEY}, timeout=15 )