2

I am sending data between two ESP8266 modules via TCP connection every 10 seconds in Lua:

string="abc"
cl=net.createConnection(net.TCP, 0)
cl:connect(80,"192.168.4.1")
tmr.alarm(2, 10000, 1, function()
cl.send("The string variable is: "..string.."")end)

However, if I want to send string variable as in the code above, I keep getting error message:

PANIC: unprotected error in call to Lua API (init.lua:26: bad argument #1 to 'send' (net.socket expected, got string))
PANIC: unprotected error in call to Lua API (bad argument #1 (Server/Socket expected))

It works for me just when sending numerical variables. Is there any way to send string variable?

Thanks, Kaki

1 Answer 1

3

The error message is that the first argument to send call is expected to be the socket, not a string.

You should be using cl:send("value") instead of cl.send("value") as the first one is really a short form for cl.send(cl, "value").

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for a clear answer, it helped me a lot. Now it works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.