4343#define HTTP_CONTENT " AT+HTTPPARA=\" CONTENT\" ,\" application/json\"\r\n "
4444#define NORMAL_MODE " AT+CFUN=1,1\r\n "
4545#define REGISTRATION_STATUS " AT+CREG?\r\n "
46+ #define SIGNAL_QUALITY " AT+CSQ\r\n "
4647
4748#define OK " OK\r\n "
4849#define DOWNLOAD " DOWNLOAD"
@@ -56,20 +57,22 @@ Result HTTP::configureBearer(const char *apn){
5657
5758 int attempts = 0 ;
5859 int MAX_ATTEMPTS = 10 ;
59- while (sendCmdAndWaitForResp (REGISTRATION_STATUS, CONNECTED, 5000 ) != TRUE && attempts < MAX_ATTEMPTS){
60+
61+ while (sendCmdAndWaitForResp (REGISTRATION_STATUS, CONNECTED, 2000 ) != TRUE && attempts < MAX_ATTEMPTS){
62+ sendCmdAndWaitForResp (SIGNAL_QUALITY, CONNECTED, 1000 );
6063 attempts ++;
6164 if (attempts == MAX_ATTEMPTS) {
6265 attempts = 0 ;
6366 preInit ();
6467 }
6568 }
6669
67- if (sendCmdAndWaitForResp (BEARER_PROFILE_GPRS, OK, 5000 ) == FALSE )
70+ if (sendCmdAndWaitForResp (BEARER_PROFILE_GPRS, OK, 2000 ) == FALSE )
6871 result = ERROR_BEARER_PROFILE_GPRS;
6972
7073 char httpApn[128 ];
7174 sprintf (httpApn, BEARER_PROFILE_APN, apn);
72- if (sendCmdAndWaitForResp (httpApn, OK, 5000 ) == FALSE )
75+ if (sendCmdAndWaitForResp (httpApn, OK, 2000 ) == FALSE )
7376 result = ERROR_BEARER_PROFILE_APN;
7477
7578 return result;
@@ -79,10 +82,11 @@ Result HTTP::connect() {
7982
8083 Result result = SUCCESS;
8184
82- if (sendCmdAndWaitForResp (OPEN_GPRS_CONTEXT, OK, 5000 ) == FALSE )
85+ if (sendCmdAndWaitForResp (OPEN_GPRS_CONTEXT, OK, 2000 ) == FALSE ){
8386 result = ERROR_OPEN_GPRS_CONTEXT;
87+ }
8488
85- if (sendCmdAndWaitForResp (HTTP_INIT, OK, 5000 ) == FALSE )
89+ if (sendCmdAndWaitForResp (HTTP_INIT, OK, 2000 ) == FALSE )
8690 result = ERROR_HTTP_INIT;
8791
8892 return result;
@@ -104,18 +108,17 @@ Result HTTP::post(const char *uri, const char *body, char *response) {
104108
105109 Result result = setHTTPSession (uri);
106110
107- char httpData[128 ];
108- int delayToDownload = 5000 ;
109- sprintf (httpData, HTTP_DATA, strlen (body), delayToDownload );
110- if (sendCmdAndWaitForResp (httpData, DOWNLOAD, 5000 ) == FALSE ){
111+ char httpData[32 ];
112+ int delayToDownload = 10000 ;
113+ sprintf (httpData, HTTP_DATA, strlen (body), 2000 );
114+ if (sendCmdAndWaitForResp (httpData, DOWNLOAD, 2000 ) == FALSE ){
111115 result = ERROR_HTTP_DATA;
112116 }
113117
114- sendCmd (body);
115118 purgeSerial ();
119+ printData (body);
116120 delay (delayToDownload);
117-
118- if (sendCmdAndWaitForResp (HTTP_POST, HTTP_200, 5000 ) == TRUE ) {
121+ if (sendCmdAndWaitForResp (HTTP_POST, HTTP_200, delayToDownload) == TRUE ) {
119122 sendCmd (HTTP_READ);
120123 result = SUCCESS;
121124 readResponse (response);
@@ -131,7 +134,7 @@ Result HTTP::get(const char *uri, char *response) {
131134
132135 Result result = setHTTPSession (uri);
133136
134- if (sendCmdAndWaitForResp (HTTP_GET, HTTP_200, 5000 ) == TRUE ) {
137+ if (sendCmdAndWaitForResp (HTTP_GET, HTTP_200, 2000 ) == TRUE ) {
135138 sendCmd (HTTP_READ);
136139 result = SUCCESS;
137140 readResponse (response);
@@ -149,7 +152,7 @@ Result HTTP::setHTTPSession(const char *uri){
149152 if (sendCmdAndWaitForResp (HTTP_CID, OK, 2000 ) == FALSE )
150153 result = ERROR_HTTP_CID;
151154
152- char httpPara[512 ];
155+ char httpPara[128 ];
153156 sprintf (httpPara, HTTP_PARA, uri);
154157
155158 if (sendCmdAndWaitForResp (httpPara, OK, 2000 ) == FALSE )
@@ -163,7 +166,7 @@ Result HTTP::setHTTPSession(const char *uri){
163166
164167void HTTP::readResponse (char *response){
165168
166- char buffer[256 ];
169+ char buffer[128 ];
167170 cleanBuffer (buffer, sizeof (buffer));
168171 cleanBuffer (response, sizeof (response));
169172
0 commit comments