itead / ITEADLIB_Arduino_SIMCom

GSM GPRS GPS Bluetooth for SIM800/808/900/908 Shield Library
GNU General Public License v2.0
61 stars 30 forks source link

Making Asynchronous POST request #4

Open solankigithub opened 8 years ago

solankigithub commented 8 years ago

Hi, Can you please suggest, how can i make an Asynchronous calls and POST data without any response. I need to post the data every 2 seconds from my device to Server. At this moment, i don't want any acknowledgement, but rather just post the data. Is there any way to achieve this? I created my own method in the library as shown below, but its still taking 10 seconds.

int InetGSM::httpAsyncPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength)
{
     boolean connected=false;
     int n_of_at=0;
     char itoaBuffer[8];
     int num_char;
     char end_c[2];
     end_c[0]=0x1a;
     end_c[1]='\0';

     while(n_of_at<3) {
          if(!connectTCP(server, port)) {
#ifdef DEBUG_ON
               Serial.println("DB:NOT CONN");
#endif
               n_of_at++;
          } else {
               connected=true;
               n_of_at=3;
          }
     }

     if(!connected) return 0;

     gsm.SimpleWrite("POST ");
     gsm.SimpleWrite(path);
     gsm.SimpleWrite(" HTTP/1.1\r\nHost: ");
     gsm.SimpleWrite(server);
     gsm.SimpleWrite("\r\n");
     gsm.SimpleWrite("User-Agent: Arduino\r\n");
     gsm.SimpleWrite("Content-Type: application/x-www-form-urlencoded\r\n");
     gsm.SimpleWrite("Content-Length: ");
     itoa(strlen(parameters),itoaBuffer,10);
     gsm.SimpleWrite(itoaBuffer);
     gsm.SimpleWrite("\r\n\r\n");
     gsm.SimpleWrite(parameters);
     gsm.SimpleWrite("\r\n\r\n");
     gsm.SimpleWrite(end_c);

     return 1;
}

Can you please suggest more improvements ? Also, is it mandatory to close the connection every time using AT+CIPCLOSE ? Isn't there a way to make the connection open and send the packet to the server ?

You quick response will be highly appreciated !

Thanks