Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino GPRS htttp command doesnt responding properly

Status
Not open for further replies.

Fazlay Rabbi

Junior Member level 1
Joined
Oct 25, 2014
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
159
I am using arduino uno with itead 3G shield , my shield works fine but it doesn't responding properly ,
After sendint
"AT+chttpact =......"

it back me +CHTTPACT: REQUEST
then when it send GET command it doesn't response at all

What could be the problem ??

here the real response and the code :


Code dot - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
GSM : Registered to network
GSM : Ready for AT command
 
*** Start HTTP Transaction ***
 
+CHTTPACT: REQUEST
AT+CHTTPACT="jsonplaceholder.typicode.com",80
Sends Request:
GET /posts/1/ HTTP/1.1
Host:jsonplaceholder.typicode.com:80
Content-Length:0
 
 
 
*** End HTTP Transaction ***
 
Memory Free : 1216



Code :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Included header files
#include <SoftwareSerial.h>
 
 
// AT command related
#define AT_CREG_QUERY ("AT+CREG?")
#define AT_CHTTPACT_COMMAND ("AT+CHTTPACT="%s",%d")
#define AT_CHTTPACT_INIT_RESPONSE ("+CHTTPACT: REQUEST")
#define AT_CHTTPACT_DATA_RESPONSE ("+CHTTPACT: DATA,")
#define AT_CHTTPACT_DONE_RESPONSE ("+CHTTPACT:0")
 
#define EOS ('\0')
#define ESC (0x1A)
#define OK ("OK")
 
// GSM definitions
#define unoTXPin (7) // Uno -> GSM
#define unoRXPin (6) // Uno <- GSM
#define powerGSMPin (8)
#define GSMBaudRate (9600)
#define UnoBaudRate (9600)
 
SoftwareSerial gsmSerial(unoRXPin,unoTXPin);
 
#define TEST_REQUEST ("GET /posts/1/ HTTP/1.1\r\nHost:jsonplaceholder.typicode.com:80\r\nContent-Length:0\r\n\r\n")
 
char aux_str [100];
 
int8_t answer;
int aux = 0;
int data_size = 0;
 
 
#define HOST_NAME ("jsonplaceholder.typicode.com")
#define HOST_PORT (80)
 
void setup() {
 
 
// init sequence
Serial.begin(UnoBaudRate);
gsmSerial.begin(UnoBaudRate);
 
gsm_power_on();
while( (sendATcommand(AT_CREG_QUERY, "+CREG: 0,1", 500) || 
sendATcommand(AT_CREG_QUERY, "+CREG: 0,5", 500)) == 0 );
Serial.println(F("GSM : Registered to network"));
Serial.println(F("GSM : Ready for AT command"));
}
void loop () {
 
sprintf(aux_str, AT_CHTTPACT_COMMAND, HOST_NAME, HOST_PORT);
Serial.println(F("\n*** Start HTTP Transaction ***\n"));
Serial.println(AT_CHTTPACT_INIT_RESPONSE);
 
answer = sendATcommand(aux_str, AT_CHTTPACT_INIT_RESPONSE, 60000);
Serial.println(aux_str);
if (answer == 1)
{  
 
data_size = 0;
 
Serial.println(F("Sends Request:"));
Serial.println(TEST_REQUEST);    
gsmSerial.println(TEST_REQUEST);
// Sends 
aux_str[0] = ESC;
aux_str[1] = 0x00;
answer = sendATcommand(aux_str, AT_CHTTPACT_DATA_RESPONSE, 300000);
 
if(answer == 1)
{
Serial.println(AT_CHTTPACT_DATA_RESPONSE);
 
while(gsmSerial.available() > 0) {
Serial.print((char)gsmSerial.read());
}
 
}
 
Serial.println(F("\n*** End HTTP Transaction ***\n"));
Serial.print(F("Memory Free : "));
Serial.println(memoryFree());
while(1); // halt
}
 
 
 
 
}
// variables created by the build process when compiling the sketch
extern int __bss_end;
extern void *__brkval;
// function to return the amount of free RAM
int memoryFree(){
int freeValue;
if((int)__brkval == 0) 
freeValue = ((int)&freeValue) - ((int)&__bss_end);
else 
freeValue = ((int)&freeValue) - ((int)__brkval);
return freeValue;
}
 
void gsm_power_on(){
 
uint8_t answer=0;
 
// checks if the module is started
answer = sendATcommand("AT", "OK", 2000);
if (answer == 0)
{
// power on pulse
digitalWrite(powerGSMPin,HIGH);
delay(200);
digitalWrite(powerGSMPin,LOW);
delay(6000);
// waits for an answer from the module
while(answer == 0){    
// Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", OK, 2000);    
}
}
 
}
 
int8_t sendATcommand(char* ATcommand, char* expected_answer1,
unsigned int timeout)
{
 
uint8_t x=0,  answer=0;
char response[100];
unsigned long previous;
 
memset(response, EOS, 100);    // Initialize the string
 
delay(100);
 
while( gsmSerial.available() > 0) gsmSerial.read();    // Clean the input buffer
 
gsmSerial.println(ATcommand);    // Send the AT command 
 
 
x = 0;
previous = millis();
 
// this loop waits for the answer
do{
 
if(gsmSerial.available() != 0){    
response[x] = gsmSerial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)    
{
answer = 1;
}
}
// Waits for the asnwer with time out
}
while((answer == 0) && ((millis() - previous) < timeout));    
 
return answer;
}
 
int8_t sendATcommand2(char* ATcommand, char* expected_answer1,
char* expected_answer2, unsigned int timeout)
{
 
uint8_t x=0,  answer=0;
char response[100];
unsigned long previous;
 
memset(response, EOS, 100);    // Initialize the string
 
delay(100);
 
while( gsmSerial.available() > 0) gsmSerial.read();    // Clean the input buffer
 
Serial.println(ATcommand);    // Send the AT command 
 
 
x = 0;
previous = millis();
 
// this loop waits for the answer
do{
 
if(gsmSerial.available() != 0){    
response[x] = gsmSerial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)    
{
answer = 1;
}
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer2) != NULL)    
{
answer = 2;
}
}
// Waits for the asnwer with time out
}
while((answer == 0) && ((millis() - previous) < timeout));    
 
return answer;
}

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top