-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (47 loc) · 1.46 KB
/
app.py
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
60
61
62
63
64
#!/usr/bin/env python
from importlib import import_module
import os
from flask import Flask, render_template, Response, request
from flask_cors import CORS
from camera_pi import Camera
from dht import readDHTSensor
from gas import readGasSensor
from wheels_dcmotor import moveDCMotor
from wheels_servo import turnDirectionServo
import atexit
import RPi.GPIO
atexit.register(RPi.GPIO.cleanup)
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return Response('Health Check', mimetype='text/xml')
@app.route('/move', methods=['POST'])
def move():
req_data = request.get_json()
speed = req_data['speed']
moveDCMotor(speed)
return Response('sucess', mimetype='text/xml')
@app.route('/turn', methods=['POST'])
def turn():
req_data = request.get_json()
degrees = req_data['degrees']
turnDirectionServo(degrees)
return Response('sucess', mimetype='text/xml')
def videogen(camera):
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('/video_feed')
def video_feed():
return Response(videogen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/dht')
def dht():
return Response(readDHTSensor(), mimetype='text/xml')
@app.route('/gas')
def gas():
return Response(readGasSensor(), mimetype='text/xml')
if __name__ == '__main__':
app.run(host='0.0.0.0', threaded=True)