new commit

This commit is contained in:
Joel Garcia 2021-09-30 20:59:30 -05:00
commit 5dd9e5972b
14 changed files with 864 additions and 0 deletions

0
README.md Normal file
View File

19
app.php Executable file
View File

@ -0,0 +1,19 @@
<head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<link rel="stylesheet" href="custom.css">
</head>
<?php
$v = $_POST['usuario'];
$v2 = $_POST['u2'];
$v3 = $_POST['u3'];
$v4 = $_POST['u4'];
$command = escapeshellcmd("sudo ./servo.py $v");
$output = shell_exec($command);
echo "This is a test, you turned your servo to $v degrees <br>";
echo "you also added $v2, $v3 and $v4"
//header("Location:ejemplo1.html");
?>

172
custom.css Normal file
View File

@ -0,0 +1,172 @@
:root {
/* Set sans-serif & mono fonts */
--sans-font: "IBM Plex Sans","Roboto",-apple-system,BlinkMacSystemFont,"Nimbus Sans L",Avenir,"Noto Sans", "Segoe UI",Arial,Helvetica,"Helvetica Neue",sans-serif;
--mono-font: "IBM Plex Mono","Roboto Mono","Ubuntu Mono","Fira Code","Overpass Mono", Monaco,"Droid Sans Mono",monospace;
/* Body font size. By default, effectively 18.4px, based on 16px as 'root em' */
--base-fontsize: 1.2rem;
/* Major third scale progression - see https://type-scale.com/ */
--header-scale: 1.185;
/* Line height is set to the "Golden ratio" for optimal legibility */
--line-height: 1.618;
/*This is my dark themed color scheme*/
--bg: #FFFFFF;
--accent-bg: #F2F4F8;
--text: #4c566a;
--text-light: #4c566a;
--border: #3b4252;
--accent: #5e81ac;
--accent-light: #5e81ac;
--code: #2e3440;
--code-bg: #e5e9f0;
}
@media (prefers-color-scheme:dark) {
:root {
--bg: #242933;
--accent-bg: #3b4252;
--text: #eceff4;
--text-light: #d8dee9;
--border: #88c0d0;
--accent: #a3be8c;
--accent-light: #bf616a;
--code: #ebcb8b;
--code-bg: #2e3440;
}
}
html{
font-family: var(--sans-font);
}
hr{
color: var(--border);
}
header{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 1rem 0;
}
body {
padding: 20px;
background-color: var(--bg);
color: var(--text);
font-size: 1.1rem;
line-height: var(--line-height);
margin: 0 auto;
max-width: 50rem;
}
main img, main video, embed {
max-width: 100%;
height: auto;
opacity: 0.8;
border-radius: 5px;
}
figure {
margin: 0;
}
figcaption {
font-size: .9rem;
color: var(--text-light);
text-align: center;
margin-bottom: 1rem;
}
blockquote {
color: var(--text-light);
font-style: italic;
}
a {
color: var(--accent);
}
a:hover {
text-decoration: none
}
h1 {
font-size: 1.3rem;
color: var(--border);
margin-bottom: 0px;
}
h2, h3, h4, h5, h6 {
font-size: 1.2rem;
color: var(--accent-light);
margin-bottom: 0px;
}
p {
padding: 0px;
}
code, pre, pre span, kbd, samp {
font-family: var(--mono-font);
color: var(--code);
background: var(--code-bg);
border-radius: 5px;
padding: 0.12rem 0.3rem;
}
kbd {
border: 1px solid var(--preformatted);
border-bottom: 3px solid var(--preformatted);
border-radius: 5px;
padding: .1rem;
}
pre {
padding: 1rem 1.4rem;
max-width: 100%;
overflow: auto;
overflow-x: auto;
background: var(--code-bg);
border: none;
border-radius: 5px;
}
pre code {
font-family: var(--mono-font);
background: none;
margin: 0;
padding: 0;
}
svg {
width: 36px;
}
/* Format navigation */
nav a {
background: var(--code-bg);
margin: 1rem 0 0 .5rem;
color: var(--border) !important;
border-radius: 8px;
display: inline-block;
padding: .1rem .6rem;
text-decoration: none;
transition: .4s;
}
nav a.nav-current {
background: var(--border);
color: var(--bg) !important;
font-weight: 700;
opacity: 1;
}
nav a:hover {
color: var(--bg) !important;
border-color: var(--border);
background: var(--border);
}
header h1{
color: var(--accent) !important;
display: inline-block;
}
header nav {
display: inline-block;
/*position: relative;*/
}
a button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
border: none;
border-radius: 5px;
background: var(--accent);
font-size: 1rem;
color: var(--bg);
text-decoration: none;
padding: .7rem .9rem;
margin: .5rem .1rem;
transition: .4s;
}

