wifi.setmode(wifi.STATION) wifi.sta.config("YOUR WIFI","YOUR PASSSWORD") wifi.sta.setip({ip="192.168.0.106",netmask="255.255.255.0",gateway="192.168.0.1"}) //sets static IP print(wifi.sta.getip()) led2= 0 // IO index = 0, which is pin 16 DeviceType="SmartPlug" Chip = "1234" IP = (wifi.sta.getip()) status=nil print (DeviceType) print (Chip) print (IP) gpio.mode(led2, gpio.OUTPUT) srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(client,request) local mes = ""; 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 if (_GET.Meth=="A") then ChipId=(_GET.ChipId); if (ChipId==Chip) then if(_GET.pin == "ON")then gpio.write(led2,gpio.HIGH); elseif(_GET.pin == "OFF")then gpio.write(led2,gpio.LOW); end status = gpio.read(led2); if (status == 0) then mes = mes.. "

UIT

"; elseif (status == 1) then mes = mes.. "

AAN

"; end elseif (ChipId~=Chip) then mes = "ERROR:DEVICE"; end elseif (_GET.Meth==nil) then mes = mes.."

ESP8266 Web Server

"; mes = mes.."

GPIO  

"; local _on,_off = "","" if(_GET.pin == "ON")then gpio.write(led2,gpio.HIGH); elseif(_GET.pin == "OFF")then gpio.write(led2,gpio.LOW); end status = gpio.read(led2); if (status == 0) then mes = mes.. "

STATUS = UIT

"; elseif (status == 1) then mes = mes.. "

STATUS = AAN

"; end end client:send(mes); client:close(); collectgarbage(); end) end)