This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed communication between webserver and raspberry pi. Updated the s…
…ave function at the user panel and placed the form in the header and footer so you dont have to included it each page. All our pages are forms anyway...
- Loading branch information
Luuk van Houdt
committed
Jan 28, 2016
1 parent
7834c59
commit 86f47d4
Showing
12 changed files
with
236 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
<div class="block border thick"> | ||
<h1>Inloggen</h1> | ||
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> | ||
<p> | ||
<input type="text" name="username" placeholder="Gebruikersnaam" /> | ||
</p> | ||
<p> | ||
<input type="password" name="password" placeholder="Wachtwoord" /> | ||
</p> | ||
<p> | ||
<button type="reset">reset</button> | ||
<button name="login" type="submit">login</button> | ||
</p> | ||
</form> | ||
<input type="text" name="username" placeholder="Gebruikersnaam" /> | ||
<input type="password" name="password" placeholder="Wachtwoord" /> | ||
<p> | ||
<button type="reset">reset</button> | ||
<button name="login" type="submit">login</button> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
<div class="block border thick"> | ||
<div class="heading border thick"> | ||
<h1>Gebruikerspaneel</h1> | ||
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> | ||
<section class="dotted"> | ||
<ul> | ||
<li><strong>Woonplaats:</strong><span><?php print $_SESSION['system']['city']; ?></span></li> | ||
<li><strong>Straatnaam:</strong><span><?php print $_SESSION['system']['street']; ?></span></li> | ||
<li><strong>Huisnummer:</strong><span><?php print $_SESSION['system']['house']; ?></span></li> | ||
</ul> | ||
</section> | ||
<section class="lights"> | ||
<h2>Verlichting</h2> | ||
<?php | ||
$lights = $_SESSION['system']['lights']; | ||
$lights_class = ($lights==1) ? ' active' : ''; | ||
?> | ||
<div class="switch<?php print $lights_class; ?>"> | ||
<a class="off">uit</a> | ||
<a class="on">aan</a> | ||
<input name="lights" type="hidden" value="<?php print $lights; ?>" /> | ||
</div> | ||
</section> | ||
<section class="camera"> | ||
<h2>Camera</h2> | ||
<?php | ||
$camera = $_SESSION['system']['camera']; | ||
$camera_class = ($camera==1) ? ' active' : ''; | ||
?> | ||
<div class="switch<?php print $camera_class; ?>"> | ||
<a class="off">uit</a> | ||
<a class="on">aan</a> | ||
<input name="camera" type="hidden" value="<?php print $camera; ?>" /> | ||
</div> | ||
</section> | ||
<button name="logout" type="submit">Uitloggen</button> | ||
<button name="save" type="submit">Opslaan</button> | ||
</form> | ||
<button name="logout" type="submit">Uitloggen</button> | ||
</div> | ||
<div class="block border thick"> | ||
<h2>Systeem</h2> | ||
<section class="dotted"> | ||
<ul> | ||
<li><strong>Woonplaats:</strong><span><?php print $_SESSION['system']['city']; ?></span></li> | ||
<li><strong>Straatnaam:</strong><span><?php print $_SESSION['system']['street']; ?></span></li> | ||
<li><strong>Huisnummer:</strong><span><?php print $_SESSION['system']['house']; ?></span></li> | ||
</ul> | ||
</section> | ||
<section class="lights"> | ||
<h2>Verlichting</h2> | ||
<?php | ||
$lights = $_SESSION['system']['lights']; | ||
$lights_class = ($lights==1) ? ' active' : ''; | ||
?> | ||
<div class="switch<?php print $lights_class; ?>"> | ||
<a class="off">uit</a> | ||
<a class="on">aan</a> | ||
<input name="lights" type="hidden" value="<?php print $lights; ?>" /> | ||
</div> | ||
</section> | ||
<section class="camera"> | ||
<h2>Camera</h2> | ||
<?php | ||
$camera = $_SESSION['system']['camera']; | ||
$camera_class = ($camera==1) ? ' active' : ''; | ||
?> | ||
<div class="switch<?php print $camera_class; ?>"> | ||
<a class="off">uit</a> | ||
<a class="on">aan</a> | ||
<input name="camera" type="hidden" value="<?php print $camera; ?>" /> | ||
</div> | ||
</section> | ||
<button name="save" type="submit">Opslaan</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from config import * | ||
import urllib2, urllib, os | ||
|
||
# Data send to the webserver | ||
sendBoot = urllib.urlencode([ | ||
('api', 'boot'), | ||
('user', username), | ||
('pass', password), | ||
('ip', ip), | ||
('port', port), | ||
]) | ||
|
||
# Send te boot message | ||
boot = urllib2.Request(host, sendBoot) | ||
boot.add_header('Content-type', 'application/x-www-form-urlencoded') | ||
print(urllib2.urlopen(boot).read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
|
||
# Configuration | ||
username = 'guest' | ||
password = 'guest' | ||
host = 'http://192.168.178.23/repos/alpha-domotica/index.php' | ||
ip = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1').read().rstrip() | ||
port = 4000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from config import * | ||
from boot import * | ||
from speaker import * | ||
from listener import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from config import * | ||
from bottle import request, post, run | ||
from RPi import GPIO as GPIO | ||
import hashlib | ||
|
||
# Setup the hardware | ||
theLight = 4 | ||
GPIO.setmode(GPIO.BCM) | ||
GPIO.setup(theLight, GPIO.OUT) | ||
GPIO.output(theLight, GPIO.LOW) | ||
|
||
# Setup the webserver so we can receive data | ||
@post('/execute') | ||
def do_execute(): | ||
# Check if the login is valid | ||
output = "" | ||
if request.POST.get('user') == username and request.POST.get('pass') == hashlib.md5(password).hexdigest(): | ||
if int(request.POST.get('lights')): | ||
GPIO.output(theLight, GPIO.HIGH) | ||
output += "Lights ON" | ||
else: | ||
GPIO.output(theLight, GPIO.LOW) | ||
output += "Lights OFF" | ||
|
||
output += " and " | ||
|
||
if int(request.POST.get('camera')): | ||
output += "Camera ON" | ||
else: | ||
output += "Camera OFF" | ||
else: | ||
output = "Invalid login credentials." | ||
|
||
print(output) | ||
|
||
run(host=ip, port=port) | ||
|
||
GPIO.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from config import * | ||
from time import sleep as sleep | ||
from RPi import GPIO as GPIO | ||
import urllib2, urllib | ||
|
||
try: | ||
# What will be send when the switch is triggered | ||
sendMessage = urllib.urlencode([ | ||
('api', 'message'), | ||
('user', username), | ||
('pass', password), | ||
]) | ||
|
||
# Use the numbering scheme | ||
GPIO.setmode(GPIO.BCM) | ||
|
||
# Define the PIN's | ||
switchAlertA = 5 | ||
switchAlertB = 6 | ||
|
||
# Setup the GPIO's | ||
GPIO.setup(switchAlertA, GPIO.IN) | ||
GPIO.setup(switchAlertB, GPIO.IN) | ||
|
||
|
||
while True: | ||
|
||
# When the switch is triggered send a message | ||
if GPIO.input(switchAlertA) or GPIO.input(switchAlertB): | ||
message = urllib2.Request(host, sendMessage) | ||
message.add_header('Content-type', 'application/x-www-form-urlencoded') | ||
print(urllib2.urlopen(message).read()) | ||
sleep(5) | ||
|
||
# Do not use all the CPU | ||
sleep(0.1) | ||
|
||
# Code execution is interrupted | ||
except KeyboardInterrupt: | ||
# Reset GPIO all settings | ||
GPIO.cleanup() |
Empty file.