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:
