Functional garage_door_opener example.
This commit is contained in:
parent
b88e0e382b
commit
2ae0a573d9
BIN
http/apple-touch-icon.png
Normal file
BIN
http/apple-touch-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@ -33,7 +33,7 @@ body {
|
||||
-webkit-box-shadow: inset 0 -1px 1px rgba(255, 255, 255, .15);
|
||||
-moz-box-shadow: inset 0 -1px 1px rgba(255, 255, 255, .15);
|
||||
box-shadow: inset 0 -1px 1px rgba(255, 255, 255, .15);
|
||||
font-family: 'Pacifico', Arial, sans-serif;
|
||||
font-family: 'Khand', sans-serif;
|
||||
line-height: 1;
|
||||
text-shadow: 0 -1px 1px rgba(175, 49, 95, .7);
|
||||
-webkit-transition: background-color .2s ease-in-out, -webkit-transform .1s ease-in-out;
|
||||
20
http/garage_door_opener.html
Normal file
20
http/garage_door_opener.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="garage_door_opener.css">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<meta charset="UTF-8">
|
||||
<title>Garage Remote</title>
|
||||
</head>
|
||||
<body bgcolor="#777777">
|
||||
<link href='http://fonts.googleapis.com/css?family=Khand:700' rel='stylesheet' type='text/css'>
|
||||
<a href="garage_door_opener.lua?door=1" class="button">
|
||||
<span>Door 1</span>
|
||||
</a>
|
||||
<a href="garage_door_opener.lua?door=2" class="button">
|
||||
<span>Door 2</span>
|
||||
</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
30
http/garage_door_opener.lua
Normal file
30
http/garage_door_opener.lua
Normal file
@ -0,0 +1,30 @@
|
||||
-- garage_door_opener.lua
|
||||
-- Part of nodemcu-httpserver, example.
|
||||
-- Author: Marcos Kirsch
|
||||
|
||||
local function pushTheButton(connection, pin)
|
||||
|
||||
-- Redirect the user back to the static page where the garage door opener buttons are.
|
||||
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\Cache-Control: private, no-store\r\n\r\n")
|
||||
connection:send('<script type="text/javascript">window.location.replace("/garage_door_opener.html");</script>')
|
||||
|
||||
-- push the button!
|
||||
-- Note that the relays connected to the garage door opener are wired
|
||||
-- to close when the GPIO pin is low. This way they don't activate when
|
||||
-- the chip is reset and the GPIO pins are in input mode.
|
||||
gpio.write(pin, gpio.LOW)
|
||||
gpio.mode(pin, gpio.OUTPUT)
|
||||
gpio.write(pin, gpio.LOW)
|
||||
tmr.delay(300000) -- in microseconds
|
||||
gpio.write(pin, gpio.HIGH)
|
||||
gpio.mode(pin, gpio.INPUT)
|
||||
|
||||
end
|
||||
|
||||
return function (connection, args)
|
||||
print('Garage door button was pressed!')
|
||||
print('Door', args.door)
|
||||
if args.door == "1" then pushTheButton(connection, 3) -- GPIO0
|
||||
elseif args.door == "2" then pushTheButton(connection, 4) -- GPIO2
|
||||
else dofile("httpserver-error.lc")(connection, {code = 400}) end -- Bad Request
|
||||
end
|
||||
@ -1 +0,0 @@
|
||||
<script type="text/javascript">window.location = "garage_door_opener.html"</script>
|
||||
@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="button.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>Garage Remote</title>
|
||||
</head>
|
||||
<body bgcolor="#777777">
|
||||
<link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
|
||||
<a href="#" class="button">
|
||||
<span>¡Bienvenido!</span>
|
||||
</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user