

Fehler/Output
root@raspberrypi:~# python /home/programme/clima_sensor.py
<type 'datetime.time'>
Traceback (most recent call last):
File "/home/programme/clima_sensor.py", line 87, in <module>
loop()
File "/home/programme/clima_sensor.py", line 77, in loop
check(temperature, humidity)
File "/home/programme/clima_sensor.py", line 64, in check
time.sleep(sleeptime)
AttributeError: 'str' object has no attribute 'sleep'
root@raspberrypi:~#
Code: Alles auswählen
#!/usr/bin/python
# coding=utf-8
import I2C_LCD_driver
import Adafruit_DHT
import sys
import RPi.GPIO as GPIO
import subprocess
import os
from time import *
from datetime import *
sensor = Adafruit_DHT.DHT11
pin = 4
sleeptime = 1
print time
led_rot = 21
led_gelb = 20
led_gruen = 12
led_blau = 16
path = "bash /home/programme/pin.sh"
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
mylcd = I2C_LCD_driver.lcd()
now = datetime.now()
date = now.strftime("%m/%d/%Y")
time = now.strftime("%H:%M:%S")
def check(temp, humidity):
if 20 < temp < 25:
os.system('%s %i 0' % (path, led_blau))
os.system('%s %i 0' % (path, led_rot))
os.system('%s %i 1' % (path, led_gruen))
elif 20 > temp:
os.system('%s %i 0' % (path, led_gruen))
os.system('%s %i 0' % (path, led_rot))
while True:
if 20 > temp:
time.sleep(sleeptime)
os.system('%s %i 1' % (path, led_blau))
time.sleep(sleeptime)
os.system('%s %i 0' % (path, led_blau))
else:
break
elif 25 < temp:
os.system('%s %i 0' % (path, led_gruen))
os.system('%s %i 0' % (path, led_blau))
while True:
if 25 < temp:
time.sleep(sleeptime)
os.system('%s %i 1' % (path, led_rot))
time.sleep(sleeptime)
os.system('%s %i 0' % (path, led_rot))
else:
break
else:
for x in range(0, 100):
x = x + 1
os.system('%s %i 1' % (path, led_rot))
os.system('%s %i 1' % (path, led_blau))
os.system('%s %i 1' % (path, led_gruen))
time.sleep(sleeptime)
os.system('%s %i 0' % (path, led_rot))
os.system('%s %i 0' % (path, led_blau))
os.system('%s %i 0' % (path, led_gruen))
time.sleep(sleeptime)
def loop():
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
temp = "Waerme: %i%s C" % (int(temperature), chr(223))
humidity2show = "Naesse: %i " % (int(humidity))
#os.system('%s %i 0' % (path, led_gruen))
check(temperature, humidity)
# mylcd.lcd_display_string("als",1,1)
mylcd.lcd_display_string(temp, 1)
mylcd.lcd_display_string(humidity2show, 2)
def destroy():
GPIO.output(ledPin, GPIO.LOW) # led off
GPIO.cleanup() # Release resource
while True:
try:
loop()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
sys.exit("Programm exit")