change background picture

add the communication between zhencha and controler
pull/4/head
zyp 4 weeks ago
parent 70c4cfbed4
commit 41d642520b

@ -19,6 +19,7 @@ from car import CAR
#from PiCamera_H264_Server import stream #from PiCamera_H264_Server import stream
import threading import threading
import cv2 import cv2
import requests
app = Flask(__name__, static_url_path='') app = Flask(__name__, static_url_path='')
# 照片保存路径 # 照片保存路径
PHOTO_PATH = "photo.jpg" PHOTO_PATH = "photo.jpg"
@ -66,6 +67,31 @@ def gen_frames(): # generate frame by frame from camera
# def capture_frame_route(): # def capture_frame_route():
# img_str = capture_frame() # img_str = capture_frame()
# return jsonify(img_str) # 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') @app.route('/capture')
def capture_image(): def capture_image():
global picam2 global picam2

@ -67,6 +67,12 @@
</div> </div>
<button id="down" type="button" onclick="down()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-down" style="margin-left: 56px;"> </button> <button id="down" type="button" onclick="down()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-down" style="margin-left: 56px;"> </button>
</div> </div>
<div>
<form id="sendCommandForm">
回复指令: <textarea id="message"></textarea><br>
<button type="button" onclick="sendCommand()">发送指令</button>
</form>
</div>
</div> </div>
<script src='/Decoder.js'></script> <script src='/Decoder.js'></script>
@ -99,6 +105,25 @@
<script> <script>
function sendCommand() {
var message = document.getElementById('message').value;
$.ajax({
type: "POST",
url: "/control/sendit",
data: JSON.stringify({
message: message
}),
contentType: "application/json",
success: function (result) {
console.log(result);
alert("指令发送成功!");
},
error: function (error) {
console.log('Error:', error);
}
});
}
function capture() { function capture() {
console.log("132465789891651354684"); console.log("132465789891651354684");
$.ajax({ $.ajax({

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 508 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 KiB

Loading…
Cancel
Save