Zeit und string Raspberry Pi
Verfasst: Donnerstag 20. Juli 2017, 19:08
Also mein Problem liegt in der 30. Zeile... ich möchte das, wenn der "timestamp" zwischen 10 und 21 liegt Licht gechekt wird usw. aber so wie ich mir das gedacht habe geht es wohl nicht und der Pi springt direkt zum else
. Wenn ich den Wert so wie in Zeile 1 in der Zweiten Codebox direkt reinschreibe, funktioniert alles wie ich will.
Wie bekomme ich nun eine brauchbare Stunde an die Stelle? Also das print unter dem timestamp = time.strftime("%H") , sagt bei mir z.B. 19, warum wird der wert in der Zeile 30 nicht benutzt?

Wie bekomme ich nun eine brauchbare Stunde an die Stelle? Also das print unter dem timestamp = time.strftime("%H") , sagt bei mir z.B. 19, warum wird der wert in der Zeile 30 nicht benutzt?
Code: Alles auswählen
SETTINGS = {
"LIGHT_GPIO": 17, # GPIO Number (BCM) for the Relay
"LIGHT_FROM": 10, # from which time the light can be turned on (hour)
"LIGHT_UNTIL": 21, # until which time (hour)
"LIGHT_CHANNEL": 0, # of MCP3008
"LIGHT_THRESHOLD": 500, # if the analog Threshold is below any of those, the light will turn on
"DHT_GPIO": 27, # GPIO Number (BCM) of the DHT Sensor
"DHT_SENSOR": Adafruit_DHT.DHT11, # DHT11 or DHT22
"TEMP_THRESHOLD": 23.0, # in Celcius. Above this value, the window will be opened by the servo
"MOTOR_GPIO+": 14, # GPIO Number (BCM), which opens the window
"MOTOR_GPIO-": 15, # GPIO Number (BCM), which closes the window
"ENDSTOP": 23, # GPIO Number of Endstop input
"PLANTS": [
{
"NAME": "Plant1",
"MOISTURE_CHANNELS": [6], # of MCP3008
"MOISTURE_THRESHOLD": 450, # if the average analog value of all sensors is above of this threshold, the Pump will turn on
"WATER_PUMP_GPIO": 18, # GPIO Number (BCM) for the Relais
"WATERING_TIME": 10, # Seconds, how long the pump should be turned on
},
]
}
def checkLight():
timestamp = time.strftime("%H")
print timestamp
if SETTINGS["LIGHT_FROM"] <= timestamp <= SETTINGS["LIGHT_UNTIL"]:
# check light sensors
print "check"
adc = MCP3008()
# read 10 times to avoid measuring errors
value = 0
for i in range(10):
value += adc.read( channel = SETTINGS["LIGHT_CHANNEL"] )
value /= 10.0
print value
if value <= SETTINGS["LIGHT_THRESHOLD"]:
# turn light on
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.LOW) # Relay LOW = ON
else:
# turn light off
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.HIGH)
else:
print "off"
# turn light off
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.HIGH)
usw...
Code: Alles auswählen
if SETTINGS["LIGHT_FROM"] <= 15 <= SETTINGS["LIGHT_UNTIL"]:
# check light sensors
print "check"
adc = MCP3008()
# read 10 times to avoid measuring errors
value = 0
for i in range(10):
value += adc.read( channel = SETTINGS["LIGHT_CHANNEL"] )
value /= 10.0
print value
if value <= SETTINGS["LIGHT_THRESHOLD"]:
# turn light on
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.LOW) # Relay LOW = ON
else:
# turn light off
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.HIGH)
else:
print "off"
# turn light off
GPIO.setup(SETTINGS["LIGHT_GPIO"], GPIO.OUT, initial=GPIO.HIGH)