A forum for everything that Kinda Works YouTube.com/ItKindaWorks
You are not logged in.
Pages: 1
So I've been working on these relays that have an ESP8266-01 onboard and can only find a lua code to control them. Most of the information that I've found is in Chinglish so I haven't been able to program a good INO code. It works great with the LUA code but I want to see if we can utilize MQTT with ItKindaWorks awesome OTA code and bells and whistles.
-- must switch to 9600 baud to control relay
uart.setup(0,9600,8,0,1)
-- join wifi
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","wifipassword")
-- print(wifi.sta.getip())
-- Lua web server
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>ESP8266 relay control</h1>";
buf = buf.."<p>Switch Relay 1<a href=\"?pin=ON1\"><button>ON</button></a> <a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
tmr.stop(0);
uart.write( 0, 0xA0,0x01,0x01,0xA2);
end
if(_GET.pin == "OFF1")then
tmr.stop(0);
uart.write( 0, 0xA0,0x01,0x00,0xA1);
end
client:send(buf);
client:close();
collectgarbage();
end)
end)
Offline
Those look like interesting little boards! Kind of weird that they use serial to talk to a dedicated driver chip though. It looks like you're not the only one around having some issues getting it to properly trigger the relay through arduino. I'd have to actually get one of these boards to test out though.
Definitely something to look into!
Creator of ItKindaWorks
Offline
I'd be happy to send you one.
Offline
Pages: 1