Created
February 29, 2016 20:43
-
-
Save affix/b71e26a5f0fde1178a3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wifi.setmode(wifi.STATION) | |
wifi.sta.config("SSID","PASSWORD") | |
print(wifi.sta.getip()) | |
outpin=4 -- Connect Relay trigger to pin D4 | |
-- Relay powered from 3V pin | |
srv=net.createServer(net.TCP) srv:listen(80,function(conn) | |
conn:on("receive",function(conn,payload) | |
function ctrlpower() | |
pwm.close(outpin) | |
gpio.mode(outpin,gpio.OUTPUT) | |
dotaz=string.sub(payload,kdesi[2]+1,#payload) | |
if dotaz=="OFF" | |
then | |
gpio.write(outpin,gpio.HIGH) | |
return | |
end | |
if dotaz=="ON" | |
then | |
gpio.write(outpin,gpio.LOW) | |
return | |
end | |
if dotaz=="FLASH" | |
then | |
pwm.setup(outpin,2,512)pwm.start(outpin) | |
return | |
end | |
pwm.setup(outpin,1000,dotaz*10) | |
pwm.start(outpin) | |
end | |
conn:send('HTTP/1.1 200 OK\n\n') | |
conn:send('<!DOCTYPE HTML>\n') | |
conn:send('<html>\n') | |
conn:send('<head><meta content="text/html; charset=utf-8">\n') | |
conn:send('<title>LUAMP</title></head>\n') | |
conn:send("<body><h1>LUAMP</h1>\n") | |
conn:send('<form action="" method="POST">\n') | |
conn:send('<input type="submit" name="pwmi" value="ON"><br><br>\n') | |
conn:send('<input type="submit" name="pwmi" value="OFF"><br><br>\n') | |
conn:send('<input type="submit" name="pwmi" value="FLASH"></form>\n') | |
conn:send('</body></html>\n') | |
conn:on("sent",function(conn) conn:close() end) | |
--parse position POST value from header | |
kdesi={string.find(payload,"pwmi=")} | |
--If POST value exist, set LED power | |
if kdesi[2]~=nil then ctrlpower()end | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment