Skip to content

Instantly share code, notes, and snippets.

@victorchee
Created January 28, 2015 13:16
Show Gist options
  • Save victorchee/6cf4b100f7225e6d3ca3 to your computer and use it in GitHub Desktop.
Save victorchee/6cf4b100f7225e6d3ca3 to your computer and use it in GitHub Desktop.
树莓派中使用Flask实现查看CPU和GPU温度,捕获摄像头图像并展示。
from flask import Flask, jsonify, request, render_template, url_for, send_from_directory, redirect
2 import temperature
3 import camera
4 app = Flask(__name__)
5 app.config['UPLOAD_FOLDER'] = 'static'
6
7 @app.route("/")
8 def index(): pass
9
10 @app.route("/temperature")
11 def temp():
12 cpu_temperature = temperature.get_cpu_temperature()
13 gpu_temperature = temperature.get_gpu_temperature()
14 return jsonify(cpu=cpu_temperature, gpu=gpu_temperature)
15
16 @app.route("/camera")
17 def cam():
18 image_name = camera.capture()
19 return jsonify(image = request.url_root+'static/'+image_name)
20
21 @app.route("/images/<imagename>")
22 def image(imagename):
23 return send_from_directory('static', imagename)
24
25 @app.route("/monitor")
26 def monitor():
27 image_name = camera.capture()
28 # return redirect(url_for('image', imagename = image_name))
29 return send_from_directory('static', image_name)
30
31 @app.route("/upload", methods=['POST'])
32 def upload():
33 if request.method == 'POST':
34 file = request.files['file']
35 filename = secure_filename(file.filename)
36 file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
37 return 'upload succeed'
38 return 'Not POST'
39
40 if __name__=="__main__":
41 app.run(host='0.0.0.0', port=8000, debug=True)
42 # app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment