Hallo zusammen
Ich möchte gerne zwecks Statistik Personen zählen die das Lasermodul unterbrechen.
Hardware mässig passt alles, und auch eine normale ausgabe in Putty bei unterbruch klappt.
jedoch möchte ich das gerne paar mal am tag in ein google form uploaden. ich habe auch schon diverse code schnippsel im netz gefunden
Code
###################################################
###################################################
######### People Counter v1-1 ############
###################################################
################################
###Setting up Python Modules####
################################
import RPi.GPIO as GPIO
import os, time
################################
##### Setting up GPIO pins #####
################################
RECEIVER_PIN = 23
################################
######Setting up Counters ######
################################
peoplecount = 0
uploadcount = 0
door = 1 # <- Use this to designate multiple doors for tracking
location = 'Entry' # <- Use this to designate multiple locations for tracking in one form
rpitemp = '/opt/vc/bin/vcgencmd measure_temp | tr -d "temp=" | tr -d "C"' # Temperatur vom RPi
def callback_func(channel):
if GPIO.input(channel):
print("Lichtschranke wurde unterbrochen")
## This waits for a specified minute of the hour, checks if anyone has been detected since the last upload, then uploads the data to a Google Form.
# if time.strftime("%M") in ("13", "28", "43", "58") and peoplecount > 0 and uploadcount == 0:
if peoplecount > 0 and uploadcount == 0:
try:
url = "https://docs.google.com/forms/d/e/1FAIpQLSduNOOwMUtpQc5QNFbcwPXQhD0MRppum3kkYHThkFvo0JluQw/formResponse?ifq&entry.664100658=%s&entry.1901373746=%s&entry.1382055524=%s&entry.718436324=%s&submit=Submit&fbzx=4499308717411757586" % (location, door, peoplecount, rpitemp)
response = br.open(url)
print "People count uploaded with value %s on door %s at %s and RPi Temp %s" % (peoplecount, door, location, rpitemp)
uploadcount = 1
peoplecount = 0
print "values reset"
sys.exit
except:
print "Cannot Access Page"
elif time.strftime("%M") in ("14", "29", "44", "59") and uploadcount == 1:
uploadcount = 0
elif GPIO.input(h1) == True:
peoplecount = peoplecount + 1
print "Motion Detected: Door %s at %s on %s. Count is %s" % (door, time.strftime("%H:%M:%S"), time.strftime("%A"), peoplecount)
sys.exit
time.sleep(3)
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RECEIVER_PIN, GPIO.IN)
GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200)
try:
while True:
time.sleep(0.5)
except:
# Event wieder entfernen mittels:
GPIO.remove_event_detect(RECEIVER_PIN)
Alles anzeigen
Codeschnippsel von:
https://tutorials-raspberrypi.de/raspberry-pi-l…eite-distanzen/
https://www.raspberrypi.org/forums/viewtopic.php?t=91902
jetzt kommt aber der fehler;
Code
File "laserschranke2.py", line 33
if peoplecount > 0 and uploadcount == 0:
^
IndentationError: unindent does not match any outer indentation level
wie kann ich das Problem beheben?
Weiss einer einen besseren weg?
Auch möchte ich ein Foto machen bei laserunterbruch, dies aber zu einem späteren zeitpunkt. ersteinmal soll der counter funktionieren
Gruss
Remo