52
data.php Executable file
View File

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>Parking Lot Database</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<link rel="stylesheet" href="custom.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
</head>
<body>
<main>
<h1> Parking Lot database</h1>
<?php
if($_POST['entrance'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$command = escapeshellcmd("sudo ./parking.py 2");
$output = shell_exec($command);
echo "$output";
}
if($_POST['space_num'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$v = $_POST['space_num'];
$command2 = escapeshellcmd("sudo ./parking.py 1 $v");
$output2 = shell_exec($command2);
echo "$output2";
}
?>
<p>Welcome to the parking lot. Make sure to update de database to check if there are any spaces available</p>
<form action="data.php" method="POST">
<input type="submit" value="Update database">
</form>
<p>If you want to enter the parking lot, press the button below to know your assigned spot and enter when the entrance opens.</p>
<form action="data.php" method="POST">
<input type="submit" value="Access parking lot" name="entrance" id="entrance">
</form>
<p>If you want to exit from the parking lot, input your spot number to open the exit.</p>
<form action="data.php" method="POST" autocomplete="off">
<input type="number" id="space_num" name="space_num" >
<input type="submit" value="Exit parking lot">
</form>
<?php
$command = escapeshellcmd("sudo ./database_output.py");
$output = shell_exec($command);
echo "$output <br>";
?>
</main>
</body>
</html>

57
database_output.py Executable file
View File

@ -0,0 +1,57 @@
#!/usr/bin/python3
import pymysql
import sys
db = pymysql.connect(host='localhost', user='pi2', passwd='emb20', db='parking_lot')
cur = db.cursor()
def output_query(sql):
query = sql
cur.execute(query)
db.commit()
values = cur.fetchall()
if sql == available:
if len(values) != 0:
print("These are the available spaces")
else:
print("There are no spaces available at the moment")
if sql == all_values:
print("There are {0} spaces in use".format(len(values)))
if len(values) != 0:
print("""<br>
<table>
<tr>
<th>ID</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>State</th>
</tr>""")
for m in values:
id_s = m[0]
date= m[1]
startime= m[2]
endtime= m[3]
if int(m[4])== 1:
estado = "in use"
elif int(m[4]) == 0:
estado = "free"
print( "<tr><td>{0}</td> <td>{1}</td> <td>{2}</td> <td>{3}</td><td>{4}</td></tr>".format(id_s, date,startime, endtime, estado))
print("</table>")
# print(values)
# print("### Latest 10 values ###\n")
available="select * from spaces where usedID = False"
all_values="select * from spaces where usedID = True"
last_value="select * from sensor where id_SENSOR = (select max(id_SENSOR) from sensor)"
last_10 = "SELECT * FROM (select * from sensor order by ID_sensor DESC LIMIT 10) section order by ID_sensor ASC"
print("<h1> Free spaces </h1>")
output_query(available)
print("<h1> Used spaces </h1>")
output_query(all_values)

19
ejemplo1.html Executable file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<link rel="stylesheet" href="custom.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
</head>
<body>
<p>Input any angle from 0 to 180 to control servomotor, remember that
thats the limit of the servomotor</p>
<p>Make sure you also add whateber in the other input boxes</p>
<form action="data.php" method="POST">
<!--<input type="text" id="usuario" name="usuario">-->
<input type="submit" value="Visualizar datos">
</form>
</body>
</html>

13
entering.php Normal file
View File

@ -0,0 +1,13 @@
<head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--<link rel="stylesheet" href="custom.css">-->
</head>
<?php
$command = escapeshellcmd("sudo ./parking.py 2");
$output = shell_exec($command);
echo "$output";
?>

BIN
favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

368
index.html Executable file
View File

@ -0,0 +1,368 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Apache2 Debian Default Page: It works</title>
<style type="text/css" media="screen">
* {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
body, html {
padding: 3px 3px 3px 3px;
background-color: #D8DBE2;
font-family: Verdana, sans-serif;
font-size: 11pt;
text-align: center;
}
div.main_page {
position: relative;
display: table;
width: 800px;
margin-bottom: 3px;
margin-left: auto;
margin-right: auto;
padding: 0px 0px 0px 0px;
border-width: 2px;
border-color: #212738;
border-style: solid;
background-color: #FFFFFF;
text-align: center;
}
div.page_header {
height: 99px;
width: 100%;
background-color: #F5F6F7;
}
div.page_header span {
margin: 15px 0px 0px 50px;
font-size: 180%;
font-weight: bold;
}
div.page_header img {
margin: 3px 0px 0px 40px;
border: 0px 0px 0px;
}
div.table_of_contents {
clear: left;
min-width: 200px;
margin: 3px 3px 3px 3px;
background-color: #FFFFFF;
text-align: left;
}
div.table_of_contents_item {
clear: left;
width: 100%;
margin: 4px 0px 0px 0px;
background-color: #FFFFFF;
color: #000000;
text-align: left;
}
div.table_of_contents_item a {
margin: 6px 0px 0px 6px;
}
div.content_section {
margin: 3px 3px 3px 3px;
background-color: #FFFFFF;
text-align: left;
}
div.content_section_text {
padding: 4px 8px 4px 8px;
color: #000000;
font-size: 100%;
}
div.content_section_text pre {
margin: 8px 0px 8px 0px;
padding: 8px 8px 8px 8px;
border-width: 1px;
border-style: dotted;
border-color: #000000;
background-color: #F5F6F7;
font-style: italic;
}
div.content_section_text p {
margin-bottom: 6px;
}
div.content_section_text ul, div.content_section_text li {
padding: 4px 8px 4px 16px;
}
div.section_header {
padding: 3px 6px 3px 6px;
background-color: #8E9CB2;
color: #FFFFFF;
font-weight: bold;
font-size: 112%;
text-align: center;
}
div.section_header_red {
background-color: #CD214F;
}
div.section_header_grey {
background-color: #9F9386;
}
.floating_element {
position: relative;
float: left;
}
div.table_of_contents_item a,
div.content_section_text a {
text-decoration: none;
font-weight: bold;
}
div.table_of_contents_item a:link,
div.table_of_contents_item a:visited,
div.table_of_contents_item a:active {
color: #000000;
}
div.table_of_contents_item a:hover {
background-color: #000000;
color: #FFFFFF;
}
div.content_section_text a:link,
div.content_section_text a:visited,
div.content_section_text a:active {
background-color: #DCDFE6;
color: #000000;
}
div.content_section_text a:hover {
background-color: #000000;
color: #DCDFE6;
}
div.validator {
}
</style>
</head>
<body>
<div class="main_page">
<div class="page_header floating_element">
<img src="/icons/openlogo-75.png" alt="Debian Logo" class="floating_element"/>
<span class="floating_element">
Apache2 Debian Default Page
</span>
</div>
<!-- <div class="table_of_contents floating_element">
<div class="section_header section_header_grey">
TABLE OF CONTENTS
</div>
<div class="table_of_contents_item floating_element">
<a href="#about">About</a>
</div>
<div class="table_of_contents_item floating_element">
<a href="#changes">Changes</a>
</div>
<div class="table_of_contents_item floating_element">
<a href="#scope">Scope</a>
</div>
<div class="table_of_contents_item floating_element">
<a href="#files">Config files</a>
</div>
</div>
-->
<div class="content_section floating_element">
<div class="section_header section_header_red">
<div id="about"></div>
It works!
</div>
<div class="content_section_text">
<p>
This is the default welcome page used to test the correct
operation of the Apache2 server after installation on Debian systems.
If you can read this page, it means that the Apache HTTP server installed at
this site is working properly. You should <b>replace this file</b> (located at
<tt>/var/www/html/index.html</tt>) before continuing to operate your HTTP server.
</p>
<p>
If you are a normal user of this web site and don't know what this page is
about, this probably means that the site is currently unavailable due to
maintenance.
If the problem persists, please contact the site's administrator.
</p>
</div>
<div class="section_header">
<div id="changes"></div>
Configuration Overview
</div>
<div class="content_section_text">
<p>
Debian's Apache2 default configuration is different from the
upstream default configuration, and split into several files optimized for
interaction with Debian tools. The configuration system is
<b>fully documented in
/usr/share/doc/apache2/README.Debian.gz</b>. Refer to this for the full
documentation. Documentation for the web server itself can be
found by accessing the <a href="/manual">manual</a> if the <tt>apache2-doc</tt>
package was installed on this server.
</p>
<p>
The configuration layout for an Apache2 web server installation on Debian systems is as follows:
</p>
<pre>
/etc/apache2/
|-- apache2.conf
| `-- ports.conf
|-- mods-enabled
| |-- *.load
| `-- *.conf
|-- conf-enabled
| `-- *.conf
|-- sites-enabled
| `-- *.conf
</pre>
<ul>
<li>
<tt>apache2.conf</tt> is the main configuration
file. It puts the pieces together by including all remaining configuration
files when starting up the web server.
</li>
<li>
<tt>ports.conf</tt> is always included from the
main configuration file. It is used to determine the listening ports for
incoming connections, and this file can be customized anytime.
</li>
<li>
Configuration files in the <tt>mods-enabled/</tt>,
<tt>conf-enabled/</tt> and <tt>sites-enabled/</tt> directories contain
particular configuration snippets which manage modules, global configuration
fragments, or virtual host configurations, respectively.
</li>
<li>
They are activated by symlinking available
configuration files from their respective
*-available/ counterparts. These should be managed
by using our helpers
<tt>
a2enmod,
a2dismod,
</tt>
<tt>
a2ensite,
a2dissite,
</tt>
and
<tt>
a2enconf,
a2disconf
</tt>. See their respective man pages for detailed information.
</li>
<li>
The binary is called apache2. Due to the use of
environment variables, in the default configuration, apache2 needs to be
started/stopped with <tt>/etc/init.d/apache2</tt> or <tt>apache2ctl</tt>.
<b>Calling <tt>/usr/bin/apache2</tt> directly will not work</b> with the
default configuration.
</li>
</ul>
</div>
<div class="section_header">
<div id="docroot"></div>
Document Roots
</div>
<div class="content_section_text">
<p>
By default, Debian does not allow access through the web browser to
<em>any</em> file apart of those located in <tt>/var/www</tt>,
<a href="http://httpd.apache.org/docs/2.4/mod/mod_userdir.html" rel="nofollow">public_html</a>
directories (when enabled) and <tt>/usr/share</tt> (for web
applications). If your site is using a web document root
located elsewhere (such as in <tt>/srv</tt>) you may need to whitelist your
document root directory in <tt>/etc/apache2/apache2.conf</tt>.
</p>
<p>
The default Debian document root is <tt>/var/www/html</tt>. You
can make your own virtual hosts under /var/www. This is different
to previous releases which provides better security out of the box.
</p>
</div>
<div class="section_header">
<div id="bugs"></div>
Reporting Problems
</div>
<div class="content_section_text">
<p>
Please use the <tt>reportbug</tt> tool to report bugs in the
Apache2 package with Debian. However, check <a
href="http://bugs.debian.org/cgi-bin/pkgreport.cgi?ordering=normal;archive=0;src=apache2;repeatmerged=0"
rel="nofollow">existing bug reports</a> before reporting a new bug.
</p>
<p>
Please report bugs specific to modules (such as PHP and others)
to respective packages, not to the web server itself.
</p>
</div>
</div>
</div>
<div class="validator">
</div>
</body>
</html>

25
parking.html Executable file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Parking Lot Database</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<!--<link rel="stylesheet" href="custom.css">-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
</head>
<body>
<p>Welcome to the parking lot.</p>
<form action="entering.php" method="POST" id="entrance">
<input type="submit" value="Access parking lot">
</form>
<form action="data.php" method="POST">
<input type="submit" value="View available spots">
</form>
<form action="parking.php" method="POST">
<input type="text" id="space_num" name="space_num" legend="Ingrese el numero del que proviene">
<input type="submit" value="Exit parking lot">
</form>
</body>
</html>

12
parking.php Normal file
View File

@ -0,0 +1,12 @@
<head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
<!--<link rel="stylesheet" href="custom.css">-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<?php
$v = $_POST['space_num'];
$command = escapeshellcmd("sudo ./parking.py 1 $v");
$output = shell_exec($command);
echo "$output";
?>

106
parking.py Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/python3
import RPi.GPIO as GPIO
import pymysql
import sys
import os
import time as t
from gtts import gTTS as gt
from datetime import datetime as dt
def angle_to_duty(angle):
return (angle / 18 + 2)
def allow_entrance():
servo.start(0)
for i in range(0,91):
servo.ChangeDutyCycle(angle_to_duty(i))
t.sleep(0.004)
t.sleep(1)
for i in range(90,-1, -1):
servo.ChangeDutyCycle(angle_to_duty(i))
t.sleep(0.006)
t.sleep(0.5)
pressed = int(sys.argv[1])
db = pymysql.connect(host='localhost', user='pi2', passwd='emb20', db='parking_lot')
cur = db.cursor()
servo_pin = 4
pwm_freq = 50 # Nos referimos a un rango en Hz
GPIO.setmode(GPIO.BCM)
GPIO.setup(servo_pin, GPIO.OUT)
servo = GPIO.PWM(servo_pin, pwm_freq)
if pressed == 1:
try:
space_num = int(sys.argv[2])
pressed = 0
query= "select spaceID from spaces where usedID = True"
cur.execute(query)
db.commit()
spaces = cur.fetchall()
if (len(spaces)) == 0:
output="There are no cars inside"
print(output)
else:
spaceID = space_num
query= "select usedID from spaces where spaceID = {0}".format(spaceID)
cur.execute(query)
db.commit()
spaces = cur.fetchall()
if spaces[0][0] == True:
print("<h2>Have a nice day!</h2>")
print("<p>We hope to see you again!</p>")
now = dt.now()
date = now.date()
time = now.time().replace(microsecond=0)
query = "update spaces set date = '{0}', endTime = '{1}', usedID = False where spaceID = {2}".format(date, time, spaceID)
cur.execute(query)
db.commit()
allow_entrance()
else:
print("<h2>This place is already empty!</h2>")
output = "<p>Please input a valid number.</p>"
print(output)
pressed = 1
except IndexError:
print("<h2>This number is out of bounds!</h2>")
output = "Please, input the spot you were assigned when you entered."
print("<script>alert('{0}')</script>".format(output))
print(output)
pressed = 1
elif pressed == 2:
try:
pressed = 0
query = "select spaceID from spaces where usedID = False order by spaceID desc"
cur.execute(query)
db.commit()
spaces = cur.fetchall()
status= "<p>Park your vehicle in slot <b>{0}</b>.".format(spaces[0][0])
print("<h2>Remember to social distance!</h2>")
print(status)
print("Enjoy your visit!</p>")
now = dt.now()
date = now.date()
time = now.time().replace(microsecond=0)
query = "update spaces set date = '{0}', startTime = '{1}', endTime= NULL, usedID = True where spaceID = {2}".format(date, time, spaces[0][0])
cur.execute(query)
db.commit()
allow_entrance()
except IndexError:
status ="<script>alert('Sorry, but there are no spaces left')</script>"
print(status)
servo.stop()
GPIO.cleanup()
db.close()
sys.exit(0)

21
servo.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/python3
import sys
import RPi.GPIO as GPIO
import time
def angleToDuty(angle):
return (angle / 18 + 2)
angle2 = int(sys.argv[1])
GPIO.setmode(GPIO.BCM)
servoPin=4
pwm_freq = 50
GPIO.setup(servoPin, GPIO.OUT)
servo = GPIO.PWM(servoPin, pwm_freq)
servo.start(0)
servo.ChangeDutyCycle(angleToDuty(angle2))
time.sleep(1)
servo.stop()
GPIO.cleanup()

BIN
sound.mp3 Normal file

Binary file not shown.