-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
74 lines (63 loc) · 1.33 KB
/
hello.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
65
66
67
68
69
70
71
72
73
74
import os, subprocess, time
from flask import Flask, send_file
#import serial
import sys
import time
device = '/dev/ttyACM0'
baud = 115200
timeout = 3
def sendc(cmd):
print "really in"
global conn
print cmd
print cmd[0]
conn.write(str(cmd) + "\n")
#l = conn.readlines()
#print l
#out2 = conn.readlines()
print "done with sendc"
return out2
def takepic(picid):
picid += ".jpg"
subprocess.call(["raspistill", "-o", picid])
time.sleep(6)
return picid
app = Flask(__name__)
@app.route('/ten/')
def ten():
print 'here'
time.sleep(10)
return 'Yo'
@app.route('/one/')
def one():
time.sleep(1)
return 'one'
@app.route('/')
def hello():
return 'Hello World!'
@app.route('/takepic/')
def reqtakepic():
subprocess.call("ls")
picid = 'takeit'
fn = takepic(picid)
subprocess.call("ls")
return send_file(fn, mimetype='image/jpeg')
@app.route('/smoothie/<data>')
def smoothie(data):
print "in"
conn = serial.Serial(device,baud,timeout=timeout)
print "sending"
#c2 = sendc(str(data))
conn.write(str(data) + "\n")
time.sleep(2)
c = conn.write("get pos\n")
out1 = conn.readlines()
print "before conn close"
conn.close()
print "down to ret"
#ret = [out1.join(" | ") ,out2.join(" | ")].join("\n")
print out1
ret = " | ".join(out1)
return ret
if __name__== "__main__":
app.run(host='0.0.0.0', threaded=True)