i want to make a esp with a button and a relais
but want to make it so that
you can push the button and the relais go's on or off
and you can get the relais on or off with domoticz
so that if the wifi go's down you can still power te relais manual
and afcourse its easy
you can insert it behind a switch outlet
Greetz BigDog
local switch esp
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 320
- Joined: 15 Apr 2015, 14:17
Re: local switch esp
With a button you mean a physical switch / button?BigDog wrote:i want to make a esp with a button and a relais
but want to make it so that
you can push the button and the relais go's on or off
and you can get the relais on or off with domoticz
so that if the wifi go's down you can still power te relais manual
and afcourse its easy
you can insert it behind a switch outlet
Greetz BigDog
Currently that's not supported, but if you modify the switch code, you can add a digitalWrite function to actuate the relays.
Re: local switch esp
I have this code on init.lua(NodeMCU) but if you can put on easy better,
my must important feature are the off delay so when i click to open the gate it change ON but after " tmr.delay(500000)" delay it return OFF, the gate has a push button so need to be like this.
my must important feature are the off delay so when i click to open the gate it change ON but after " tmr.delay(500000)" delay it return OFF, the gate has a push button so need to be like this.
Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","pass")
wifi.sta.connect()
wifi.sta.setip({ip="10.55.10.xx",netmask="255.255.255.0",gateway="10.55.10.xx"})
print("ESP8266 mode is: " .. wifi.getmode())
led1 = 4
led2 = 6
led3 = 1
led4 = 2
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
gpio.mode(led3, gpio.OUTPUT)
gpio.mode(led4, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(5555,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>Relé WIFI </h1>";
buf = buf.."<p>PORTÃO <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
buf = buf.."<p>LUZES 1 <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
buf = buf.."<p>LUZES 2 <a href=\"?pin=ON3\"><button>ON</button></a> <a href=\"?pin=OFF3\"><button>OFF</button></a></p>";
buf = buf.."<p>LUZES 3 <a href=\"?pin=ON4\"><button>ON</button></a> <a href=\"?pin=OFF4\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "OFF1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "ON1")then
gpio.write(led1, gpio.LOW);
if(_GET.pin == "ON1")then
tmr.delay(500000);
gpio.write(led1, gpio.HIGH);
end
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.LOW);
elseif(_GET.pin == "OFF3")then
gpio.write(led3, gpio.HIGH);
elseif(_GET.pin == "ON3")then
gpio.write(led3, gpio.LOW);
elseif(_GET.pin == "OFF4")then
gpio.write(led4, gpio.HIGH);
elseif(_GET.pin == "ON4")then
gpio.write(led4, gpio.LOW);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
Re: local switch esp
that would also be a very nice addon
didnt know that it wasnt supported yet becose i must wait a while before the esp's araive from china
i think they are now on a airplane somewhere
Greetz BigDog
didnt know that it wasnt supported yet becose i must wait a while before the esp's araive from china
i think they are now on a airplane somewhere
Greetz BigDog
Re: local switch esp
maluko wrote:I have this code on init.lua(NodeMCU) but if you can put on easy better,
my must important feature are the off delay so when i click to open the gate it change ON but after " tmr.delay(500000)" delay it return OFF, the gate has a push button so need to be like this.
Code: Select all
wifi.setmode(wifi.STATION) wifi.sta.config("ssid","pass") wifi.sta.connect() wifi.sta.setip({ip="10.55.10.xx",netmask="255.255.255.0",gateway="10.55.10.xx"}) print("ESP8266 mode is: " .. wifi.getmode()) led1 = 4 led2 = 6 led3 = 1 led4 = 2 gpio.mode(led1, gpio.OUTPUT) gpio.mode(led2, gpio.OUTPUT) gpio.mode(led3, gpio.OUTPUT) gpio.mode(led4, gpio.OUTPUT) srv=net.createServer(net.TCP) srv:listen(5555,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>Relé WIFI </h1>"; buf = buf.."<p>PORTÃO <a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>"; buf = buf.."<p>LUZES 1 <a href=\"?pin=ON2\"><button>ON</button></a> <a href=\"?pin=OFF2\"><button>OFF</button></a></p>"; buf = buf.."<p>LUZES 2 <a href=\"?pin=ON3\"><button>ON</button></a> <a href=\"?pin=OFF3\"><button>OFF</button></a></p>"; buf = buf.."<p>LUZES 3 <a href=\"?pin=ON4\"><button>ON</button></a> <a href=\"?pin=OFF4\"><button>OFF</button></a></p>"; local _on,_off = "","" if(_GET.pin == "OFF1")then gpio.write(led1, gpio.HIGH); elseif(_GET.pin == "ON1")then gpio.write(led1, gpio.LOW); if(_GET.pin == "ON1")then tmr.delay(500000); gpio.write(led1, gpio.HIGH); end elseif(_GET.pin == "OFF2")then gpio.write(led2, gpio.HIGH); elseif(_GET.pin == "ON2")then gpio.write(led2, gpio.LOW); elseif(_GET.pin == "OFF3")then gpio.write(led3, gpio.HIGH); elseif(_GET.pin == "ON3")then gpio.write(led3, gpio.LOW); elseif(_GET.pin == "OFF4")then gpio.write(led4, gpio.HIGH); elseif(_GET.pin == "ON4")then gpio.write(led4, gpio.LOW); end client:send(buf); client:close(); collectgarbage(); end) end)
How about add a delay on switch output to not have other software do this, because dont have trust on comunication by net.
For open gate this is a preciose feature, need only a dry contact.
Who is online
Users browsing this forum: No registered users and 4 guests