-->
Page 1 of 1

Is TELNET the right way to go?

PostPosted: Wed Jun 21, 2017 11:09 am
by PhilTilson
I may be missing something here, but if I am, I'm sure someone will put me right!

I want to monitor the progress of a program running on the ESP over a considerable period. Because the device is remotely mounted, I can't use the serial port, so it has to be done via wifi.

I guess I could write the output to the browser screen, but that seems to fill up the page buffer quite quickly.

So I had in mind to use telnet to connect to my PC and use the msdos echo command to append the diagnostic information to a file, which could keep growing as long as needed.

I have tried to follow the telnet commands but, although I can connect to the telnet server, the login seems to fail and I get random bits of messages returned from the server (which I am viewing on a serial port, as this is being done on another ESP for testing).

Does anyone have any good examples of using telnet? There don't seem to be any on Mike's examples pages, nor in the link to additional example programs.

All suggestions appreciated!

Phil

Re: Is TELNET the right way to go?

PostPosted: Wed Jun 21, 2017 4:12 pm
by Electroguard
I don't know the best way, just how I'd try to tackle it...

Back in V2 days I created an embedded scrollable I-Frame window using the standard html stuff for showing incoming udp messages history.

Nowadays there are websockets, so a better way would be to declare a variable at the start for displaying your changing data in an enlarged textbox.

Perhaps have the textbox variable default to holding the latest data, then each time new data becomes available it causes the previous data to be saved with an incremental name/number to flash, then a couple of forward / backward nav buttons could allow stepping back through loading previously saved flash data into the textbox display window.
Basically create your own non-volatile log file which you can step through in the browsers textbox window when needed.

Gives you the option of remotely instigating an automatic stepping through of all saved data entries and udp streaming them out to eg:cicciocb's udp debugger utility on computer.

Re: Is TELNET the right way to go?

PostPosted: Thu Jun 22, 2017 4:32 pm
by PhilTilson
I've had a bit more success!

Three things seem to be essential: the first is to allow delays for the Telnet server to respond; the second is to terminate all calls to telnet.client.write() with a chr(13) and the third is always to follow a .write with a .read.str, otherwise the buffer seems to fill up.

So something like this:

Code: Select allif telnet.client.connect("192.168.4.1", 12345) = 0 then
   serialprintln "Telnet access failed!"
   end
end if

delay 1000
genin$ = telnet.client.read.str()
delay 500
x = telnet.client.write("ESP" & chr(13))   'username
delay 500
genin$ = telnet.client.read.str()
delay 500
x = telnet.client.write("password" & chr(13))   'password
delay 500
genin$ = telnet.client.read.str()

seems to work quite well.

Because telnet is an insecure protocol, I have taken the precaution of using a non-standard port, rather than 23, just in case.

To write to the log, I use:

Code: Select allx = telnet.client.write("echo Now logged in >> log.txt" & chr(13))
delay 500
genin$ = telnet.client.read.str()

which seems to work reliably. Still a few glitches, but it's simple!

Phil