webserver.py
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, send_file,request,url_for,redirect, render_template
import os
import json
import acc_test_2
import threading
import multiprocessing
import requests
import pygame
import time
app = Flask(__name__)
global data
global th
data=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,))
th.setDaemon(True)
@app.route('/')
def upload_main():
return render_template('index.html')
@app.route('/record', methods=['GET','POST'])
def submit():
global th
global data
print(threading.enumerate())
if not th.is_alive():
print('dead')
data=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,))
th.start()
return render_template('record.html')
@app.route('/stop', methods=['GET','POST'])
def stop():
th.do_run = False
th.join()
print("data length is " + str(len(data)))
r = upload(data)
return (r.content, r.status_code, r.headers.items())
def upload(datas):
params={'datas':datas}
url='http://192.168.0.25:80/upload'
return requests.post(url,data =json.dumps(params))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)