vladi4ko

dht22_fan.py

Feb 1st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import datetime
  5. import calendar
  6. import time
  7. import os
  8. import subprocess
  9.  
  10.  
  11. def checkhumidity():
  12.     p = subprocess.Popen(["/project/dht22/monitor/humidity.sh"], stdout=subprocess.PIPE)
  13.     getstatus = p.communicate()[0].strip()
  14.     return float(getstatus) + 0
  15.  
  16. def checktemperature():
  17.     p = subprocess.Popen(["/project/dht22/monitor/temperature.sh"], stdout=subprocess.PIPE)
  18.     getstatus = p.communicate()[0].strip()
  19.     return float(getstatus) + 0
  20.  
  21. def onoffstatus():
  22.     p = subprocess.Popen(["/project/dht22/monitor/status.sh"], stdout=subprocess.PIPE)
  23.     onoffstatus = p.communicate()[0].strip()
  24.     return int(float(onoffstatus)) + 0
  25.  
  26.  
  27. levelhumidity = 30
  28.  
  29. def min():
  30.     temp = 0
  31.     #temp = checktemperature()
  32.     humidity = checkhumidity()
  33.     hnow = datetime.datetime.now().strftime('%H:%M:%S')
  34.     if (levelhumidity > humidity):
  35.         if (onoffstatus() == 1):
  36.             os.system("/project/dht22/monitor/off.sh")
  37.         time.sleep(5)
  38.         #print(u"мин. Час:%s темп:%s - влажност:%s - вентилатор:%s ".encode('utf-8') %(hnow,temp,humidity,onoffstatus()))
  39.         min()
  40.     else:
  41.         pass
  42.  
  43. def max():
  44.     temp = 0
  45.     #temp = checktemperature()
  46.     levelhumidity = 27
  47.     humidity = checkhumidity()
  48.     hnow = datetime.datetime.now().strftime('%H:%M:%S')
  49.     if (levelhumidity < humidity):
  50.         if (onoffstatus() < 1):
  51.             os.system("/project/dht22/monitor/on.sh")
  52.         time.sleep(60)
  53.         #print(u"макс. Час:%s темп:%s - влажност:%s - вентилатор:%s ".encode('utf-8') %(hnow,temp,humidity,onoffstatus()))
  54.         max()
  55.     else:
  56.         pass
  57.  
  58.  
  59. #print u"Старт".encode('utf-8')
  60. try:
  61.     while True:            # this will carry on until you hit CTRL+C
  62.         temp = 0
  63.         #temp = checktemperature()
  64.         humidity = checkhumidity()
  65.         hnow = datetime.datetime.now().strftime('%H:%M:%S')
  66.         if (humidity > levelhumidity):
  67.             #print(u"старт макс. Час:%s темп:%s - влажност:%s - вентилатор:%s ".encode('utf-8') %(hnow,temp,humidity,onoffstatus()))
  68.             max()
  69.             time.sleep(1)
  70.         if (humidity < levelhumidity):
  71.             #print(u"старт мин. Час:%s темп:%s - влажност:%s - вентилатор:%s ".encode('utf-8') %(hnow,temp,humidity,onoffstatus()))
  72.             min()
  73.             time.sleep(1)
  74.  
  75. except KeyboardInterrupt:
  76.     pass
  77. finally:                   # this block will run no matter how the try block exits..
  78.     pass
Add Comment
Please, Sign In to add comment