Simple Telnet to Serial Converter - doesn't work..

Hello Forum,

I am trying to make run my arduino as a simple telnet to serial converter, using the Ethernet Shield. I get the messages from telnet to serial without problems, but the way back doesn't work as expected. It doesn't transmit the CR/LF in the end.
My target is to transmit a line (ending with CRLF) from telnet to serial, and the way back. Any Ideas how to do?

My Code:

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 178, 42 };
byte gateway[] = { 192, 168, 178, 1 };
byte subnet[] = { 255, 255, 255, 0 };

Server server(23);

void setup()
{ 
  Ethernet.begin(mac, ip, gateway, subnet); // initialize the ethernet device
  Serial.begin(9600); // initialize the serial device
  server.begin(); // start listening for clients
}

void loop()
{
  Client client = server.available();
  if (client) { Serial.write(client.read()); }
  
  if (Serial.available()) { server.print(char(Serial.read()));  }
}

The Problem is in this line:

  if (Serial.available()) { server.print(char(Serial.read()));  }

How can I make it also transmits the end of the line?

Thanks in advance,
Michael

Does the data from the serial line have a CR/LF at the end? You really shouldn't need anything else to handle the non-printing characters. Note that "telnet" is not involved here; Telnet is a protocol that has its own idiosyncrasies, including some funniness with line termination (CR/LF, etc.) You have a simple serial to "tcp raw" device, which should be fine as long as the program at the other end isn't too picky...

Mmmh, I should try if it works...
I like to connect an ELM322-Chip, what is a kind of Modem (unterstanding AT-Commands) for OBD2. Talking to this Converter worked fine, then I found an iPhone-App ("REV"), what sends commands via Port 10000 to an Ethernet Device.
I checked this output with netcat, and I saw a "ATZ" appearing :smiley:
So now I try to listen with my Arduino to this Port (23 is just for testing), and send via serial to the ELM.
If it's purely RAW, it should work, yes! Why the written line just appears when I press "ENTER"? I expected, it comes in the moment I press the key. But this might be the behaviour of telnet or the terminal software...

Thanks for this hint, I will write the result tonight! :slight_smile:

Why the written line just appears when I press "ENTER"?

Are you using the "Serial Monitor" window of the Arduino IDE as your terminal program? It does NOT send CR/LF at the end of the string when you hit enter!