webserver.py
1.29 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
54
55
56
57
58
59
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
global timeData
timeData = []
data=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,timeData,))
th.setDaemon(True)
@app.route('/')
def upload_main():
print(timeData)
return render_template('index.html')
@app.route('/record', methods=['GET','POST'])
def submit():
global th
global data
global timeData
print(threading.enumerate())
if not th.is_alive():
print('dead')
data=[]
timeData=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,timeData,))
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)))
print("timeData is " + str(timeData[0]))
r = upload(data)
return (r.content, r.status_code, r.headers.items())
def upload(datas):
params={'datas':datas, 'timeData':timeData[0]}
url='http://192.168.0.36:80/upload'
return requests.post(url,data =json.dumps(params))
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)