Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import web, os, subprocess, time
- import Adafruit_DHT as dht
- web.config.debug = False
- urls = ('/.*', 'hooks')
- app = web.application(urls, globals(),autoreload=True)
- # Return CPU temperature as a character string
- def getCPUtemperature():
- s = subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])
- #print s.split('=')[1]
- return s.split('=')[1][:-3]
- def read_DHT():
- h,t = dht.read_retry(dht.DHT22, 4)
- #print h, t
- t = format(t, '.2f')
- h = format(h, '.2f')
- return(t,h)
- class hooks:
- def GET(self):
- t,h = read_DHT()
- return "Temp "+str(t)+" Hum "+str(h)+ " cputemp " + str(getCPUtemperature())
- if __name__ == '__main__':
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement