Advertisement
Masoko

dht_web.py

Sep 5th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/python
  2. import web, os, subprocess, time
  3. import Adafruit_DHT as dht
  4.  
  5. web.config.debug = False
  6. urls = ('/.*', 'hooks')
  7. app = web.application(urls, globals(),autoreload=True)
  8.  
  9.  
  10. # Return CPU temperature as a character string
  11. def getCPUtemperature():
  12.         s = subprocess.check_output(["/opt/vc/bin/vcgencmd","measure_temp"])
  13.         #print s.split('=')[1]
  14.         return s.split('=')[1][:-3]
  15.  
  16. def read_DHT():
  17.         h,t = dht.read_retry(dht.DHT22, 4)
  18.         #print h, t
  19.         t = format(t, '.2f')
  20.         h = format(h, '.2f')
  21.         return(t,h)
  22.  
  23. class hooks:
  24.     def GET(self):
  25.                 t,h = read_DHT()
  26.                 return "Temp "+str(t)+" Hum "+str(h)+ " cputemp " + str(getCPUtemperature())
  27.  
  28. if __name__ == '__main__':
  29.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement