From 7db4dde048df8e440bcc25fef89c3c5dd26abc86 Mon Sep 17 00:00:00 2001 From: Luuk van Houdt Date: Thu, 28 Jan 2016 18:47:39 +0100 Subject: [PATCH] Everything is working correctly now, added some styling. One thing still has to be tested, will speaker.py send a shutdown message when the script stops executing. --- css/main.css | 180 +++++++++++++++++++++++++++++++++--------- html/admin.php | 108 +++++++++++++++++++++---- html/login.php | 12 +-- html/user.php | 12 +-- inc/functions.php | 63 +++++++++------ install.sql | 39 ++++----- py/boot.py | 1 + py/domotica-system.py | 71 ----------------- py/index.py | 15 +++- py/listener.py | 62 +++++++-------- py/speaker.py | 95 ++++++++++++---------- scss/_common.scss | 106 ++++++++++++++++++++++--- scss/_variables.scss | 3 +- 13 files changed, 504 insertions(+), 263 deletions(-) delete mode 100644 py/domotica-system.py diff --git a/css/main.css b/css/main.css index d765ece..de06e34 100644 --- a/css/main.css +++ b/css/main.css @@ -65,7 +65,7 @@ article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, /* line 1, ../scss/_common.scss */ html, body { - font: 14px Tahoma, Geneva, sans-serif; + font: 0 Tahoma, Geneva, sans-serif normal; } /* line 4, ../scss/_common.scss */ @@ -93,52 +93,59 @@ p { font-size: 14px; } -/* line 20, ../scss/_common.scss */ +/* line 21, ../scss/_common.scss */ +a { + text-decoration: none; +} + +/* line 25, ../scss/_common.scss */ h1 { font-size: 28px; } -/* line 23, ../scss/_common.scss */ +/* line 28, ../scss/_common.scss */ h2 { font-size: 24px; } -/* line 26, ../scss/_common.scss */ +/* line 31, ../scss/_common.scss */ h3 { font-size: 22px; } -/* line 29, ../scss/_common.scss */ +/* line 34, ../scss/_common.scss */ h4 { font-size: 20px; } -/* line 32, ../scss/_common.scss */ +/* line 37, ../scss/_common.scss */ h5 { font-size: 18px; } -/* line 35, ../scss/_common.scss */ +/* line 40, ../scss/_common.scss */ h6 { font-size: 16px; } -/* line 38, ../scss/_common.scss */ +/* line 43, ../scss/_common.scss */ h1, h2, h3, h4, h5, h6 { + color: #193441; font-family: Impact, Charcoal, sans-serif; margin-bottom: 20px; } -/* line 42, ../scss/_common.scss */ +/* line 49, ../scss/_common.scss */ input { width: 100%; border: 0; padding: 8px 4px; margin-bottom: 10px; display: inline-block; + box-sizing: border-box; } -/* line 49, ../scss/_common.scss */ +/* line 58, ../scss/_common.scss */ button { cursor: pointer; border: 0; @@ -149,69 +156,170 @@ button { -webkit-border-radius: 3px; border-radius: 3px; } -/* line 56, ../scss/_common.scss */ +/* line 65, ../scss/_common.scss */ button:focus, button:hover { background-color: #3E606F; } -/* line 61, ../scss/_common.scss */ -.row { +/* line 70, ../scss/_common.scss */ +header { + padding: 20px; + margin: -20px -20px 20px; + box-sizing: border-box; + background-color: rgba(255, 255, 255, 0.7); + border-bottom: 5px solid #D1DBBD; +} + +/* line 78, ../scss/_common.scss */ +section { + padding: 10px; margin-bottom: 20px; + box-sizing: border-box; + border: 1px dashed #3E606F; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; } -/* line 65, ../scss/_common.scss */ +/* line 86, ../scss/_common.scss */ +.results { + margin-top: 20px; + text-align: left; +} +/* line 89, ../scss/_common.scss */ +.results .row { + width: 100%; + font-size: 0; + display: inline-block; + box-sizing: border-box; + color: #193441; + padding: 10px 8px; + background-color: #94BFCA; + border-bottom: 1px solid #D1DBBD; +} +/* line 98, ../scss/_common.scss */ +.results .row:hover { + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80); + opacity: 0.8; +} +/* line 101, ../scss/_common.scss */ +.results .row:first-of-type { + -moz-border-radius: 10px 10px 0 0; + -webkit-border-radius: 10px; + border-radius: 10px 10px 0 0; +} +/* line 104, ../scss/_common.scss */ +.results .row:last-of-type { + border-bottom-width: 0; + -moz-border-radius: 0 0 10px 10px; + -webkit-border-radius: 0; + border-radius: 0 0 10px 10px; +} +/* line 108, ../scss/_common.scss */ +.results .row.active { + color: #FCFFF5; + background-color: #3E606F; +} +/* line 112, ../scss/_common.scss */ +.results .row span { + font-size: 14px; + margin-right: 2%; +} +/* line 116, ../scss/_common.scss */ +.results .row .status { + -moz-border-radius: 100%; + -webkit-border-radius: 100%; + border-radius: 100%; + height: 14px; + width: 14px; + display: inline-block; +} +/* line 121, ../scss/_common.scss */ +.results .row .status.off { + background-color: #D1DBBD; +} +/* line 124, ../scss/_common.scss */ +.results .row .status.on { + background-color: #3E606F; +} + +/* line 131, ../scss/_common.scss */ .block { padding: 20px; + width: 32%; + margin: 0 2% 20px 0; + font-size: 14px; box-sizing: border-box; - width: 33.33333%; + vertical-align: top; display: inline-block; background-color: rgba(255, 255, 255, 0.7); + border: 5px solid #D1DBBD; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; } @media screen and (max-width: 721px) and (min-width: 480px) { - /* line 65, ../scss/_common.scss */ + /* line 131, ../scss/_common.scss */ .block { width: 80%; + margin-right: 0; } } @media screen and (max-width: 481px) { - /* line 65, ../scss/_common.scss */ + /* line 131, ../scss/_common.scss */ .block { width: 100%; + margin-right: 0; } } - -/* line 79, ../scss/_common.scss */ -.border { - border: 1px solid #D1DBBD; - -moz-border-radius: 10px; - -webkit-border-radius: 10px; - border-radius: 10px; +/* line 150, ../scss/_common.scss */ +.block:last-of-type { + margin-right: 0; } -/* line 82, ../scss/_common.scss */ -.border.thick { - border-width: 5px; + +/* line 155, ../scss/_common.scss */ +.fields { + width: 100%; + font-size: 0; + display: inline-block; } -/* line 85, ../scss/_common.scss */ -.border.dotted { - border-style: dotted; +/* line 159, ../scss/_common.scss */ +.fields input[name="city"] { + width: 30%; + border-right: 2px solid #D1DBBD; + -moz-border-radius: 5px 0 0 5px; + -webkit-border-radius: 5px; + border-radius: 5px 0 0 5px; +} +/* line 164, ../scss/_common.scss */ +.fields input[name="street"] { + width: 40%; + border-right: 2px solid #D1DBBD; +} +/* line 168, ../scss/_common.scss */ +.fields input[name="house"] { + width: 30%; + -moz-border-radius: 0 5px 5px 0; + -webkit-border-radius: 0; + border-radius: 0 5px 5px 0; } -/* line 90, ../scss/_common.scss */ +/* line 174, ../scss/_common.scss */ .switch { display: inline-block; background-color: #D1DBBD; } -/* line 94, ../scss/_common.scss */ +/* line 178, ../scss/_common.scss */ .switch.active .on { cursor: default; background-color: #3E606F; } -/* line 98, ../scss/_common.scss */ +/* line 182, ../scss/_common.scss */ .switch.active .off { cursor: pointer; background-color: transparent; } -/* line 103, ../scss/_common.scss */ +/* line 187, ../scss/_common.scss */ .switch a { width: 30px; padding: 8px; @@ -219,11 +327,11 @@ button:focus, button:hover { line-height: 100%; display: inline-block; } -/* line 109, ../scss/_common.scss */ +/* line 193, ../scss/_common.scss */ .switch a.on { cursor: pointer; } -/* line 112, ../scss/_common.scss */ +/* line 196, ../scss/_common.scss */ .switch a.off { background-color: #3E606F; } diff --git a/html/admin.php b/html/admin.php index ed90393..99c1cb4 100644 --- a/html/admin.php +++ b/html/admin.php @@ -1,13 +1,20 @@ -
+

Beheerders paneel

-
-
+ +

Domotica systemen

- - - - +
+
+ + + +
+
+ +
+
+
prepare('SELECT * FROM systems WHERE city LIKE :city AND street LIKE :street AND house LIKE :house'); @@ -18,24 +25,97 @@ )); $rows = $q->fetchAll(); } else { - $q = $pdo->prepare('SELECT * FROM systems LIMIT 0,10'); + $q = $pdo->prepare('SELECT * FROM systems LIMIT 10'); $q->execute(); $rows = $q->fetchAll(); } if ($rows) : foreach ($rows as $row) : + $selected = (isset($_SESSION['system']) and $row['user_id']==$_SESSION['system']['user_id']) ? ' active' : ''; + ?> + + + + + + + + Geen domotica systemen gevonden. + +
+
+
+

