This article illustrates how to control remotely via web a GPIO line using the Tornado web server for Python
To follow this article you have to install Tornado on your CORE9G25 Board.
The first attempt is to control a led wired on an CORE9G25 board.
The files used are:
Led controller
Led control panelONOFF
Last status message:
led.py(The web server): Position: CD://Debian/python/tornado/led/led.py
import tornado.ioloop
import tornado.web
import ablib
class ledon(tornado.web.RequestHandler):
def get(self):
led.on()
print "Led ON"
self.write("Led ON")
class ledoff(tornado.web.RequestHandler):
def get(self):
led.off()
print "Led OFF"
self.write("Led OFF")
application = tornado.web.Application([
(r"/ledon", ledon),
(r"/ledoff", ledoff),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": ".","default_filename": "index.html"}),
])
if __name__ == "__main__":
led = ablib.Daisy11('D11','L1')
application.listen(8080,"0.0.0.0")
tornado.ioloop.IOLoop.instance().start()
index.html: A simple html page with two buttons. Position: CD://Debian/python/tornado/led/index.html
Go the CD://Debian/python/tornado/led/index.html to see the file details
The web site icon: favico.ico
type the follow command:
debarm:~/playground/python/tornado/led# python led.py
It is possible to use a different GPIO line just changing the line
led = ablib.Daisy11('D11','L1')
Open your browser and try to send the on-off command directly using these urls:
Now open the default web page:
and turn on-off the led using the two HTML buttons like these:
Led control panel
ON OFF
Last status message:
Related links
Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website: http://www.acmesystems.it