hello!
i'm looking data logger wich add record in database on pir action found 1 soluion on internet wich perfect me
http://smart-home.te.ua/raspberry-pi-mo ... -movement/
unffortinatly error
thx
i'm looking data logger wich add record in database on pir action found 1 soluion on internet wich perfect me
http://smart-home.te.ua/raspberry-pi-mo ... -movement/
unffortinatly error
maybe can me finde problem?file "pir.py", line 40
elif current_state==0 , previous_state==1:
^
indentationerror: unexpected indent
code: select all
#!/usr/bin/python # import required python libraries import rpi.gpio gpio import time import mysqldb import datetime # use bcm gpio references instead of physical pin numbers gpio.setmode(gpio.bcm) # define gpio use on pi gpio_pir = 7 gpio_led = 8 # set pin input gpio.setup(gpio_pir,gpio.in) # echo current_state = 0 previous_state = 0 gpio.setup(gpio_led,gpio.out) gpio.output(8, false) try: # loop until pir output 0 while gpio.input(gpio_pir)==1: current_state = 0 # loop until users quits ctrl-c while true : # read pir state current_state = gpio.input(gpio_pir) if current_state==1 , previous_state==0: # pir triggered print " motion detected!" status = " motion detected!" gpio.output(8, true) time.sleep(5) gpio.output(8, false) con = mysqldb.connect(host="localhost", user="root", passwd="password", db="action") cur = con.cursor() cur.execute("insert motion(motion,datetime) values (%s, %s)",(status, datetime.datetime.now())) con.commit() # record previous state previous_state=1 elif current_state==0 , previous_state==1: # reed has returned ready state print " ready" previous_state=0 # wait 10 milliseconds time.sleep(0.01) except keyboardinterrupt: print " quit" # reset gpio settings gpio.cleanup()
looks elif line over-indented 1 space delete 1 space beginning of line.
raspberrypi
Comments
Post a Comment