nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

ESP8266: Server code get node to restart on 3.0.0 on 2.2.1 it is working OK. #3416

Closed LDRunner355 closed 2 years ago

LDRunner355 commented 3 years ago

modules_config.zip

This server .lua code get node to restart on 3.0.0 up on connecting to server port On 2.2.1 it is working OK, no restart occure.

s=net.createServer(net.TCP)
s:listen(23,function(c)
   con_std = c
   function s_output(str)
      if(con_std~=nil)
         then
         con_std:send(" \r") 
         con_std:send(str)
      end
   end
   node.output(s_output, 0)
   c:on("receive",function(c,l)
    node.input(l)
   end)
   c:on("disconnection",function(c)
      con_std = nil
      node.output(nil)
   end)
   print(("Connected to Node. (%d mem free, %s)"):format(node.heap(), wifi.sta.getip()))
end)
nwf commented 2 years ago

When I run your code, the UART spews forth

> stdin:7: bad argument #1 to 'send' (string expected, got table)
stack traceback:
    [C]: in method 'send'
    stdin:7: in function 's_output'
    [C]: in ?

This is because the node.output() function now takes a pipe object. See