Hi i have been tasked to do a online counter using passive infrared sensor and a Raspberry PI. I need to be able to post the count on a webpage page which i had to create on my own.However, i am unable to get the counter output which i had coded in python to my webpage page.
I have tried using count(output),exec() and shell_exec() and it did not work.
Is it possible not to try to use flask? As i am very new to webpage designing and python.
I am not very good in coding python or php.
These is the python codes i have written
import RPi.GPIO as GPIO #1
import math
import os
import threading
import subprocess
import time
import os.path
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", passwd="brandon",
db="menagerie")
cur =db.cursor()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12,GPIO.IN)
GPIO.setup(11,GPIO.IN) #16
peoplecount=0 #18
while(1):
if GPIO.input(12):
time.sleep(2)
peoplecount = peoplecount+1
time.sleep(1.5)
cur.execute("INSERT INTO people(vistor,Date) VALUES(1,now())")
db.commit()
print peoplecount
print "hello" #30
if(peoplecount < 1):
peoplecount=0
elif GPIO.input(11):
time.sleep(2)
peoplecount = peoplecount-1
time.sleep(1.5)
print peoplecount
print "come back again"
conn.commit()
cur.close()
These are my webpage codes :
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td {
border:1px solid black;
}
</style>
</head>
<body>
<?php
echo "welcome to PI LAB<br>";
echo date ('y-m-d H:i:s');
$conn = new mysqli("localhost","root","brandon","menagerie");
if($conn->connect_error)
{
die("connection failed:" . $conn->connect_error);
}
$sql = "SELECT * FROM people";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>Vistor</th><th>Entry</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["vistor"]. " </td><td> " . $row["Date"]. "</td>
</tr>";
}
echo"</table>";
}
$conn->close();
?>
</body>
</html>