-->
Page 1 of 1

Telnet example issues: packages lost during frequent sends

PostPosted: Sat Dec 19, 2015 9:41 am
by linhz
It seem that for the telnet example posted on the nodeMCU.com official site does not work if I have several consecutive prints. Only the first line is sent, and it is actually sent without the end-of-line character.
I am using a custom build from http://nodemcu-build.com/ , and is running on ESP-01
NodeMCU custom build by frightanic.com
branch: master
commit: 432f698fd80e0ff90ea4f209b66c77d5105ea55a
SSL: false
modules: node,file,gpio,wifi,net,tmr,uart,ow,dht,rtctime,sntp
build built on: 2015-12-18 03:59
powered by Lua 5.1.4 on SDK 1.4.0

When I used it with an older 0.9.6 firmware I did not encounter this problem.
I inserted a UART write in the s_output(str) function for debugging and noticed that this function receives the contest string and the end-of-line character in two separate calls. This might be fine with default UART, but I think is quite unreasonable for redirected TCP communications??
Is this a problem with the nodeMCU net library or should I implement some sort of buffer and waiting mechanism for the telnet server myself??
Help appreciated!!

My telnet code:
Code: Select alls=net.createServer(net.TCP,180)
s:listen(23,function(c)
    function s_output(str)
      if(c~=nil) then
        c:send(str, function() uart.write(0,"*sent\n") end)
      end
      uart.write(0,"\n*rec:\n"..str)
    end
    node.output(s_output, 0)   
    -- re-direct output to function s_ouput.
    c:on("receive",function(c,l)
      node.input(l)           
    end)
    c:on("disconnection",function(c)
      node.output(nil)       
      --unregist redirect output function, output goes to serial
    end)
    print("Welcome to NodeMCU world.")
    print("Hello world 1")
    print("Hello world 2")
    print("Hello world 3")
end)


And on my laptop I wrote a node.js script to show what is received (only the first line):
Connected
From Socket:192.168.0.105 : 23
Welcome to NodeMCU world.

The same issue is there for Win7 telnet and also an android telnet app.

Re: Telnet example issues: packages lost during frequent sen

PostPosted: Mon Jan 25, 2016 2:53 am
by davdav
Hi,

I have a similar problem like yours. Did you find a solution or an explanation to the problem?

I have to send 300 byte to the server. However if I call the "send" method and send all the 300 bytes, it returns an error.

If I split the data into two instructions "send", it send the first 150 byte plus an end of line which in reality is not present in the original data.

Has someone a solution or is it a bug of SDK 1.4.0. I'm using nodemcu custom build


NodeMCU custom build by frightanic.com
branch: master
commit: 93421f2702fb02ce169f82f96be7f2a8865511e1
SSL: false
modules: node,wifi,net,uart
build built on: 2015-12-23 13:47
powered by Lua 5.1.4 on SDK 1.4.0
lua: cannot open init.lua

Thanks.

Re: Telnet example issues: packages lost during frequent sen

PostPosted: Mon Jan 25, 2016 2:43 pm
by devsaurus
linhz wrote:It seem that for the telnet example posted on the nodeMCU.com official site does not work if I have several consecutive prints.
When I used it with an older 0.9.6 firmware I did not encounter this problem.

Correct. Dispatching several send in a row worked with older versions because the SDK back then buffered them (at least a couple). This 'feature' was removed from Espressif's libraries and consecutive send commands now lead to data loss. Unfortunately, there are no countermeasures in the NodeMCU firmware. You need to account for this in the Lua scripts.

The telnet.lua example has been revised recently. Please use https://github.com/nodemcu/nodemcu-firmware/blob/dev/lua_examples/telnet.lua as reference and update your code accordingly.

Re: Telnet example issues: packages lost during frequent sen

PostPosted: Tue Jan 26, 2016 11:37 am
by davdav
Hi devsaurus,

Thanks for reply and explanation. Since I use the ESP as a terminal and I don't write any LUA inside the module,but I send the command throught the UART port, how can I send the data correclty?

This is my code (what I send to UART of the ESP module)

conn=net.createConnection(net.TCP, false)
conn:on("connection", function(conn) print("connect") end)
conn:on("disconnection", function(conn) print("disconnect") end)
conn:on("sent", function(conn) print("sent") end)


conn:connect(11111, "XXX.YYY.ZZZ.KKK")

Once I receive the "connect" callback I send

conn:send("<first 150 bytes of the 300 bytes>")

Wait for the "sent" callback and send the second part

conn:send("<second 150 bytes of the 300 bytes>")


Is it the right method?
However, I checked that server receive both part, but at the end of the first one the server
reconnizes an end of line (which is not present in the original data to send) and therefore the data are not interpreted correctly.

Do you know if the function "send" append an "end of line" at the end of the string?

Thanks