PaulStoffregen / Ethernet

Ethernet library for Teensy (Wiznet W5100 / W5200 / W5500)
http://www.pjrc.com/teensy/td_libs_Ethernet.html
130 stars 83 forks source link

endPacket() failure #29

Closed weirdgyn closed 5 years ago

weirdgyn commented 5 years ago

I'm writing a quite complex sketch where I use Ethernet library to provide UDP bidirectional connections between a Teensy + W850io module and a client application running on an Android tablet. The 'receving' part (running on Teensy) works fine but when I try to send data back to the client I got a very strange behaviour on endPacket() call. Everything stops working just after this call..

This's my code:

void sendTelemetry(int i, const char* _identification, int _value)
{
  char _buffer[5] = { 0, 0, 0, 0, 0 };
  char _buffer_crc[3] = { 0, 0, 0 };
  char _buffer_identification[2] = { 0, 0 };
  String _aux = "";
  byte _crc = 0x00;

  _aux.reserve(16);

  Int2HexStr(_value, _buffer);
  _crc = computeCRC(_buffer);                   // TODO: calcolo crc
  Byte2HexStr(_crc, _buffer_crc);                // sprint(_buffer_crc,"%02X", _crc );

#ifdef DEBUG_SEND_TELEMETRY
  Serial.print("CRC(0x)=");
  Serial.println(_buffer_crc);
#endif

  sprintf(_buffer_identification, "%d", i);

  _aux = "$";
  _aux += _identification;
  _aux += _buffer_identification;
  _aux += _buffer;
  _aux += _buffer_crc;
  _aux += "&";

  if (ethTelemetry.beginPacket(destinationIP, UDP_REMOTE_PORT) == 1)
  {
    ethTelemetry.write(_aux.c_str());
#ifdef DEBUG_SEND_TELEMETRY
    Serial.print("UDP sending: ");
#endif

    if (ethTelemetry.endPacket() != 1)
    {
#ifdef DEBUG_SEND_TELEMETRY
      Serial.print("endPacket() failed!");
#endif
    }
  }
  else
  {
#ifdef DEBUG_SEND_TELEMETRY
    Serial.print("beginPacket() failed!");
#endif
  }

#ifdef DEBUG_SEND_TELEMETRY
  Serial.print("...sent: ");
  Serial.println(_aux.c_str());
#endif
}
PaulStoffregen commented 5 years ago

I replied on the forum.

https://forum.pjrc.com/threads/53999-W850io-endPacket()-failure

Please do not create duplicate messages. An issue here on github is only appropriate if the problem is really a bug in the Ethernet library.