Support for Lua scripts

This commit is contained in:
Marcos Kirsch 2015-02-15 16:46:29 -06:00
parent 94c90c39ab
commit fa2e85dbb0
5 changed files with 66 additions and 21 deletions

View File

@ -1,21 +0,0 @@
# GARAGE
This project uses an [ESP2866](http://www.esp8266.com) with [nodeMCU](http://nodemcu.com/index_cn.html) firmware to control a garage door.
Controlling a garage door from a microcontroller is easy. All you need to do is emulate a push button with a relay and wire it in parallel with the real push button on your garage door motor.
# Hardware
I bought a [kit from eBay](http://www.ebay.com/itm/281519483801?_trksid=p2059210.m2749.l2649) that came with most of what I needed:
* A cheap CH430 USB to Serial TTL adapter with 3.3V logic
* A bunch of female to female jumper wires and jumpers
* A somewhat useful carrying board that makes access to GPIO pins impossible as soldered.
* AM1117 5V to 3.3V power supply with 800 mA capacity.
* Female USB cable
* ESP-01 board, which gives access to 2 GPIO pins.
Separately, I bought [2 relays](http://www.ebay.com/itm/2pcs-3V-Relay-High-Level-Driver-Module-optocouple-Relay-Moduele-for-Arduino-/141523155660?) that can handle way more voltage and current than I need, but are handy because I can drive them with 3.3V logic of the ESP2866.
# Open issues
* When the ESP2866 powers up, both GPIO pins are in input mode, which the relay reads as logic high. That's not good, as it would trigger a garage door opening! I need to invert the logic. What's the easiest and cheapest way to do this?

21
http/file_list.lua Normal file
View File

@ -0,0 +1,21 @@
local function sendHeader(connection)
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\Cache-Control: private, no-store\r\n\r\n")
end
local function sendFileList(connection)
connection:send("<ul>\n")
local l = file.list()
for name, size in pairs(l) do
connection:send(" <li>" .. name .. " (" .. size .. ")</li>\n")
end
connection:send("</ul>\n")
end
return function (connection, args)
sendHeader(connection)
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>A Lua script sample</title></head>')
connection:send('<body>')
connection:send('<h1>File Listing</h1>')
sendFileList(connection)
connection:send('</body></html>')
end

13
http/memory.lua Normal file
View File

@ -0,0 +1,13 @@
local function sendHeader(connection)
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\Cache-Control: private, no-store\r\n\r\n")
end
return function (connection, args)
sendHeader(connection)
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>A Lua script sample</title></head>')
connection:send('<body>')
connection:send('<h1>Memory Statistics</h1>')
connection:send('Heap: ' .. node.heap() .. ' bytes')
connection:send('Garbage collector use: ' .. collectgarbage("count") .. ' kilobytes')
connection:send('</body></html>')
end

27
http/node_info.lua Normal file
View File

@ -0,0 +1,27 @@
local function sendHeader(connection)
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\Cache-Control: private, no-store\r\n\r\n")
end
local function sendAttr(connection, attr, val)
connection:send("<li><b>".. attr .. ":</b> " .. val .. "<br></li>\n")
end
return function (connection, args)
collectgarbage()
sendHeader(connection)
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>A Lua script sample</title></head>')
connection:send('<body>')
connection:send('<h1>Node info</h1>')
majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
connection:send('<ul>Node info:')
sendAttr(connection, "majorVer" , majorVer)
sendAttr(connection, "devVer" , devVer)
sendAttr(connection, "chipid" , chipid)
sendAttr(connection, "flashid" , flashid)
sendAttr(connection, "flashsize" , flashsize)
sendAttr(connection, "flashmode" , flashmode)
sendAttr(connection, "flashspeed" , flashspeed)
sendAttr(connection, "node.heap()" , node.heap())
connection:send('</ul>')
connection:send('</body></html>')
end

5
http/redirect.html Normal file
View File

@ -0,0 +1,5 @@
<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>