Berichten

+
+ prepare('SELECT timestamp FROM messages WHERE user_id = :selected ORDER BY timestamp DESC LIMIT 10 '); + $q->execute(array( + ':selected' => $_SESSION['system']['user_id'], + )); + $rows = $q->fetchAll(); + if ($rows) : + foreach ($rows as $row) : ?>
- - - - +
+ Geen berichten voor het geselecteerde domotica systeem gevonden. + + Geen domotica systeem geselecteerd. + +
+
+
+

Handelingen

+ +
+

Verlichting

+ +
+ uit + aan + +
+
+
+

Camera

+ +
+ uit + aan + +
+
+
+ +
+ -
Geen domotica systemenen gevonden.
+ Geen domotica systeem geselecteerd. diff --git a/html/login.php b/html/login.php index c30d4c3..04eaaca 100644 --- a/html/login.php +++ b/html/login.php @@ -1,9 +1,11 @@ -
+

Inloggen

- - -

+

+ + +
+
-

+
\ No newline at end of file diff --git a/html/user.php b/html/user.php index cf2ab45..c7a05ce 100644 --- a/html/user.php +++ b/html/user.php @@ -1,10 +1,10 @@ -
+

Gebruikerspaneel

-
-
+ +

Systeem

-
+
  • Woonplaats:
  • Straatnaam:
  • @@ -35,5 +35,7 @@
