SmartArduino / WiFiMCU

WiFiCMU-v0.9.8-pre release
https://github.com/SmartArduino/WiFiMCU
123 stars 65 forks source link

loadstring on net socket event #10

Closed adampolar closed 8 years ago

adampolar commented 8 years ago

I'm new to EMW3165 and lua but trying to get up to speed. I've recently tried to make a telnet server that passes it's input straight to the lua interpreter (using loadstring) and then passes the output back to the client, this is one of the main examples on NodeMCU but I couldn't find it on WiFiMCU anywhere. the code i have so far is as follows(it is called by a dofile call in my init.lua);

inputCommand = "";
ace = "";
skt = net.new(net.TCP,net.SERVER)
net.on(skt, "accept", function(clt,ip,port) end)
net.on(skt,"receive",
    function(clt,data)
        print(data);
        if string.find(data, "\n") then
            temp = inputCommand;
            print(temp);
            assert(loadstring(temp))()
            net.send(clt, "OK");
            ace = inputCommand;
            inputCommand="";
        else
            inputCommand = inputCommand .. data;
        end
    end)

net.start(skt,23)

The issue is that this crashes the emw3165 when a command is sent (">>>>>>>>>[" is printed, then the device restarts). In fact just doing the following

skt = net.new(net.TCP,net.SERVER)
net.on(skt, "accept", function(clt,ip,port) end)
net.on(skt,"receive",
    function(clt,data)
            assert(loadstring("return 1+1"))()
    end)

net.start(skt,23)

is enough to make it crash? However calling loadstring over serial works fine. Why does this not work?

Thanks,

Adam

adampolar commented 8 years ago

Sorry, I didn't realise I had an old version of the firmware. I have upgraded from 0.9.6 to 0.9.8 and it works. Thanks!