Modify for more standard hardware Wemos D1 Pro and its relay shield.

This commit is contained in:
Marcos Kirsch 2017-02-04 23:18:16 -06:00
parent cc2173e334
commit 6ab6fcfff1

View File

@ -5,15 +5,14 @@
local function pushTheButton(connection, pin) local function pushTheButton(connection, pin)
-- push the button! -- push the button!
-- Note that the relays connected to the garage door opener are wired -- The hardware in this case is a Wemos D1 Pro with two relay shields.
-- to close when the GPIO pin is low. This way they don't activate when -- The first relay is controlled with D1.
-- the chip is reset and the GPIO pins are in input mode. -- The second one was modified to be controlled with D2.
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.write(pin, gpio.HIGH)
gpio.mode(pin, gpio.INPUT) gpio.mode(pin, gpio.OUTPUT, gpio.FLOAT)
tmr.delay(300000) -- in microseconds
gpio.mode(pin, gpio.INPUT, gpio.FLOAT)
gpio.write(pin, gpio.LOW)
-- Send back JSON response. -- Send back JSON response.
connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n") connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
@ -23,8 +22,8 @@ end
return function (connection, req, args) return function (connection, req, args)
print('Garage door button was pressed!', args.door) print('Garage door button was pressed!', args.door)
if args.door == "1" then pushTheButton(connection, 1) -- GPIO1 if args.door == "1" then pushTheButton(connection, 1)
elseif args.door == "2" then pushTheButton(connection, 2) -- GPIO2 elseif args.door == "2" then pushTheButton(connection, 2)
else else
connection:send("HTTP/1.0 400 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n") connection:send("HTTP/1.0 400 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
connection:send('{"error":-1, "message":"Bad door"}') connection:send('{"error":-1, "message":"Bad door"}')