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

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
Kaki
  • 93
  • 1
  • 7

1 Answers1

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").

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56