-->
Page 1 of 1

UDP server conditional

PostPosted: Tue Oct 18, 2016 2:08 pm
by renelima
I have this code
Code: Select allsrv:on("receive", function(s, data)
    print("received: " .. data)
    if(data == "teste")then
        print("fkdjsfsjdkfdsdfks")
    end
    s:send("echo: " .. data)
end)


I need to make a "IF" in the message that comes to activate a GPIO, how can I do this? Thus this not working.

Re: UDP server conditional

PostPosted: Wed Oct 19, 2016 8:52 am
by marcelstoer
renelima wrote:Thus this not working.


Why is it not working? The sketch looks very similar to what I posted at http://stackoverflow.com/a/36769999/131929 and was confirmed to work just fine. 'print("received: " .. data)' prints the value of the 'data' parameter so it should be easy to verify what value it has.

As per http://nodemcu.readthedocs.io/en/dev/en ... etsocketon the type of 'data' is string and in Lua '==' for strings will return true if contents of the strings are equal.