Created
September 21, 2015 07:20
-
-
Save unicore32/4c19b7f3a5b1a9099731 to your computer and use it in GitHub Desktop.
ESP-WROOM-02でLチカ
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
-- Pin config | |
gpio.mode(5, gpio.OUTPUT) -- GPIO14 -> OUTPUT | |
-- Wi-Fi config | |
wifi_cfg={} | |
wifi_cfg.ssid="ESP8266_TEST01" | |
wifi_cfg.pwd="password" | |
wifi.ap.config(wifi_cfg) | |
-- IP Config | |
ip_cfg={} | |
ip_cfg.ip="192.168.1.1" | |
ip_cfg.netmask="255.255.255.0" | |
ip_cfg.gateway="192.168.1.1" | |
wifi.ap.setip(ip_cfg) | |
-- Enable Access Point | |
wifi.setmode(wifi.SOFTAP) | |
collectgarbage(); | |
srv=net.createServer(net.TCP) | |
srv:listen(80,function(conn) | |
conn:on("receive", function(client,request) | |
local buf = ""; | |
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); | |
if(method == nil)then | |
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); | |
end | |
local _GET = {} | |
if (vars ~= nil)then | |
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do | |
_GET[k] = v | |
end | |
end | |
buf = "<title> ESP8266 Web Server</title>"; | |
buf = buf.."<h1> ESP8266 Web Server</h1>"; | |
buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>"; | |
if(_GET.pin == "ON1")then | |
gpio.write(5, gpio.HIGH); | |
elseif(_GET.pin == "OFF1")then | |
gpio.write(5, gpio.LOW); | |
end | |
client:send(buf); | |
client:close(); | |
collectgarbage(); | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment