mardi 20 septembre 2016

Code debugging, Raspberry pi relays and if statements

I've a problem with Raspberry pi realays, earlyer I'd wrote about LED and the problem was kinda similar, but this time these metods won't work.

#!/usr/bin/env python
import sys
import time
import datetime
import RPi.GPIO as GPIO
import SDL_DS1307

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

Rele1 = 17
Rele2 = 27



GPIO.setup(17, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)

filename = time.strftime("%Y-%m-%d%H:%M:%SRTCTest") + ".txt"
starttime = datetime.datetime.utcnow()

ds1307 = SDL_DS1307.SDL_DS1307(1, 0x68)
ds1307.write_now()
while True:
        currenttime = datetime.datetime.utcnow()
        deltatime = currenttime - starttime
        data=time.strftime("%Y"+"%m"+"%d"+"%H"+"%M")
        with open('data.txt') as f:
                for line in f:
                        parts=line.split()
                        if parts[0]<=(data)<=parts[1]:
                                GPIO.output(Rele1, True)
                                GPIO.output(Rele2, False)
                        else:
                                GPIO.output(Rele1, False)
                                GPIO.output(Rele2, True)

There's a problem, when if statement false, relays works as they shoud be, but when true starts problems, relay can't open nomaly. I've tried "break" after if and else, but it not helping, where can be the problem whitch makes that mess? :)

Aucun commentaire:

Enregistrer un commentaire