garage.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. print('Welcome to GARAGE')
  2. print(' Created by Marcos Kirsch')
  3. require "webServer"
  4. pinGarage = 4 -- GPIO2
  5. clientTimeoutInSeconds = 10
  6. port = 80
  7. -- Prepare pins
  8. function preparePin(pin)
  9. -- Pins start out configured for input, and the relay has a pulldown resistor
  10. -- in order to prevent from activating on reset. Makes ure to set pin to low
  11. -- BEFORE setting to output, less the relay see it as a toggle.
  12. gpio.write(pin, gpio.LOW)
  13. gpio.mode(pin, gpio.OUTPUT)
  14. end
  15. preparePin(pinGarage)
  16. -- This functions emulates pushing the button for opening/closing the garage door.
  17. function pushTheButton(pin)
  18. gpio.write(pin, gpio.HIGH)
  19. delayInMicroseconds = 500000 -- half a second should be enough
  20. tmr.delay(delayInMicroseconds)
  21. gpio.write(pin, gpio.LOW)
  22. end
  23. -- Read the "garage remote" HTML that is served
  24. --file.open("remote.html", "r")
  25. --html = file.read()
  26. webServer.start(port, clientTimeoutInSeconds)
  27. --
  28. --server = net.createServer(net.TCP, clientTimeoutInSeconds) server:listen(port, function(connection)
  29. -- --if server == nil
  30. -- -- print("Server listening on port " .. port)
  31. -- -- return
  32. -- --end
  33. -- connection:on("receive",function(connection,payload)
  34. -- print(payload) -- for debugging only
  35. -- --generates HTML web site
  36. -- connection:send(httpHeader200 .. html)
  37. --
  38. -- pushTheButton(pinGarage)
  39. -- connection:on("sent",function(connection) connection:close() end)
  40. -- end)
  41. --end)