Modify for more standard hardware Wemos D1 Pro and its relay shield.
This commit is contained in:
parent
cc2173e334
commit
6ab6fcfff1
@ -5,15 +5,14 @@
|
||||
local function pushTheButton(connection, pin)
|
||||
|
||||
-- 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
|
||||
-- The hardware in this case is a Wemos D1 Pro with two relay shields.
|
||||
-- The first relay is controlled with D1.
|
||||
-- The second one was modified to be controlled with D2.
|
||||
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.
|
||||
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)
|
||||
print('Garage door button was pressed!', args.door)
|
||||
if args.door == "1" then pushTheButton(connection, 1) -- GPIO1
|
||||
elseif args.door == "2" then pushTheButton(connection, 2) -- GPIO2
|
||||
if args.door == "1" then pushTheButton(connection, 1)
|
||||
elseif args.door == "2" then pushTheButton(connection, 2)
|
||||
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('{"error":-1, "message":"Bad door"}')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user