-- Wemos Relay.lua -- John Longworth December 2016 -- For use with WeMos single relay shield local SSID = "xxxxxxxx" -- Enter your SSID local pwd = "xxxxxxxx" -- Enter your password wifi.setmode(wifi.STATIONAP) wifi.sta.config(SSID,pwd) wifi.sta.autoconnect(1) wifi.sta.setip({ip="192.168.0.50"}) -- change this to your reqirements ip = wifi.sta.getip() print("Key this IP address "..ip.." into a browser") local pin = 1 --Wemos relay connected to D1 (GPIO5) gpio.mode(pin, gpio.OUTPUT) --Set D1 as an 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 = "" .."WeMos ESP8266 Relay Control
" .."

WeMos Relay Control

" .."

Switch  " .." 

" .."

John Longworth - December 2016

" .."
" local _on,_off = "","" if(_GET.pin == "ON1")then gpio.write(pin, gpio.HIGH); elseif(_GET.pin == "OFF1")then gpio.write(pin, gpio.LOW); end client:send(buf) client:close() end) end)