Added logic writing ploop setpooint and removed webhooks temporarily

This commit is contained in:
AzureAD\AniketSaha 2025-07-08 17:14:41 +02:00
parent 73048e2bd5
commit 1fa393c6a9
2 changed files with 21 additions and 19 deletions

View File

@ -63,7 +63,6 @@ class CANBackend:
pass
def send_state_command(self, state: str, pu_number: int, ploop_setpoint:float):
#TODO : link ploop_setpoint
if not self.connected:
raise RuntimeError("CAN not connected")
@ -81,6 +80,11 @@ class CANBackend:
try:
print(f"[DEBUG] Writing state {state_map[state]} to index 0x2024, subindex {pu_number}")
self.node.sdo[0x2024][0x01].raw = state_map[state]
# Write the ploop setpoint to its own index/subindex
print(f"[DEBUG] Writing ploop_setpoint {ploop_setpoint} to index 0x2007, subindex {0x00}")
self.node.sdo[2007][0x00].raw = int(ploop_setpoint * 100)
except Exception as e:
print(f"[SDO WRITE ERROR] Failed to write to 0x2024:{pu_number} - {e}")
raise

34
main.py
View File

@ -18,28 +18,26 @@ logging.basicConfig(level=logging.INFO)
can_backend = CANBackend()
# Serve static files (HTML, JS, CSS)
app.mount("/static", StaticFiles(directory="static"), name="static")
@router.post("/webhook")
async def github_webhook(request: Request):
payload = await request.json()
print("[WEBHOOK] Received webhook:", payload.get("head_commit", {}).get("message"))
try:
# Call the update script on the HOST using host bash
subprocess.run(
["/usr/bin/bash", "-c", "bash /home/hmi/Desktop/HMI/update_hmi.sh"],
check=True,
capture_output=True,
text=True
)
return {"status": "Update triggered"}
except subprocess.CalledProcessError as e:
print(f"[WEBHOOK] Update failed:\n{e.stderr}")
return {"status": "Update failed", "error": str(e)}
# @router.post("/webhook")
# async def github_webhook(request: Request):
# payload = await request.json()
# print("[WEBHOOK] Received webhook:", payload.get("head_commit", {}).get("message"))
# try:
# # Call the update script on the HOST using host bash
# subprocess.run(
# ["/usr/bin/bash", "-c", "bash /home/hmi/Desktop/HMI/update_hmi.sh"],
# check=True,
# capture_output=True,
# text=True
# )
# return {"status": "Update triggered"}
# except subprocess.CalledProcessError as e:
# print(f"[WEBHOOK] Update failed:\n{e.stderr}")
# return {"status": "Update failed", "error": str(e)}
@app.post("/connect_toggle")