0% found this document useful (0 votes)
46 views1 page

Scrip

The document configures a WiFi access point and creates an HTTP server on port 80. The server listens for requests and returns an HTML page with a form to turn a GPIO pin on or off depending on the submitted value. When a request is received, it checks the GET parameters and sets the pin high or low accordingly before sending the response.

Uploaded by

Mijin28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views1 page

Scrip

The document configures a WiFi access point and creates an HTTP server on port 80. The server listens for requests and returns an HTML page with a form to turn a GPIO pin on or off depending on the submitted value. When a request is received, it checks the GET parameters and sets the pin high or low accordingly before sending the response.

Uploaded by

Mijin28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

wifi.setmode(wifi.

SOFTAP)
wifi.ap.config({ssid="test",pwd="12345678"})
gpio.mode(1, gpio.OUTPUT)
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 = buf.."<h1> Hello, NodeMcu.</h1><form src=\"/\">Turn PIN1 <select name=\"pin\"
onchange=\"form.submit()\">"
local _on,_off = "",""
if(_GET.pin == "ON")then
_on = " selected=true"
gpio.write(1, gpio.HIGH)
elseif(_GET.pin == "OFF")then
_off = " selected=\"true\""
gpio.write(1, gpio.LOW)
end
buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>"
client:send(buf)
end)
conn:on("sent", function (c) c:close() end)
end)

file:///C|/Users/CompuXpert/Documents/CELU-PLC/scrip.txt[13/06/2017 19:17:54]

You might also like