webserver.py 1.12 KB
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)