After seeing other universities are using online platform to perform basic physical experiments, such as measuring gravity, Prof Le want to build a remote experimet platform himself.
We are asked to figure out how to remote control first.
Raspberry is in fashion then, combined with python, which is a powerful tool in web coding, I tested and succeeded.
Python code:
import web import os import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) render = web.template.render('static/') TAKE_PHOTO = "raspistill -o static/out.jpeg -w 500 -h 500 -n -t 1 -rot 180" urls = ( '/takephoto', 'TakePhoto', '/', 'index', '/light','Light', '/dark','Dark' ) class index: def GET(self): return render.index() def doMove(s): IO = '4310' for i in xrange(4): call(['gpio', 'write', IO[i], s[i]]) class TakePhoto: def GET(self): os.system(TAKE_PHOTO) class Light: def GET(self): GPIO.output(18, True) class Dark: def GET(self): GPIO.output(18,False) if __name__ == '__main__': app = web.application(urls, globals()) app.run()
Main part of html code, used as interface to remote users:
<body> <img width="500" height="500" src="/static/out.jpeg" id="myimg"> <br /> <button onclick="$.post('/pythonweb/move?direction=stop')">stop</button> <br /> <br /> <input type="text" id="content"> <button onclick="$.post('/pythonweb/speak', {content: $('#content')[0].value})">Speak</button> <script> setInterval(function(){ $('#myimg').attr('src', '/static/out.jpeg?' + new Date().getTime()); $.get('/takephoto'); }, 2000); </script> </body>