I am trying to send Get request from my GSM Module but after connecting to server it is not responding any thing
#include <SoftwareSerial.h>
SoftwareSerial myGsm(2,3);
void setup()
{
myGsm.begin(9600);
Serial.begin(9600);
delay(500);
myGsm.println("AT+CGATT=1");
delay(200);
printSerialData();
myGsm.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR,connection type is GPRS
delay(1000);
printSerialData();
myGsm.println("AT+SAPBR=3,1,\"APN\",\"wap.mobilinkworld.com\"");//setting the APN,2nd parameter empty works for all networks
delay(5000);
printSerialData();
myGsm.println();
myGsm.println("AT+SAPBR=1,1");
delay(10000);
printSerialData();
myGsm.println();
myGsm.println("AT+SAPBR=2,1");
delay(10000);
printSerialData();
myGsm.println("AT+HTTPINIT");
delay(2000);
printSerialData();
myGsm.println("AT+HTTPPARA=\"URL\",\"http://sensor.somee.com/api/Data/GetData?SensorID=1\"");// setting the httppara,
delay(1000);
printSerialData();
myGsm.println();
delay(10000);//the delay is important if the return datas are very large, the time required longer.
printSerialData();
delay(9000);
printSerialData();
delay(1000);
Serial.println("done ");
printSerialData();
}
void loop()
{
}
void printSerialData()
{
while(myGsm.available()!=0)
Serial.write(myGsm.read());
}
and the Out put is
AT+CGATT=1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","wap.mobilinkworld.com"
OK
AT+SAPBR=1,1
OK
AT+SAPBR=2,1
+SAPBR: 1,1,"10.209.122.68"
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","http://sensor.somee.com/api/Data/GetData?Sen
done
-
Could you solve this problem?Davoud– Davoud2021年02月22日 09:19:03 +00:00Commented Feb 22, 2021 at 9:19
2 Answers 2
You haven't instructed the module to make a request yet. With the AT+HTTPPARA command, you are just configuring the request you want to make. In your case, you just specified the URL you want to call. Next, you have to send
AT+HTTPACTION=1
to make the actual request using the HTTP GET method, and then you can read the HTTP response using
AT+HTTPREAD
Keep in mind that after AT+HTTPACTION you will receive an unsolicited result code in the format
+HTTPACTION: <Method>,<StatusCode>,<DataLen>
this will happen after the module will actually do the request and will have the response.
You should place the code to communicate (which is a recurring task) into the loop (and do this without blocking delay()s. Using delay stops the CPU so whatever comes to the buffer is probably not processed.
Read about the difference of placing code in the setup and the loop in the Arduino basic documentation.
Never use delay in communiction scenarios (except for intializing hardware in setup) see example blinkwithoutdelay in ArduinoIDE
-
Calling webservice in a loop :| ?! What do you mean?Davoud– Davoud2021年02月22日 09:18:09 +00:00Commented Feb 22, 2021 at 9:18