I have been informed that I should switch to different commands, which I have. My code now looks like:
void SubmitHttpRequest()
{
Serial1.println("AT+CSQ");
delay(100);
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
Serial1.println("AT+CGATT?");
delay(100);
ShowSerialData();
Serial1.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
Serial1.println("AT+SAPBR=3,1,\"APN\",\"everywhere\"");//setting the APN, the second need you fill in your local apn server
delay(4000);
ShowSerialData();
//Enable GPRS
Serial1.println("AT+SAPBR=1,1");
delay(2000);
ShowSerialData();
//Query if connection is setup correctly, return IP address if it is
Serial1.println("AT+SAPBR=2,1");
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPSSL=1"); //enable HTTPS
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"CID\",1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"URL\",\"https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register\"");
delay(6000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
delay(3000);
ShowSerialData();
Serial1.println("AT+HTTPDATA=200,10000");// setting the httppara, the second parameter is the website you want to access
delay(3000);
ShowSerialData();
Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");// setting the httppara, the second parameter is the website you want to access
delay(3000);
ShowSerialData();
Serial1.println("AT+HTTPACTION=1");//submit the request //0:READ 1:POST 2:HEAD
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
ShowSerialData();
Serial1.println("AT+HTTPREAD");
delay(1000);
ShowSerialData();
Serial1.println("AT+HTTPTERM");
delay(1000);
ShowSerialData();
Serial1.println("");
delay(100);
}
This gives me the result of:
AT+CSQ
+CSQ: 18,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","everywhere"
OK
AT+SAPBR=1,1
ERROR
AT+SAPBR=2,1
+SAPBR: 1,1,"31.94.203.234"
OK
AT+HTTPSSL=1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPPARA="URL","https://rocky-garden-56471.herokuapp.com/breAT+HTTPPARA="CONTENT","application/json"
OK
AT+HTTPDATA=100,10000
DOWNLOAD
ERROR
AT+HTTPREAD
OK
AT+HTTPTERM
OK
Which is incredibly close, as (ignore the connection error which has appeared because I was already connected) I only have the single error on download. I can't seem to figure out why this is happening, changing delays and data size doesn't appear to make any difference. Any idea what could be causing this?