bportaluri WiFiEsp - [WiFiEsp] Data packet send error (1)

Is anyone else have issues with this bloody irritating error message from his library with recent changes he has made?

I was having major issues sending web pages until I doubled or quadrupled his timeouts in his various ::SendData(…) functions in EspDrv.cpp:

bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
{
	LOGDEBUG2(F("> sendData:"), sock, len);

	char cmdBuf[20];
	sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len);
	espSerial->println(cmdBuf);

	//int idx = readUntil(1000, (char *)">", false);
	int idx = readUntil(4000, (char *)">", false);
	if(idx!=NUMESPTAGS)
	{
		LOGERROR(F("Data packet send error (1)"));
		return false;
	}

	espSerial->write(data, len);

	//idx = readUntil(2000);
	idx = readUntil(4000);
	if(idx!=TAG_SENDOK)
	{
		LOGERROR(F("Data packet send error (2)"));
		return false;
	}

    return true;
}

This seems to have reliably fixed my problem of this same error being thrown before I was able to send a complete web page.

But now I am also getting the same error when sending an email. My code was working just fine until the recent changes.

In attached SMTPClinet.cpp, my code gets as far as line 103 (that is trying to write the “From: …<…>” email field) and then WifiEsp throws the error:

[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Data packet send error (1)
[WiFiEsp] Failed to write to socket 1

Nothing I have tried in his library will stop this error. Doubling the timeouts again makes no difference.

Basically it is now impossible to send an email using his library, based on this example http://playground.arduino.cc/Code/Email, when it was possible with previous versions of the library.

SMTPClient.cpp (10.2 KB)

SMTPClient.h (1.49 KB)

When it’s bloody irritating then it’s time to write your own library and be in charge, then you can control everything

You have the source code of the library, have you tried debugging ?

J-M-L:
When it’s bloody irritating then it’s time to write your own library and be in charge, then you can control everything

You have the source code of the library, have you tried debugging ?

The error is be generated here:

bool EspDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
{
	LOGDEBUG2(F("> sendData:"), sock, len);

	char cmdBuf[20];
	sprintf_P(cmdBuf, PSTR("AT+CIPSEND=%d,%u"), sock, len);
	espSerial->println(cmdBuf);

	//int idx = readUntil(1000, (char *)">", false);
	int idx = readUntil(4000, (char *)">", false);
	if(idx!=NUMESPTAGS)
	{
		[b]LOGERROR(F("Data packet send error (1)"));[/b]
		return false;
	}

	espSerial->write(data, len);

	//idx = readUntil(2000);
	idx = readUntil(4000);
	if(idx!=TAG_SENDOK)
	{
		LOGERROR(F("Data packet send error (2)"));
		return false;
	}

    return true;
}

It makes no sense why I can get this far with my SMTPClient class but no farther:

if (waitAck())
				{
					memset(strTemp, 0, nBuffSize);
					strcpy_P(strTemp, (PGM_P)F("MAIL From: <"));
					if (strlen(m_strFromEmail) > 0)
						strcat(strTemp, m_strFromEmail);
					strcat_P(strTemp, (PGM_P)F(">"));
					
					write(strTemp);
					if (waitAck())
					{
						memset(strTemp, 0, nBuffSize);
						strcpy_P(strTemp, (PGM_P)F("RCPT To: <"));
						strcat(strTemp, m_strToEmail);
						strcat_P(strTemp, (PGM_P)F(">"));
						write(strTemp);
						if (waitAck())
						{
							write(F("DATA"));
							if (waitAck())
							{
								memset(strTemp, 0, nBuffSize);
								strcpy_P(strTemp, (PGM_P)F("To: <"));
								strcat(strTemp, m_strToEmail);
								strcat_P(strTemp, (PGM_P)F(">"));
								if (write(strTemp))
								{								
									memset(strTemp, 0, nBuffSize);
									strcpy_P(strTemp, (PGM_P)F("From: Irrigation controller <"));
									strcat(strTemp, m_strFromEmail);
									strcat_P(strTemp, (PGM_P)F(">"));
									if (write(strTemp))

delay(100) etc after my calls to write(...), i.e. give the shield time to empty its send buffer before writing the next lot of data, don't work either.