- +
+ +
diff --git a/inc/functions.php b/inc/functions.php index 946ac6b..394e091 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -45,15 +45,15 @@ if (isset($_POST['save'])) { // Get the new value - $lights = (isset($_POST['lights'])) ? $_POST['lights'] : 0; - $camera = (isset($_POST['camera'])) ? $_POST['camera'] : 0; + $lights = (isset($_POST['lights'])) ? intval($_POST['lights']) : 0; + $camera = (isset($_POST['camera'])) ? intval($_POST['camera']) : 0; // Update the database with the new value $q = $pdo->prepare('UPDATE systems SET lights = :lights, camera = :camera WHERE user_id = :uid'); $q->execute(array( ':lights' => $_POST['lights'], ':camera' => $_POST['camera'], - ':uid' => $_SESSION['user']['user_id'], + ':uid' => $_SESSION['system']['user_id'], )); // Update the session with the new value @@ -68,23 +68,27 @@ $r = $q->fetch(); // Inform the related system with a POST request - $ip = rtrim($_SESSION['system']['ip']); - $port = rtrim($_SESSION['system']['port']); - $url = 'http://'.$ip.':'.$port.'/execute'; - $data = array( - 'user' => urlencode($_SESSION['user']['username']), - 'pass' => urlencode($r['password']), - 'lights' => urlencode($_SESSION['system']['lights']), - 'camera' => urlencode($_SESSION['system']['camera']), - ); - $data_string = ''; - foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } - rtrim($data_string,'&'); - $ch = curl_init(); - curl_setopt($ch,CURLOPT_URL,$url); - curl_setopt($ch,CURLOPT_POST,count($data)); - curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string); - $result = curl_exec($ch); + if (intval($_SESSION['system']['status'])) { + $ip = rtrim($_SESSION['system']['ip']); + $port = rtrim($_SESSION['system']['port']); + $url = 'http://' . $ip . ':' . $port . '/execute'; + $data = array( + 'user' => urlencode($_SESSION['user']['username']), + 'pass' => urlencode($r['password']), + 'lights' => urlencode($_SESSION['system']['lights']), + 'camera' => urlencode($_SESSION['system']['camera']), + ); + $data_string = ''; + foreach ($data as $key => $value) { + $data_string .= $key . '=' . $value . '&'; + } + rtrim($data_string, '&'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, count($data)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + $result = curl_exec($ch); + } // Redirect back to the form header('Location:'.$_SERVER['REQUEST_URI']); @@ -100,13 +104,18 @@ // Handle the on boot api call if ($_POST['api'] == 'boot' and $current_user) { - $q = $pdo->prepare('UPDATE systems SET ip = :ip, port = :port WHERE user_id = :uid'); + $q = $pdo->prepare('UPDATE systems SET ip = :ip, port = :port, status = :status WHERE user_id = :uid'); $q->execute(array( ':ip' => $_POST['ip'], - ':port' => $_POST['port'], + ':port' => intval($_POST['port']), + ':status' => intval($_POST['status']), ':uid' => $current_user['user_id'], )); - print('The system is ready to interact.'); + if (intval($_POST['status'])) { + print('The system is ready to interact.'); + } else { + print('The system shutdown successfully.'); + } } // Handle messages send via the api @@ -119,4 +128,12 @@ print('Message was successfully sent.'); } die(); +} + +if (isset($_GET['selected']) and (isset($_SESSION['user']['role']) and $_SESSION['user']['role'] == 1)) { + $q = $pdo->prepare('SELECT * FROM systems WHERE user_id = :id'); + $q->execute(array(':id' => $_GET['selected'])); + $r = $q->fetch(); + $_SESSION['system'] = $r; + header('Location:'.substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?selected'))); } \ No newline at end of file diff --git a/install.sql b/install.sql index 6e24027..c2a6d51 100644 --- a/install.sql +++ b/install.sql @@ -3,8 +3,8 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: Jan 26, 2016 at 08:05 AM --- Server version: 5.6.27-0ubuntu1 +-- Generation Time: Jan 28, 2016 at 06:38 PM +-- Server version: 5.6.28-0ubuntu0.15.10.1 -- PHP Version: 5.6.11-1ubuntu3.1 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; @@ -28,18 +28,9 @@ SET time_zone = "+00:00"; CREATE TABLE IF NOT EXISTS `messages` ( `message_id` int(11) NOT NULL, - `system_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; - --- --- Dumping data for table `messages` --- - -INSERT INTO `messages` (`message_id`, `system_id`, `user_id`, `timestamp`) VALUES -(1, 1, 2, '2016-01-26 07:02:23'), -(2, 1, 2, '2016-01-26 07:05:00'); +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; -- -------------------------------------------------------- @@ -65,8 +56,8 @@ CREATE TABLE IF NOT EXISTS `systems` ( -- INSERT INTO `systems` (`system_id`, `user_id`, `ip`, `port`, `status`, `city`, `street`, `house`, `camera`, `lights`) VALUES -(1, 2, '123.123.123.123', 80, 0, 'Utrecht', 'Nijenoord', '1', 0, 0), -(2, 3, '321.321.321.321', 80, 0, 'Amsterdam', 'Damrak', '1', 0, 0); + (1, 2, '0', 0, 0, 'Utrecht', 'Nijenoord', '1', 0, 0), + (2, 3, '0', 0, 0, 'Amsterdam', 'Damrak', '1', 0, 0); -- -------------------------------------------------------- @@ -86,9 +77,9 @@ CREATE TABLE IF NOT EXISTS `users` ( -- INSERT INTO `users` (`user_id`, `username`, `password`, `role`) VALUES -(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 1), -(2, 'user', 'ee11cbb19052e40b07aac0ca060c23ee', 0), -(3, 'guest', '084e0343a0486ff05530df6c705c8bb4', 0); + (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 1), + (2, 'user', 'ee11cbb19052e40b07aac0ca060c23ee', 0), + (3, 'guest', '084e0343a0486ff05530df6c705c8bb4', 0); -- -- Indexes for dumped tables @@ -98,19 +89,19 @@ INSERT INTO `users` (`user_id`, `username`, `password`, `role`) VALUES -- Indexes for table `messages` -- ALTER TABLE `messages` - ADD PRIMARY KEY (`message_id`); +ADD PRIMARY KEY (`message_id`); -- -- Indexes for table `systems` -- ALTER TABLE `systems` - ADD PRIMARY KEY (`system_id`); +ADD PRIMARY KEY (`system_id`); -- -- Indexes for table `users` -- ALTER TABLE `users` - ADD PRIMARY KEY (`user_id`); +ADD PRIMARY KEY (`user_id`); -- -- AUTO_INCREMENT for dumped tables @@ -120,17 +111,17 @@ ALTER TABLE `users` -- AUTO_INCREMENT for table `messages` -- ALTER TABLE `messages` - MODIFY `message_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3; +MODIFY `message_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=10; -- -- AUTO_INCREMENT for table `systems` -- ALTER TABLE `systems` - MODIFY `system_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3; +MODIFY `system_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3; -- -- AUTO_INCREMENT for table `users` -- ALTER TABLE `users` - MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4; +MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; \ No newline at end of file diff --git a/py/boot.py b/py/boot.py index 78895a4..6c32b11 100644 --- a/py/boot.py +++ b/py/boot.py @@ -8,6 +8,7 @@ ('pass', password), ('ip', ip), ('port', port), + ('status', 1), ]) # Send te boot message diff --git a/py/domotica-system.py b/py/domotica-system.py deleted file mode 100644 index 226560a..0000000 --- a/py/domotica-system.py +++ /dev/null @@ -1,71 +0,0 @@ -from time import sleep as sleep -import RPi.GPIO as GPIO -import urllib2, urllib - -# Configuration -username = 'guest' -password = 'guest' -url = 'http://alphadomotica.ml/index.php' -ip = urllib2.urlopen('http://ipinfo.io').read() -port = 80 - -# While running -try: - # Use the numbering scheme - GPIO.setmode(GPIO.BCM) - - # Global variables - statusLight = False - dataBoot = urllib.urlencode([ - ('api', 'boot'), - ('user', username), - ('pass', password), - ('ip', ip), - ('port', port), - ]) - dataMessage = urllib.urlencode([ - ('api', 'message'), - ('user', username), - ('pass', password), - ]) - - # Send te boot message - boot = urllib2.Request(url, dataBoot) - boot.add_header('Content-type', 'application/x-www-form-urlencoded') - print(urllib2.urlopen(boot).read()) - - - # Define the PIN's - theLight = 4 - switchAlert = 5 - switchLight = 6 - - # Setup the GPIO's - GPIO.setup(theLight, GPIO.OUT) - GPIO.setup(switchAlert, GPIO.IN) - GPIO.setup(switchLight, GPIO.IN) - - while True: - - # When the light switch is pressed - if GPIO.input(switchLight) and not statusLight: - statusLight = True - - if GPIO.input(switchAlert): - message = urllib2.Request(url, dataMessage) - message.add_header('Content-type', 'application/x-www-form-urlencoded') - print(urllib2.urlopen(message).read()) - - # Check if the light should be on or off - if statusLight: - GPIO.output(theLight, GPIO.HIGH) - else: - GPIO.output(theLight, GPIO.LOW) - - # Do not use all the CPU - sleep(0.1) - -# Code execution is interupted -except KeyboardInterrupt: - # Reset all settings - GPIO.cleanup() diff --git a/py/index.py b/py/index.py index cd1fa5d..b900685 100644 --- a/py/index.py +++ b/py/index.py @@ -1,4 +1,15 @@ from config import * from boot import * -from speaker import * -from listener import * \ No newline at end of file +from speaker import speaker +from listener import listener + +# Make the functions run parallel +from multiprocessing import Process + +if __name__ == '__main__': + p1 = Process(target=speaker) + p1.start() + p2 = Process(target=listener) + p2.start() + p1.join() + p2.join() \ No newline at end of file diff --git a/py/listener.py b/py/listener.py index 68f2dec..0de465b 100644 --- a/py/listener.py +++ b/py/listener.py @@ -1,38 +1,38 @@ from config import * -from bottle import request, post, run -from RPi import GPIO as GPIO -import hashlib +def listener(): + 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 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" + # Setup the webserver so we can receive data + @post('/execute') + def do_execute(): + output = "" + # Check if the login is valid + 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 " + output += " and " - if int(request.POST.get('camera')): - output += "Camera ON" - else: - output += "Camera OFF" - else: - output = "Invalid login credentials." + if int(request.POST.get('camera')): + output += "Camera ON" + else: + output += "Camera OFF" + else: + output = "Invalid login credentials." - print(output) + print(output) + run(host=ip, port=port) -run(host=ip, port=port) - -GPIO.cleanup() \ No newline at end of file + GPIO.cleanup() \ No newline at end of file diff --git a/py/speaker.py b/py/speaker.py index 0c55fd8..713b398 100644 --- a/py/speaker.py +++ b/py/speaker.py @@ -1,41 +1,56 @@ 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() \ No newline at end of file +def speaker(): + 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: + # Data send to the webserver + sendShutdown = urllib.urlencode([ + ('api', 'boot'), + ('user', username), + ('pass', password), + ('ip', ip), + ('port', port), + ('status', 0), + ]) + + # Send te boot message + shutdown = urllib2.Request(host, sendShutdown) + shutdown.add_header('Content-type', 'application/x-www-form-urlencoded') + print(urllib2.urlopen(shutdown).read()) + + # Reset GPIO all settings + GPIO.cleanup() \ No newline at end of file diff --git a/scss/_common.scss b/scss/_common.scss index 68de83d..0265929 100644 --- a/scss/_common.scss +++ b/scss/_common.scss @@ -1,5 +1,5 @@ html, body { - font:14px $text; + font:0 $text normal; } body { text-align: center; @@ -17,6 +17,11 @@ body { p { font-size:14px; } + +a { + text-decoration: none; +} + h1 { font-size: 28px; } @@ -36,16 +41,20 @@ h6 { font-size:16px; } h1, h2, h3, h4, h5, h6 { + color: $darkblue; font-family: $headings; margin-bottom:20px; } + input { width:100%; border:0; padding:8px 4px; margin-bottom:10px; display: inline-block; + box-sizing: border-box; } + button { cursor: pointer; border:0; @@ -58,32 +67,107 @@ button { } } -.row { +header { + padding:20px; + margin:-20px -20px 20px; + box-sizing: border-box; + background-color: $rgba; + border-bottom:5px solid $grey; +} + +section { + padding:10px; margin-bottom:20px; + box-sizing: border-box; + border:1px dashed $blue; + @include border-radius(10px); +} + +.results { + margin-top:20px; + text-align: left; + .row { + width:100%; + font-size:0; + display: inline-block; + box-sizing: border-box; + color: $darkblue; + padding:10px 8px; + background-color:$lightblue; + border-bottom: 1px solid $grey; + &:hover { + @include opacity(0.8); + } + &:first-of-type { + @include border-radius(10px 10px 0 0); + } + &:last-of-type { + border-bottom-width: 0; + @include border-radius(0 0 10px 10px); + } + &.active { + color:$white; + background-color: $blue; + } + span { + font-size:14px; + margin-right:2%; + } + .status { + @include border-radius(100%); + height:14px; + width:14px; + display: inline-block; + &.off { + background-color:$grey; + } + &.on { + background-color: $blue; + } + } + } } .block { padding:20px; + width: 32%; + margin:0 2% 20px 0; + font-size:14px; box-sizing: border-box; - width: percentage(1/3); + vertical-align: top; display: inline-block; - background-color:rgba(255,255,255, 0.7); + background-color:$rgba; + border:5px solid $grey; + @include border-radius(10px); @media screen and (max-width:$middle_max) and (min-width:$small_min) { width:80%; + margin-right:0; } @media screen and (max-width:$small_max) { width:100%; + margin-right:0; + } + &:last-of-type { + margin-right:0; } } -.border { - border:1px solid $grey; - @include border-radius(10px); - &.thick { - border-width:5px; +.fields { + width:100%; + font-size:0; + display: inline-block; + input[name="city"] { + width:30%; + border-right:2px solid $grey; + @include border-radius(5px 0 0 5px); + } + input[name="street"] { + width:40%; + border-right:2px solid $grey; } - &.dotted { - border-style:dotted; + input[name="house"] { + width:30%; + @include border-radius(0 5px 5px 0); } } diff --git a/scss/_variables.scss b/scss/_variables.scss index 8d733c0..48b6c88 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -3,9 +3,10 @@ $headings: Impact, Charcoal, sans-serif; $white: #FCFFF5; $grey: #D1DBBD; -$lightblue: #91AA9D; +$lightblue: #94BFCA; $blue: #3E606F; $darkblue: #193441; +$rgba: rgba(255,255,255, 0.7); $large_min: 1080px; $large_max: 1081px;