diff --git a/carsrun/__pycache__/car.cpython-311.pyc b/carsrun/__pycache__/car.cpython-311.pyc
index 196df95..3141b73 100644
Binary files a/carsrun/__pycache__/car.cpython-311.pyc and b/carsrun/__pycache__/car.cpython-311.pyc differ
diff --git a/carsrun/appCam.py b/carsrun/appCam.py
index 0e85ee3..e43927e 100644
--- a/carsrun/appCam.py
+++ b/carsrun/appCam.py
@@ -70,7 +70,7 @@ def gen_frames(): # generate frame by frame from camera
@app.route('/control/sendit', methods=['POST'])
def send_command():
# 定义目标 IP 地址、端口和路由
- ip = "192.168.98.204"
+ ip = "192.168.60.204"
port = 3000
route = "sendit2"
diff --git a/carsrun/apptest.py b/carsrun/apptest.py
index 89b9d9e..72bda97 100644
--- a/carsrun/apptest.py
+++ b/carsrun/apptest.py
@@ -1,31 +1,46 @@
-from flask import Flask, render_template, Response
-from picamera2 import Picamera2
-import time
+from flask import Flask, request, jsonify
import cv2
+import threading
+import time
app = Flask(__name__)
-def gen_frames(): # generate frame by frame from camera
- picam2 = Picamera2()
- picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
- picam2.start()
- while True:
- # Capture frame-by-frame
- frame = picam2.capture_array() # read the camera frame
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
- ret, buffer = cv2.imencode('.jpg', frame)
- frame = buffer.tobytes()
- yield (b'--frame\r\n'
- b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
-
-@app.route('/')
-def index():
- return render_template('index.html')
-
-@app.route('/video_feed')
-def video_feed():
- #Video streaming route. Put this in the src attribute of an img tag
- return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
+# 设置存储照片的目录路径
+photo_path = '/Desktop/cars/photo/'
+
+# 初始化摄像头
+camera = cv2.VideoCapture(-1)
+camera.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
+camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
+
+# 初始化变量
+photo_num_count = 0
+capture_lock = threading.Lock()
+last_photo_time = time.time()
+
+# 拍照函数
+def capture_photo():
+ global photo_num_count
+ with capture_lock:
+ ret, frame = camera.read()
+ if ret:
+ photo_num_count += 1
+ photo_filename = f'{photo_path}photo_{photo_num_count}.jpg'
+ cv2.imwrite(photo_filename, frame)
+ print(f'{photo_num_count} photos saved. new photo: {photo_filename}')
+
+# 拍照请求处理
+@app.route('/photo', methods=['POST'])
+def photo():
+ capture_photo()
+ return jsonify({"status": "photo captured"})
+
+# 停止请求处理
+@app.route('/stop', methods=['POST'])
+def stop():
+ camera.release()
+ print("Camera stopped")
+ return jsonify({"status": "camera stopped"})
if __name__ == '__main__':
- app.run(host='0.0.0.0', port=5000, debug=True)
+ app.run(host='0.0.0.0', port=5000)
\ No newline at end of file
diff --git a/carsrun/captured_photo.jpg b/carsrun/captured_photo.jpg
new file mode 100644
index 0000000..a171472
Binary files /dev/null and b/carsrun/captured_photo.jpg differ
diff --git a/carsrun/index-t1.html b/carsrun/index-t1.html
new file mode 100644
index 0000000..901f62b
--- /dev/null
+++ b/carsrun/index-t1.html
@@ -0,0 +1,218 @@
+
+
+
+
+
+
+
+ Live Video Based on Flask
+
+
+
+
+ 实时视频流
+
+ 小车控制界面
+
+ 小车控制
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/carsrun/templates/appCam1.py b/carsrun/templates/appCam1.py
new file mode 100644
index 0000000..28e2255
--- /dev/null
+++ b/carsrun/templates/appCam1.py
@@ -0,0 +1,171 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# appCam.py
+# based on tutorial ==> https://blog.miguelgrinberg.com/post/video-streaming-with-flask
+# PiCam Local Web Server with Flask
+# MJRoBot.org 19Jan18
+
+from flask import Flask, render_template, Response, redirect, url_for, send_file, jsonify, request
+
+# Raspberry Pi camera module (requires picamera package)
+#from camera_pi import Camera
+from picamera2 import Picamera2
+import os
+import time
+from gevent import pywsgi
+from car import CAR
+#from PiCamera_H264_Server import stream
+import threading
+import cv2
+app = Flask(__name__, static_url_path='')
+# 照片保存路径
+PHOTO_PATH = "photo.jpg"
+
+def gen_frames(): # generate frame by frame from camera
+ picam2 = Picamera2()
+ picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
+ picam2.start()
+ while True:
+ # Capture frame-by-frame
+ frame = picam2.capture_array() # read the camera frame
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
+ ret, buffer = cv2.imencode('.jpg', frame)
+ frame = buffer.tobytes()
+ yield (b'--frame\r\n'
+ b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
+
+
+@app.route('/')
+def index():
+ return render_template('index-t.html')
+
+@app.route('/video_feed')
+def video_feed():
+ #Video streaming route. Put this in the src attribute of an img tag
+ return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
+#---------------------------------------------------------------------------------
+@app.route('/take_photo')
+def take_photo():
+ picam2 = Picamera2()
+ picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
+ picam2.start()
+ frame = picam2.capture_array() # Capture a single frame
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
+ cv2.imwrite(PHOTO_PATH, frame) # Save the frame as a JPEG file
+
+ return send_file(PHOTO_PATH, as_attachment=True) # Send the file to download
+#---------------------------------------------------------------------------------------
+
+# def gen(camera):
+# """Video streaming generator function."""
+# while True:
+# frame = camera.get_frame()
+# yield (b'--frame\r\n'
+# b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
+
+# @app.route('/capture')
+# def capture():
+# pic = open("qrcode.png", "wb")
+# frame = Camera().get_frame()
+# pic.write(frame)
+# return Response(b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n',
+# mimetype='multipart/x-mixed-replace; boundary=frame')
+# #return send_file("qrcode.png", mimetype='image/png')
+# #return redirect(url_for('index'))
+
+# @app.route('/video_feed')
+# def video_feed():
+# """Video streaming route. Put this in the src attribute of an img tag."""
+# return Response(gen(Camera()),
+# mimetype='multipart/x-mixed-replace; boundary=frame')
+car = CAR()
+@app.route('/control/')
+def control_index():
+ word = """指令:\n
+ /stop(/Q): 小车停止运动\n
+ /forward(/W): 小车开始运动\n
+ /back(/S): 小车向后运动\n
+ /left(/A): 小车向左运动\n
+ /right(/D): 小车向右运动\n"""
+ print(word)
+ return word
+
+# def execute_forward_function():
+# url = "http://192.168.185.242:80/send_command" # 示例URL,实际使用时需要替换为正确的服务器地址
+# data = {"command": 'base -c {"T":1,"L":0.5,"R":0.5}'} # 请求体数据
+
+# # 发送请求并打印返回结果
+# try:
+# response = request.post(url, data=data)
+# print(response.text) # 打印服务器返回的内容
+# except request.exceptions.RequestException as e:
+# print(f"请求发生错误: {e}")
+# print("执行前进功能")
+# # 返回一些结果
+# return "前进功能已执行"
+
+# @app.route('/control/forward', methods=['GET'])
+# def control_forward():
+# try:
+# # 获取前端发送的数据
+# data = request.args
+
+# # 调试输出接收到的数据
+# print("接收到的数据:", data)
+
+# # 执行你的函数
+# result = execute_forward_function() # 确保这个函数是可以被调用的,如果有必要打印它的返回值
+
+# # 返回JSON响应, result 需要确保是可json化的对象
+# return jsonify({
+# "resultCode": 200,
+# "message": "请求成功",
+# "data": result
+# })
+# except Exception as e:
+# print(f"发生错误: {e}") # 打印异常
+# return jsonify({"resultCode": 500, "message": "内部服务器错误"}), 500 # 返回500错误
+
+
+
+@app.route('/control/')
+def fun(info):
+ if hasattr(car, info):
+ getattr(car, info)()
+ return 'Run: '+info+'\n'
+ else:
+ return 'Error: '+info+' not be defined\n'
+
+# 新增路由处理文本传输功能
+@app.route('/send_text', methods=['POST'])
+def send_text():
+ try:
+ # 获取前端发送的数据
+ data = request.form
+ ip = data.get('ip')
+ port = int(data.get('port'))
+ text = data.get('text')
+
+ # 构建URL
+ url = "http://{}:{}/send_text".format(ip, port)
+
+ # 发送请求
+ response = requests.post(url, data={'text': text})
+
+ # 返回响应
+ return jsonify({
+ "resultCode": 200,
+ "message": "请求成功",
+ "data": response.text
+ })
+ except Exception as e:
+ print(f"error: {e}")
+ return jsonify({"resultCode": 500, "message": "内部服务器错误"}), 500
+
+if __name__ == '__main__':
+ app.run(host='0.0.0.0', port =80, debug=True, threaded=True)
+ # t = threading.Thread(target=stream)
+ # t.start()
+ # server = pywsgi.WSGIServer(('0.0.0.0', 80), app)
+ # server.serve_forever()
diff --git a/carsrun/templates/index-t1.html b/carsrun/templates/index-t1.html
new file mode 100644
index 0000000..901f62b
--- /dev/null
+++ b/carsrun/templates/index-t1.html
@@ -0,0 +1,218 @@
+
+
+
+
+
+
+
+ Live Video Based on Flask
+
+
+
+
+ 实时视频流
+
+ 小车控制界面
+
+ 小车控制
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/data.db b/data.db
index 3b0db78..148ff0d 100644
Binary files a/data.db and b/data.db differ
diff --git a/log.txt b/log.txt
index 5fb4871..c7ec2dd 100644
--- a/log.txt
+++ b/log.txt
@@ -1,6 +1,7 @@
-guard df123qwerty 2023-04-24-10-13-55
-guard df123qwerty 2023-04-24-10-14-31
-guard df123qwerty 2023-04-24-10-16-50
-guard df123qwerty 2023-04-24-10-17-04
-guard df123qwerty 2023-04-24-10-17-05
-guard df123qwerty 2023-04-24-10-17-07
+admin - 2024-10-31T08:18:22.560Z
+zyp - 2024-10-31T08:18:32.459Z
+admin - 2024-10-31T08:28:40.653Z
+zyp - 2024-10-31T08:28:46.935Z
+chenjk - 2024-10-31T09:41:40.969Z
+chenjk - 2024-10-31T09:41:52.294Z
+chenjk - 2024-10-31T09:42:24.196Z
diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json
index 89990a1..233607c 100644
--- a/node_modules/.package-lock.json
+++ b/node_modules/.package-lock.json
@@ -1,7 +1,7 @@
{
"name": "ui",
"version": "0.0.0",
- "lockfileVersion": 2,
+ "lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/@mapbox/node-pre-gyp": {
@@ -1553,6 +1553,15 @@
"mkdirp": "bin/cmd.js"
}
},
+ "node_modules/moment": {
+ "version": "2.30.1",
+ "resolved": "https://registry.npmmirror.com/moment/-/moment-2.30.1.tgz",
+ "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
diff --git a/package-lock.json b/package-lock.json
index d248c1a..435f534 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,6 +16,7 @@
"express": "~4.16.1",
"express-session": "^1.17.0",
"http-errors": "~1.6.3",
+ "moment": "^2.30.1",
"morgan": "~1.9.1",
"multer": "^1.4.4",
"nodemailer": "^6.7.3",
@@ -1574,6 +1575,15 @@
"mkdirp": "bin/cmd.js"
}
},
+ "node_modules/moment": {
+ "version": "2.30.1",
+ "resolved": "https://registry.npmmirror.com/moment/-/moment-2.30.1.tgz",
+ "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
+ "license": "MIT",
+ "engines": {
+ "node": "*"
+ }
+ },
"node_modules/morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
@@ -3897,6 +3907,11 @@
"minimist": "^1.2.5"
}
},
+ "moment": {
+ "version": "2.30.1",
+ "resolved": "https://registry.npmmirror.com/moment/-/moment-2.30.1.tgz",
+ "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how=="
+ },
"morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
diff --git a/package.json b/package.json
index 368d989..7abb205 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"express": "~4.16.1",
"express-session": "^1.17.0",
"http-errors": "~1.6.3",
+ "moment": "^2.30.1",
"morgan": "~1.9.1",
"multer": "^1.4.4",
"nodemailer": "^6.7.3",
diff --git a/rizhi.txt b/rizhi.txt
index 0e47acb..704a76c 100644
--- a/rizhi.txt
+++ b/rizhi.txt
@@ -1,5 +1,3 @@
-qinziyao 2023-04-24-10-13-53
-admin 2023-04-24-10-19-08
zyp 2024-10-15-17-08-52
zyp 2024-10-15-17-21-31
zyp 2024-10-15-17-25-47
diff --git a/routes/index.js b/routes/index.js
index 4506ab2..44ca3ee 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -13,6 +13,9 @@ var jsonParser = bodyParser.json();
var urlencodedParser = bodyParser.urlencoded({
extended: false
})
+
+
+const moment = require('moment'); // 使用 moment.js 来方便地处理时间格式
//桌面latest版
function execute(cmd){
execSync(cmd,{cwd:'C:\\Users\\17217\\Desktop\\english\\python'},function(error, stdout, stderr){
@@ -158,6 +161,28 @@ router.get('/download', function (req, res, next) {
});
router.post('/login', urlencodedParser, function (req, res, next) {
var name = req.body.name;
+ // 获取当前时间并格式化
+ const now = new Date();
+ const loginTime = now.toISOString(); // 使用 ISO 格式的时间字符串
+
+ // 在 name 获取后,添加文件操作代码
+ //const fs = require('fs');
+ const path = 'C:/Users/17217/Desktop/teamwk123/log.txt'; // 文件路径
+
+ // 将 name 和 loginTime 写入文件,追加模式
+ fs.appendFile(path, `${name} - ${loginTime}\n`, function (err) {
+ if (err) {
+ console.error('写入文件时发生错误:', err);
+ // 你可以选择返回错误响应或者继续执行
+ return;
+ }
+ console.log('用户名和登录时间已写入文件:', name, loginTime);
+ });
+
+
+
+
+
var pwd = req.body.pwd;
var sqlite3 = require('sqlite3').verbose()
var sql = "SELECT * FROM users where username='" + name + "' and password='" + pwd+"'"
@@ -168,7 +193,11 @@ router.post('/login', urlencodedParser, function (req, res, next) {
req.session.error = "用户名或密码错误,请重新输入!";
res.redirect('login');
} else {
- username = name
+ username = name; // 使用 const 来定义变量
+
+
+
+
// var exec = require('child_process').exec;
// exec(`python C:/Users/17217/Desktop/english/users/admin/log.py `+username)
// db.run("delete from "+name,function(){ //每次先将表信息清空再重新读取文件夹里面的文件信息
@@ -315,7 +344,7 @@ router.post('/upload', multer({dest:'./users/'}).any(),function(req, res){
})
// execute("python D:/99/ui_ref/users/admin/a.py")
var exec = require('child_process').exec;
- exec(`python C:/Users/17217/Desktop/english/users/admin/decode.py`)
+ exec(`python C:/Users/17217/Desktop/teamwk123/users/admin/decode.py`)
res.send('上传成功,点击←返回上一页');
}
})
@@ -329,7 +358,7 @@ router.post('/execution',function(req, res){
router.post("/getit", function (data, res) {
- fs.readFile("C:\\Users\\17217\\Desktop\\english\\result.txt", 'utf-8', (err, data) => {
+ fs.readFile("C:\\Users\\17217\\Desktop\\teamwk123\\result.txt", 'utf-8', (err, data) => {
if (err) {
console.error(err);
return;
@@ -341,7 +370,7 @@ router.post("/getit", function (data, res) {
})
router.post("/histroy", function (data, res) {
- fs.readFile("C:\\Users\\17217\\Desktop\\english\\log.txt", 'utf-8', (err, data) => {
+ fs.readFile("C:\\Users\\17217\\Desktop\\teamwk123\\log.txt", 'utf-8', (err, data) => {
if (err) {
console.error(err);
return;
@@ -353,7 +382,7 @@ router.post("/histroy", function (data, res) {
})
router.post("/log", function (data, res) {
- fs.readFile("C:\\Users\\17217\\Desktop\\english\\rizhi.txt", 'utf-8', (err, data) => {
+ fs.readFile("C:\\Users\\17217\\Desktop\\teamwk123\\rizhi.txt", 'utf-8', (err, data) => {
if (err) {
console.error(err);
return;
diff --git a/users/admin/decode.py b/users/admin/decode.py
index e4b5144..9f8be2f 100644
--- a/users/admin/decode.py
+++ b/users/admin/decode.py
@@ -10,17 +10,17 @@ def get_public_key_from_file(filepath):
key_file.read(),
)
return public_key
-public_key = get_public_key_from_file('D:/99/ui_ref/users/admin/public.pem')
+public_key = get_public_key_from_file('C:/Users/17217/Desktop/english/users/admin/public.pem')
# 将明文进行RSA加密
from time import strftime
import requests
-a = requests.post("http://127.0.0.1:5000/qr", files={"qr_pic": open("D:/99/ui_ref/users/admin/qrcode.png", "rb")})
+a = requests.post("http://127.0.0.1:5000/qr", files={"qr_pic": open("C:/Users/17217/Desktop/english/users/admin/qrcode.png", "rb")})
print(a.text)
b = r = requests.post("http://127.0.0.1:5000/match", data={"pattern": "df123qwerty"})
print(b.text)
-file = open('D:/99/ui_ref/users/admin/result.txt','w')
+file = open('C:/Users/17217/Desktop/english/result.txt','w')
plaintext0 = a.text
plaintext = plaintext0.encode('utf-8')
ciphertext = public_key.encrypt(
diff --git a/users/admin/log.txt b/users/admin/log.txt
index 9960ac7..8b13789 100644
--- a/users/admin/log.txt
+++ b/users/admin/log.txt
@@ -1,16 +1 @@
-guard df123qwerty 2023-04-18-09-45-13
-guard df123qwerty 2023-04-18-09-46-50
-guard df123qwerty 2023-04-18-09-46-52
-guard df123qwerty 2023-04-18-10-16-00
-guard df123qwerty 2023-04-18-10-20-29
-guard Null 2023-04-18-10-28-11
-guard df123qwerty 2023-04-18-15-01-55
-guard df123qwerty 2023-04-18-18-21-13
-guard df123qwerty 2023-04-18-21-56-05
-guard df123qwerty 2023-04-18-22-00-38
-guard df123qwerty 2023-04-19-08-47-19
-guard df123qwerty 2023-04-19-09-03-15
-guard df123qwerty 2023-04-19-09-48-46
-guard df123qwerty 2023-04-19-10-07-22
-guard df123qwerty 2023-04-19-10-54-03
-guard df123qwerty 2023-04-19-10-54-22
+
diff --git a/users/admin/rizhi.txt b/users/admin/rizhi.txt
index d869c72..8b13789 100644
--- a/users/admin/rizhi.txt
+++ b/users/admin/rizhi.txt
@@ -1,37 +1 @@
-qinziyao 2023-04-18-21-36-05
-admin 2023-04-18-21-36-27
-xuchen 2023-04-18-21-42-33
-admin 2023-04-18-21-42-47
-admin 2023-04-18-21-58-14
-guard 2023-04-18-21-58-38
-qinziyao 2023-04-18-22-31-50
-qinziyao 2023-04-18-22-54-14
-fighter1 2023-04-19-08-25-10
-fighter1 2023-04-19-08-38-37
-admin 2023-04-19-08-42-53
-guard 2023-04-19-08-46-52
-admin 2023-04-19-08-48-23
-fighter2 2023-04-19-09-02-35
-admin 2023-04-19-09-02-57
-fighter2 2023-04-19-09-04-44
-admin 2023-04-19-09-05-31
-fighter2 2023-04-19-09-05-47
-fighter1 2023-04-19-09-05-52
-qinziyao 2023-04-19-09-42-50
-guard 2023-04-19-10-04-46
-qinziyao 2023-04-19-10-06-53
-admin 2023-04-19-10-08-09
-fighter1 2023-04-19-10-11-27
-flying_pigeon 2023-04-19-10-18-42
-guard 2023-04-19-10-53-14
-qinziyao 2023-04-21-23-36-47
-admin 2023-04-21-23-57-01
-tester 2023-04-23-08-21-17
-tester 2023-04-23-08-26-06
-qinziyao 2023-04-23-11-28-31
-admin 2023-04-23-15-33-25
-admin 2023-04-23-17-12-05
-qinziyao 2023-04-23-20-24-04
-admin 2023-04-23-20-25-27
-halo 2023-04-23-20-42-59
-admin 2023-04-23-20-48-24
+