Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import cherrypy
  2. import os
  3. import json
  4. import time
  5.  
  6. import RPi.GPIO as GPIO
  7.  
  8. class TestClass:
  9.     @cherrypy.expose
  10.     def __init__(self):
  11.         GPIO.setwarnings(False)
  12.         GPIO.setmode(GPIO.BOARD)
  13.  
  14.         GPIO.setup(31, GPIO.OUT)
  15.         GPIO.setup(33, GPIO.OUT)
  16.         GPIO.setup(35, GPIO.OUT)
  17.         GPIO.setup(37, GPIO.OUT)
  18.  
  19.         GPIO.output(31, True)
  20.         GPIO.output(33, True)
  21.         GPIO.output(35, True)
  22.         GPIO.output(37, True)
  23.  
  24.     @cherrypy.expose
  25.     def index(self):
  26.         return open('index.html')
  27.    
  28.     @cherrypy.expose
  29.     @cherrypy.tools.json_out()
  30.     def gpio31(self):
  31.         GPIO.output(31, False)
  32.         time.sleep(5)
  33.         GPIO.output(31, True)
  34.    
  35.     @cherrypy.expose
  36.     @cherrypy.tools.json_out()
  37.     def gpio33(self):
  38.         GPIO.output(33, False)
  39.         time.sleep(5)
  40.         GPIO.output(33, True)
  41.    
  42.     @cherrypy.expose
  43.     @cherrypy.tools.json_out()
  44.     def gpio35(self):
  45.         GPIO.output(35, False)
  46.         time.sleep(5)
  47.         GPIO.output(35, True)
  48.    
  49.     @cherrypy.expose
  50.     @cherrypy.tools.json_out()
  51.     def gpio37(self):
  52.         GPIO.output(37, False)
  53.         time.sleep(5)
  54.         GPIO.output(37, True)
  55.  
  56. configfile = os.path.join(os.path.dirname(__file__),'server.conf')
  57. cherrypy.quickstart(TestClass(), config=configfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement