Arduino WIFLY POST text file...

Hi,

I have a txt file on the SD card from my arduino.

And I need to send that file through my WIFI module ... (wiflyHQ library).

What better way to send?

I try POST method ... but my response is null..

// INIT :
           if (wifly.open(host, 80)) {
            Serial.print(F("Connected to ")); 
            Serial.println(host);

            /* Send the request */
            String httpPostCommand = "POST " + (String)url + " HTTP/1.1"; // try with 1.1 so we can skip Content-Length header
            wifly.println(httpPostCommand);
            wifly.print("Host: "); 
            wifly.println(host);
            wifly.println("Content-Type: multipart/form-data, boundary=xxxBOUNDARYxxx");
            wifly.print("Content-Length: "); 
            wifly.println(readingsFileSize + 81);     
            wifly.println();
            wifly.println("--xxxBOUNDARYxxx");
            wifly.println("content-disposition: form-data; name=\"data\"");
            wifly.println();

            int ch;
            while ((ch = readingsFile.read()) != -1) 
            {
              wifly.print((char)ch); 
              Serial.print((char)ch);
            }

             wifly.println("--xxxBOUNDARYxxx");
            Serial.println("--xxxBOUNDARYxxx");
            wifly.println();
            Serial.println(); 

            int dataIndex = 0;
            char postRespBuffer[256];


            while (wifly.available() > -1)
            {
              postRespBuffer[0]='\0';
              int readedBytes = wifly.gets(postRespBuffer, sizeof(postRespBuffer) - 1,2500);
              postRespBuffer[readedBytes] = '\0';

              Serial.write(postRespBuffer);  // @todo only for debug

              // verify POST request OK: HTTP/1.***200***OK

              if ((strstr(postRespBuffer, "HTTP/1") != NULL) && (strstr(postRespBuffer, "200") != NULL)){
                Serial.print("Post Response OK");
                return true; 
                // @todo read POST response OK --> VERIFY..
              }
              else if(postRespBuffer==""){
                Serial.print(F("Post Response is NULL"));
              }
              else{
                Serial.print(F("Invalid response from server at POST: "));
                Serial.println(postRespBuffer);
                return false;  
              }
            }

this:
POST /readings.axd HTTP/1.1
Host: 192.168.28.100
Content-Type: multipart/form-data, boundary=xxxBOUNDARYxxx
Content-Length: 236

--xxxBOUNDARYxxx
content-disposition: form-data; name="data"

2013_06_12 11:49 2700CFDAD0 0
2013_06_12 11:52 0F00088CD2 1
2013_06_12 11:52 0F000C9C0E 2
2013_06_12 11:52 0F000C9C0E 3
2013_06_12 12:00 0F00088CD2 1
--xxxBOUNDARYxxx

works in windows cmd... with telnet.. but not work in arduino.. why ? sugestions...

            while (wifly.available() > -1)

0 is greater than -1. There is no sense trying to read something when there are 0 bytes available.

Expecting a response as quickly as you do is unrealistic. You need a while(wifly.connected()) loop that wraps a while(wifly.available() > 0) loop.

PaulS:

            while (wifly.available() > -1)

0 is greater than -1. There is no sense trying to read something when there are 0 bytes available.

Expecting a response as quickly as you do is unrealistic. You need a while(wifly.connected()) loop that wraps a while(wifly.available() > 0) loop.

ok.. i change >> "while (wifly.available() > 0)"

.. I use "WiflyHQ"... wifly.connected() --> this function does not exist

but exist wifly.isConnected()..

Please give me an example...

Please give me an example...

First, post a link to the library that you are using. I don't have that library.

PaulS:

Please give me an example...

First, post a link to the library that you are using. I don't have that library.

Sorry.. GitHub - harlequin-tech/WiFlyHQ: WiFly RN-XV Arduino Library

It looks like the isConnected() method is equivalent to the connected() method in the Ethernet class. So, something like:

while(wifly.isConnected())
{
while(wifly.available() > 0)
{
// Read the response
}
}