Bryan
Published © GPL3+

Open your Gate with your Smartphone

Replace your gate's remote control with your smartphone and an ESP8266.

BeginnerProtip2 hours4,558
Open your Gate with your Smartphone

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Relay (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

NodeMCU firmware
NodeMCU firmware

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schema

Code

ESP8266 code

Lua
-------------------------------
-- wifi client config
wifi.setmode(wifi.STATION);
cfg={}
cfg.ssid="SSID"
cfg.pwd="PASSWORD"
cfg.ip="192.168.1.40"
cfg.netmask="255.255.255.0"
cfg.gateway="192.168.1.0"
wifi.sta.setip(cfg)
wifi.sta.connect()
-------------------------------

-------------------------------
-- GPIO config
relay_pin = 1
gpio.mode(relay_pin, gpio.OUTPUT)
-------------------------------

-------------------------------
-- TCP Server initialisation
srv=net.createServer(net.TCP)
--print("Server HTTP started")
srv:listen(80,function(conn)
    conn:on("receive", function(client,request)
    --print(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.."<a style='text-decoration: none;' href=\"?relay=ACTION\"><table width=100% height=50% border=1>"
        buf = buf.."<tr>"
        buf = buf.."<td style='text-align: center;'>"
        buf = buf.."<h1>ouvrir portail</h1>"
        buf = buf.."</td>"
        buf = buf.."</tr>"
        buf = buf.."</table></a>"
        local _on,_off = "",""
        if(_GET.relay == "ACTION")then
                gpio.write(relay_pin, gpio.LOW);
                tmr.delay(500000) --500 ms
                gpio.write(relay_pin, gpio.HIGH);
        end
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)

Credits

Bryan

Bryan

2 projects • 2 followers
architecte IT

Comments