From 41d642520b2c14bd7674ba494649bea0cd1fd4c6 Mon Sep 17 00:00:00 2001 From: zyp <1721777650@qq.com> Date: Wed, 30 Oct 2024 21:12:00 +0800 Subject: [PATCH] change background picture add the communication between zhencha and controler --- carsrun/appCam.py | 26 ++++++++++++++++++++++++++ carsrun/templates/index-t.html | 25 +++++++++++++++++++++++++ public/images/1.jpg | Bin 128730 -> 520669 bytes public/images/11.jpg | Bin 0 -> 128730 bytes public/images/2.jpg | Bin 520669 -> 0 bytes 5 files changed, 51 insertions(+) create mode 100644 public/images/11.jpg delete mode 100644 public/images/2.jpg diff --git a/carsrun/appCam.py b/carsrun/appCam.py index 134eb93..0e85ee3 100644 --- a/carsrun/appCam.py +++ b/carsrun/appCam.py @@ -19,6 +19,7 @@ from car import CAR #from PiCamera_H264_Server import stream import threading import cv2 +import requests app = Flask(__name__, static_url_path='') # 照片保存路径 PHOTO_PATH = "photo.jpg" @@ -66,6 +67,31 @@ def gen_frames(): # generate frame by frame from camera # def capture_frame_route(): # img_str = capture_frame() # return jsonify(img_str) +@app.route('/control/sendit', methods=['POST']) +def send_command(): + # 定义目标 IP 地址、端口和路由 + ip = "192.168.98.204" + port = 3000 + route = "sendit2" + + # 从请求中获取消息内容 + data = request.json + message = data.get('message') + + if message is None: + return jsonify({"error": "缺少 message 参数"}), 400 + + # 构建完整的 URL + url = f"http://{ip}:{port}/{route}" + + # 发送 POST 请求 + try: + response = requests.post(url, json={'message': message}) + response.raise_for_status() # 检查请求是否成功 + return f"命令已发送,服务器响应: {response.text}" + except requests.exceptions.RequestException as e: + return f"请求失败: {str(e)}", 500 + @app.route('/capture') def capture_image(): global picam2 diff --git a/carsrun/templates/index-t.html b/carsrun/templates/index-t.html index 80f625a..8a987bd 100644 --- a/carsrun/templates/index-t.html +++ b/carsrun/templates/index-t.html @@ -67,6 +67,12 @@ +