gpt4 book ai didi

python - 树莓派人数统计到谷歌表格

转载 作者:行者123 更新时间:2023-12-04 10:30:01 30 4
gpt4 key购买 nike

我正在尝试计算打破激光束(硬件工作)然后发布到谷歌表格的人。
代码:

###################################################
######### 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)
错误:
Lichtschranke wurde unterbrochen
Motion Detected: Door 1 at 19:47:22 on Friday. Count is 1
Cannot Access Page
变量似乎没有发送任何数据。如果我不发送带有 %s 的表格有用。有人可以帮助我还是有更好的方法?

最佳答案

我认为您正在使用浏览器模块打开 URL。如果是这样,您还没有导入浏览器模块。所以这就是它抛出异常并且打印无法访问页面的原因

from mechanize import Browser
br = Browser()

使用 PIP 安装模块并将其添加到代码的开头。这应该有帮助

关于python - 树莓派人数统计到谷歌表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60458557/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com