- Mon Nov 24, 2014 9:06 am
#3226
Signed in - and I have an IP address. I thought I'd give the TCP listener a shot.
I set this up..
l1="0\n"
sv=net.createServer(net.TCP, 90) -- 30s time out for a inactive client
sv:listen(4000,function(c)
c:on("receive", function(sck, pl)
print(pl)
if (pl=="GO1\n") then c:send(l1)
elseif pl=="YES1\n" then l1="1\n" c:send("OK\n")
elseif pl=="NO1\n" then l1="0\n" c:send("OK\n")
else c:send("0\n")
end
end)
end)
This worked very well - and quickly - I could use my Android App to simulate turning a light on and off - and the status request "GO1\n showed me the state of the string (which in reality would be a LED or whatever.
Of course that's too small to be of real use.. so I tried to make it bigger - after resetting the board..
Here is the sequence from power up...This time for 4 virtual outputs..
NodeMcu 0.9.2 build 20141124 powered by Lua 5.1.4
>
Loading functions
Connecting
Connected to.loft-east.IP:.192.168.0.22
OK
> l1="0\n"
> l2="0\n"
> l3="0\n"
> l4="0\n"
> sv=net.createServer(net.TCP, 90) -- 30s time out for a inactive client
> sv:listen(4000,function(c)
>>
>> c:on("receive", function(sck, pl)
>> print(pl)
>> if (pl=="GO1\n") then c:send(l1)
>> elseif pl=="GO2\n" then c:send(l2)
>> elseif pl=="GO3\n" then c:send(l3)
>> elseif pl=="GO4\n" then c:send(l4)
>> elseif pl=="YES1\n" then l1="1\n" c:send("OK\n")
>> elseif pl=="NO1\n" then l1="0\n" c:send("OK\n")
>> elseif pl=="YES2\n" then l2="1\n" c:send("OK\n")
>> elseif pl=="NO2\n" then l2="0\n" c:send("OK\n")
>> elseif pl=="YES3\n" then l3="1\n" c:send("OK\n")
>> elseif pl=="NO3\n" then l3="0\n" c:send("OK\n")
>> elseif pl=="YES4\n" then l4="1\n" c:send("OK\n")
c_GORSvf.SzfJSzfn
Pete's LUA module 0.1
NodeMcu 0.9.2 build 20141124 powered by Lua 5.1.4
>
Loading functions
Connecting
Connected to.loft-east.IP:.192.168.0.22
OK
This is a trivial example - yet as you can see, the interpreter is giving up before the final command - and once again rebooting.
. Here's what I TRIED to put in.
l1="0\n"
l2="0\n"
l3="0\n"
l4="0\n"
sv=net.createServer(net.TCP, 90) -- 30s time out for a inactive client
sv:listen(4000,function(c)
c:on("receive", function(sck, pl)
print(pl)
if (pl=="GO1\n") then c:send(l1)
elseif pl=="GO2\n" then c:send(l2)
elseif pl=="GO3\n" then c:send(l3)
elseif pl=="GO4\n" then c:send(l4)
elseif pl=="YES1\n" then l1="1\n" c:send("OK\n")
elseif pl=="NO1\n" then l1="0\n" c:send("OK\n")
elseif pl=="YES2\n" then l2="1\n" c:send("OK\n")
elseif pl=="NO2\n" then l2="0\n" c:send("OK\n")
elseif pl=="YES3\n" then l3="1\n" c:send("OK\n")
elseif pl=="NO3\n" then l3="0\n" c:send("OK\n")
elseif pl=="YES4\n" then l4="1\n" c:send("OK\n")
elseif pl=="NO4\n" then l4="0\n" c:send("OK\n")
else c:send("0\n")
end
end)
end)