Authentificate to API
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
zeJlYcaW0dji4A88Q3OGfvqgqXUuUAm0
|
||||||
+13
-1
@@ -72,7 +72,17 @@ def get_device_id():
|
|||||||
pass
|
pass
|
||||||
return "RPI_Orchestrateur_Default"
|
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()
|
DEVICE_ID = get_device_id()
|
||||||
|
API_KEY = get_api_key()
|
||||||
|
|
||||||
# --- DISPLAY QUEUE & NOTIFICATION HELPERS ---
|
# --- DISPLAY QUEUE & NOTIFICATION HELPERS ---
|
||||||
display_update_queue = None
|
display_update_queue = None
|
||||||
@@ -310,6 +320,7 @@ def on_new_alert(alert: Alert):
|
|||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
"https://smartwave.matthiasg.dev/alert",
|
"https://smartwave.matthiasg.dev/alert",
|
||||||
|
headers={"Content-Type": "application/json", "X-API-Key": API_KEY},
|
||||||
json=payload,
|
json=payload,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -447,6 +458,7 @@ async def request_cloud_cooking_plan(microwave_id, sensors_data):
|
|||||||
requests.post,
|
requests.post,
|
||||||
URL,
|
URL,
|
||||||
json=sensors_data,
|
json=sensors_data,
|
||||||
|
headers={"Content-Type": "application/json", "X-API-Key": API_KEY},
|
||||||
timeout=HTTP_TIMEOUT
|
timeout=HTTP_TIMEOUT
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -666,7 +678,7 @@ async def handle_telemetry_request(endpoint: str, do_timeout=True):
|
|||||||
requests.post,
|
requests.post,
|
||||||
endpoint,
|
endpoint,
|
||||||
data=telemetry_payload, # <-- Changed from json=telemetry_payload
|
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
|
timeout=15
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user