Receive form data

This commit is contained in:
2025-12-31 15:17:04 +01:00
parent 139b3992d8
commit aeb4bd74d9
3 changed files with 19 additions and 13 deletions

Binary file not shown.

View File

@@ -4,7 +4,7 @@ import os
import cv2 import cv2
import requests import requests
from dotenv import load_dotenv from dotenv import load_dotenv
from flask import Flask, jsonify from flask import Flask, jsonify, request
from hardware.light.lora_light_sensor_reader import LoraLightSensorReader from hardware.light.lora_light_sensor_reader import LoraLightSensorReader
from hardware.rfid.reader import RfidReader from hardware.rfid.reader import RfidReader
@@ -55,6 +55,8 @@ game_service = GameService()
@app.route("/command/party/start", methods=['POST']) @app.route("/command/party/start", methods=['POST'])
def start_party(): def start_party():
try: try:
data = request.get_json()
print(f"Received data : {data}")
print("Party started!") print("Party started!")
return jsonify({"status": "ok", "message": "Party started"}), 200 return jsonify({"status": "ok", "message": "Party started"}), 200
except Exception as ex: except Exception as ex:
@@ -64,16 +66,8 @@ def start_party():
@app.route("/command/party/play", methods=['POST']) @app.route("/command/party/play", methods=['POST'])
def make_move(): def make_move():
try: try:
frame, fen = game_service.make_move() game_service.make_move()
print(fen)
headers = {'Content-Type': 'image/jpeg'}
body = {'frame': frame, 'fen': fen}
response = requests.post(
"https://192.168.15.125:1880/party/image",
data=body,
headers=headers,
verify=False)
print(response.status_code)
return jsonify({"status": "ok", "message": "Party started"}), 200 return jsonify({"status": "ok", "message": "Party started"}), 200
except Exception as ex: except Exception as ex:
print(ex) print(ex)

View File

@@ -23,5 +23,17 @@ class GameService:
self.clock_service.stop() self.clock_service.stop()
self.detection_service.stop() self.detection_service.stop()
def make_move(self) -> tuple[bytes, str]: def make_move(self) -> None:
return self.detection_service.analyze_single_frame() try :
frame, fen = self.detection_service.analyze_single_frame()
print(fen)
headers = {'Content-Type': 'image/jpeg'}
body = {'frame': frame, 'fen': fen}
response = requests.post(
"https://192.168.15.125:1880/party/image",
data=body,
headers=headers,
verify=False)
print(response.status_code)
except Exception as e:
print(e)