From 65538efc1b1874a6279e5758a9214141c2315b7e Mon Sep 17 00:00:00 2001 From: Marcos Kirsch Date: Tue, 10 Mar 2015 22:14:10 -0500 Subject: [PATCH] Modified HTML to call lua script via javascript. Also embedded an image just for stress testing the server --- http/garage_door_opener.html | 50 ++++++++++++++++++++++++++++++++++-- http/garage_door_opener.lua | 20 ++++++++------- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/http/garage_door_opener.html b/http/garage_door_opener.html index 9071409..ca1a0a5 100644 --- a/http/garage_door_opener.html +++ b/http/garage_door_opener.html @@ -6,14 +6,60 @@ Garage Remote + - + Door 1 - + Door 2 +
Text goes here
+ diff --git a/http/garage_door_opener.lua b/http/garage_door_opener.lua index e2fd8ae..baca7d3 100644 --- a/http/garage_door_opener.lua +++ b/http/garage_door_opener.lua @@ -4,10 +4,6 @@ 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('') - -- 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 @@ -19,12 +15,18 @@ local function pushTheButton(connection, pin) gpio.write(pin, gpio.HIGH) gpio.mode(pin, gpio.INPUT) + -- Send back JSON response. + connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\Cache-Control: private, no-store\r\n\r\n") + connection:send('{"error":0, "message":"OK"}') + 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 + print('Garage door button was pressed!', args.door) + if args.door == "1" then pushTheButton(connection, 3) -- GPIO0 + elseif args.door == "2" then pushTheButton(connection, 4) -- GPIO2 + else + connection:send("HTTP/1.0 400 OK\r\nContent-Type: application/json\r\Cache-Control: private, no-store\r\n\r\n") + connection:send('{"error":-1, "message":"Bad door"}') + end end