have the count reset every 10 minutes for more useful results
This commit is contained in:
@@ -33,7 +33,7 @@ try:
|
|||||||
#print mcp.read_adc(0)
|
#print mcp.read_adc(0)
|
||||||
# Check if current ldr value is less than or greater than ldrConst
|
# Check if current ldr value is less than or greater than ldrConst
|
||||||
if mcp.read_adc(0) > 150:
|
if mcp.read_adc(0) > 150:
|
||||||
count = count + 1
|
count += 1
|
||||||
|
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = MySQLdb.connect("HOSTNAME","USERNAME","PASSWORD","DATABASE")
|
db = MySQLdb.connect("HOSTNAME","USERNAME","PASSWORD","DATABASE")
|
||||||
@@ -50,6 +50,7 @@ try:
|
|||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
# Commit your changes in the database
|
# Commit your changes in the database
|
||||||
db.commit()
|
db.commit()
|
||||||
|
count = 0 #reset count for next interval
|
||||||
except:
|
except:
|
||||||
# Rollback in case there is any error
|
# Rollback in case there is any error
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|||||||
@@ -21,11 +21,10 @@ count = 0
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
curr_date = datetime.now()
|
||||||
|
|
||||||
if GPIO.input(PIR_PIN):
|
if GPIO.input(PIR_PIN):
|
||||||
count = count + 1
|
count += 1
|
||||||
|
|
||||||
#print count
|
|
||||||
|
|
||||||
# Open database connection
|
# Open database connection
|
||||||
db = MySQLdb.connect("HOSTNAME","USERNAME","PASSWORD","DATABASE")
|
db = MySQLdb.connect("HOSTNAME","USERNAME","PASSWORD","DATABASE")
|
||||||
@@ -33,18 +32,15 @@ try:
|
|||||||
# prepare a cursor object using cursor() method
|
# prepare a cursor object using cursor() method
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
curr_date = datetime.now()
|
|
||||||
|
|
||||||
# Prepare SQL query to INSERT a record into the database.
|
|
||||||
sql = "INSERT INTO PIRSTATS (datetime, gatecount) VALUES ('%s', '%d')" % (curr_date.isoformat(' '), count)
|
|
||||||
|
|
||||||
|
|
||||||
if (curr_date.minute % 10 == 0) and (curr_date.second == 0):
|
if (curr_date.minute % 10 == 0) and (curr_date.second == 0):
|
||||||
try:
|
try:
|
||||||
# Execute the SQL command
|
# Execute the SQL command
|
||||||
cursor.execute(sql)
|
cursor.execute("INSERT INTO PIRSTATS (datetime, gatecount) VALUES ('%s', '%d')" % (curr_date.isoformat(' '), count))
|
||||||
# Commit your changes in the database
|
# Commit your changes in the database
|
||||||
db.commit()
|
db.commit()
|
||||||
|
count = 0 #reset count for next 10-minute interval
|
||||||
except:
|
except:
|
||||||
# Rollback in case there is any error
|
# Rollback in case there is any error
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ try:
|
|||||||
distance = round(distance, 2)
|
distance = round(distance, 2)
|
||||||
|
|
||||||
if distance < 120:
|
if distance < 120:
|
||||||
count = count + 1
|
count += 1
|
||||||
|
|
||||||
#print count
|
#print count
|
||||||
#print distance
|
#print distance
|
||||||
@@ -71,6 +71,7 @@ try:
|
|||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
# Commit your changes in the database
|
# Commit your changes in the database
|
||||||
db.commit()
|
db.commit()
|
||||||
|
count = 0 #reset count for next interval
|
||||||
except:
|
except:
|
||||||
# Rollback in case there is any error
|
# Rollback in case there is any error
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|||||||
Reference in New Issue
Block a user