raspberry pi people count to google form

Viewed 104

I am trying to count people who break a laser beam (hardware works) and then post to google form.

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 = 'vcgencmd measure_temp | cut -c6-7' # 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:
    global peoplecount
    global uploadcount
    if peoplecount > 0 and uploadcount == 0:
                try:
                        url = 'https://docs.google.com/forms/d/e/1FAIpQLSduNOOwMUtpQc5QNFbcwPXQhD0MRppum3kkYHThkFvo0JluQw/formResponse?entry.664100658=%s&entry.1901373746=%s&entry.1382055524=%s&entry.718436324=%s&submit=Senden' % (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 = 0
                        peoplecount = 0
                        print "values reset"
                except:
                        print "Cannot Access Page"


    elif time.strftime("%M") in ("38", "39", "40", "41") and uploadcount == 1:
                uploadcount = 0

    elif GPIO.input(RECEIVER_PIN) == 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)

                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)

error:

Lichtschranke wurde unterbrochen
Motion Detected: Door 1 at 19:47:22 on Friday. Count is 1
Cannot Access Page

It seems that the variables don't send any data. If I don't send the form with %s it works. Can anybody help me or is there a better method?

1 Answers

I think you are using the Browser module to open the URL. If so you haven't imported the browser module. So that's why it's throwing an exception and printing cannot Access page

from mechanize import Browser
br = Browser()

Install the module using PIP and add this at the start of the code. This should help

Related