Arduino Nano ethernet-shield Telnet not receiving all bytes

i want to get an Arduino nano to interface with a Telnet Server. The Telnet is on my local network, and communication works partially.
I use the SPI and EthernetENC Library with this code. The shield on my nano is a ENC28J60 Ethernet Shield.
When i connect to my Host via Putty (Port 134), i get a time stamp (01.01.1900 06:39). Then i can send things and it will print on my Host.
If i connect with the Arduino, i just get “01.” the rest of the time stamp is lost. I can send things with my Arduino to the Host, and it will print successfully. So only the receiving part is the Problem.

#include <SPI.h>
#include <EthernetENC.h>




String luvmsg = "";


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 45, 177);

// Enter the IP address of the server you're connecting to:
IPAddress server(192, 168, 45, 135);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use port 10002):
EthernetClient client;

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

  // start the Ethernet connection:
  Ethernet.begin(mac, ip);

  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  while (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
    delay(500);
  }

  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 134)) {
    Serial.println("connected");
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  //client.print("*44*");

}

void loop() {
//  char p = client.peek();
 // if(p != -1){
 // Serial.print(p);}
  // if there are incoming bytes available
  // from the server, read them and print them:

  
  if (client.available()) {
    Serial.print(client.available());
    Serial.print(". Char: ");
    char  c = client.read();
    Serial.println(c);
    
  }else{

  // as long as there are bytes in the serial queue,
  // read them and send them out the socket if it's open:
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if(inChar == 'x'){
      Serial.println("stop");
      //client.stop();
      }
    if (client.connected()) {
      client.print(inChar);
    }
  }

/*
  if (client.available()){


    client.readBytes(buffer,500);
    client.flush();
    
    char c = client.read();
    if(index < 500)
    {
      buffer[index] = c;
      index++;
      Serial.println(index);
      buffer[index] = '\0';
    }
  }*/


  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while (true) {
      delay(1);
    }
  }
  }

}

Why does this if-Loop all of a sudden stop fetching the chars from the server?
One thin I have noticed:
I can see how many Chars it is really printing. As it turns out, it’s not only “01.”. there are about 16 chars with a strange ascii symbol, then one LF (4. Char) and then the three chars “01.” Is this a clue to what might be happening?

did you read my comment there?

Yes, i saw it. But i don't really know what i should do with it.
Do i have to perform a handshake?

I can't see where buffer is declared s something missing from the code you pasted?

I can see that you fill buffer but then never do anything with it, did you mean to print it out?

FelixKunzJr:
Yes, i saw it. But i don't really know what i should do with it.
Do i have to perform a handshake?

turn it off in putty. or ignore the data. implementing the negotiations is not trivial and I guess you don't need it.

countrypaul:
I can't see where buffer is declared s something missing from the code you pasted?

I can see that you fill buffer but then never do anything with it, did you mean to print it out?

The buffer is an old artifact, I tried to fill a buffer and then print it out, but it didn't work. I commented out this part a while ago.

FelixKunzJr:
The buffer is an old artifact, I tried to fill a buffer and then print it out, but it didn't work. I commented out this part a while ago.

OK, sorry I missed the two comment lines around that section.

Rereading your original post, you say "there are about 16 chars with a strange ascii symbol, then one LF (4. Char) and then the three chars "01." Is this a clue to what might be happening?" 16 chars would correspond to the timestamp you expect.

countrypaul:
Rereading your original post, you say "there are about 16 chars with a strange ascii symbol, then one LF (4. Char) and then the three chars "01." Is this a clue to what might be happening?" 16 chars would correspond to the timestamp you expect.

Thats something i also thought of... That it receiving 16 chars, but it has some kind of offset so it reads about 10 old chars, then 4 of the new message and it thinks it's done. But i kinda discarded this idea, because i can send new messages to the client, and nothing new shows up. If it would have an offset, i should get the rest of the timestamp when i send new messages, right?

just to be clear. I made the EthernetENC library and it is not a problem of the library

I thought the Nano was a 3.3V device and the Ethernet shield a 5v device, if so have you included any level shifters?

Not sure how/whether this could cause problems like you are seeing, but it could have other adverse effects.

countrypaul:
I thought the Nano was a 3.3V device and the Ethernet shield a 5v device, if so have you included any level shifters?

Not sure how/whether this could cause problems like you are seeing, but it could have other adverse effects.

Nano is a 5 V device and Ethernet shield is a 3.3 V device with 5 V tolerant pins.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.