Reading form POST data seems utterly impossible with wifiesp library.
If a read one char at a time until I reach the data length in the HTTP POST header then I end up with a TIMEOUT error and chars lost from my form POST data.
If I try a loop with bulk reads like below, I end up with total garbage as my POST data:
How do you frigging do this?????
Extremely frustrated!
bool CWifi::readPostData(WiFiEspClient& WifiClient, const uint16_t nPostDataLength)
{
bool bEndOfDataFound = true;
CTextFile filePostData(m_strPostDataFileName.c_str(), O_WRITE | O_CREAT | O_TRUNC);
uint16_t nTotalBytesRead = 0;
if (filePostData)
{
while ((WifiClient.available() > 0) && (nTotalBytesRead < nPostDataLength))
{
if (WifiClient.available() > BUFF_SIZE)
{
m_nBytesRead = WifiClient.read(m_arrayReadBuff, BUFF_SIZE);
}
else
m_nBytesRead = WifiClient.read(m_arrayReadBuff, WifiClient.available());
filePostData.write(m_arrayReadBuff, m_nBytesRead);
nTotalBytesRead += m_nBytesRead;
}
filePostData.close();
dumpFile(m_strPostDataFileName.c_str());
}
return bEndOfDataFound;
I tried this loop to get my POST data.
bool CWifi::readPostData(WiFiEspClient& WifiClient, uint16_t nPostDataLength)
{
bool bEndOfDataFound = true;
CTextFile filePostData(m_strPostDataFileName.c_str(), O_WRITE | O_CREAT | O_TRUNC);
uint16_t nTotalBytesRead = 0;
if (filePostData)
{
debug('*', WifiClient.available());
debug('*', BUFF_SIZE);
debug('*', nPostDataLength);
while (WifiClient.available() > 0)
{
m_nBytesRead = WifiClient.read(m_arrayReadBuff, nPostDataLength);
debug('@', WifiClient.available());
}
debug('*', m_nBytesRead);
}
}
The out put of the debug statements are as follows:
WifiClient.available() = 568
BUFF_SIZE = 2048
nPostDataLength = 555
After 'm_nBytesRead = WifiClient.read(m_arrayReadBuff, nPostDataLength);'
And then I am in an infinite loop
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
WifiClient.available() = 245
.
.
.
Aren't these read functions supposed to read the number of bytes specified by the second parameter or else what ever bytes are available?
Why do I end up in an infinite loop with WifiESP with bytes available for reading?????
HOW DO YOU SENSIBLY GET BYTES OUT OF THIS DAMN WifiClient object?