Modify Telnet Server API Sample

Hi,

I’m relatively new to NET+OS and am trying to modify the Telnet Server API Sample that came with the software.

The general structure of the sample is correct for my purposes except I need to remove the Welcome message and the login features to make it transfer data from telnet to serial without the need for any authentication.

Does anyone have any ideas on how to do this?

Thanks

I do not believe you can completely remove the authentication. The closest you can get is a username with no password. In root.c there are calls to NAsetSysAccess(). Add one whose second parameter is the name you want and set the third parameter to “”.

As far as the welcome messages are concerned, there are calls to TSSendString() in telnet.c. Find the ones you do not like and comment them out.

One thing to be careful of. There are (theoretically) two telnets. One is the sample project. The other is built into the BSP. Ensure the one in the BSP is disabled. Otherwise the two will conflict.

I have had done some digging and found some example code from maxstream that uses the select command in conjunction with serial ports. I have included a few excerpts from a file named ms_serial.c. I hope this code example helps.

Ok, so lets say I don’t base my project on the sample project given. How would I go about creating a program that would accept TCP input and output to the serial port? Something that boots up and starts working and doesnt need a login.

Thanks

Ok, now I am not sure what you are looking for exactly. I’ll make some assumptions and answer based on my assumptions.

I’ll assume you are developing using the ESP IDE.
There is a sample project entitled basic sample. That gives you something akin to a hello world project.

You’ll want to look at the sample project called sample serial driver. That might give you a taste of the serial port APIs. As far as the networking end. Digi NEt+OS follows the standard sockets paradigm. I’d create a socket. bind to INET_ANY (ip address meaning any client) and a port of your choice. Then listen and accept. Then recv. The API reference guide, that is included in the kit and in ESP provide the details of the APIs.

Once you have received some data, it can be written out to the serial port using the serial APIs.

Here’s a thread that talks about serial to ethernet data transfer, including a sample app that shows how it’s done:

http://www.digi.com/support/forum/viewthread_thread,1206_offset,20#4544

Also, you don’t want to use the telnet api for serial to ethernet transfers, not only because of authentication, but because a CR (0x0D) is required to send data from the Telnet connection to the serial port (it’s buffered until it sees the CR).

Thanks for the link, it helped a lot.

I’ve looked at the source code that is given and am using it as a guideline.

I’ve run into a problem with the select() function. As far as I’m aware, it is able to manage requests on sockets AND serial ports but so far I’ve only got it to work with sockets.

Here is part of my code pasted below:

while(1)
{
// Clear out old fd_sets
FD_ZERO(&read_set);

    FD_SET(serialFD, &read_set);
    FD_SET(sockFD, &read_set);
    
    retval = select(FD_SETSIZE, &read_set, (fd_set *) 0, (fd_set *) 0, &wait);
    
    if(retval <= 0) // A return value of 0 is a timeout, -1 is an error 
    {
    	if(retval < 0)
        printf("Error on select: %d

", getErrno());
else printf("Timeout
");
}
else
{
if(FD_ISSET(sockFD, &read_set))
{
printf("Ready to read from socket
");

			tx_thread_sleep(200);
		}
		if(FD_ISSET(serialFD, &read_set))
		{
			printf("Ready to read from serial

");
tx_thread_sleep(200);
}
}
}

Anyone have any ideas on why the socket works and the serial doesn’t? I am able to use write() and send() to write to the serial and socket, so I know that they both work.

Adamp - the code you show looks fine. I would make sure the thread you running it in has a priority of 16 (the serl monitor thread, which allows you to use the serial port with select, runs at 14).

After that, I would make sure data is actually being recieved on the particular serial port you’re watching.