I am having a strange issue where if I try and create a TCP connection to my service, it doesn't work. But any other website, such as google, works fine. The serial monitor output is also slightly different, but I cannot see any difference in the code. I am using this module for communications.
This is the method that I am using:
void SendPost()
{
Serial1.println("AT+CGATT?");
delay(1000);
ShowSerialData();
Serial1.println("AT+CSTT=\"everywhere\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
Serial1.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
Serial1.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
Serial1.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
Serial1.println("AT+CIPSTART=\"tcp\",\"www.google.com/\",\"80\"");//start up the connection //https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register
delay(5000);
ShowSerialData();
Serial1.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");
delay(500);
ShowSerialData();
Serial1.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
Serial1.println();
ShowSerialData();
Serial1.println("AT+CIPCLOSE");//close the connection
delay(100);
ShowSerialData();
}
Using 'www.google.com' I get an OK upon tcp connection (with an expected error on the data as I try to POST):
Setup CompleteAT+CGATT?
+CGATT: 1
OK
AT+CSTT="everywhere"
OK
AT+CIICR
OK
AT+CIFSR
100.66.4.95
AT+CIPSPRT=0
OK
AT+CIPSTART="tcp","www.google.com/","80"
OK
STATE: IP STAAT+CIPSEND
ERROR
{"device_info":"breadcrum-prototype-a"}
AT+CIPCLOSE
ERROR
But using the address I actually want to post data to (https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register), it cannot connect and I get this:
Setup CompleteAT+CGATT?
+CGATT: 1
OK
AT+CSTT="everywhere"
OK
AT+CIICR
OK
AT+CIFSR
100.66.4.95
AT+CIPSPRT=0
OK
AT+CIPSTART="tcp","https://rocky-garden-56471.herokuapp.com/breAT+CIPSEND
ERROR
{"device_info":"breadcrum-prototype-a"}
AT+CIPCLOSE
ERROR
This errors on connection, and you can also see that the full address isn't printed out for some reason. Does anyone have any idea what could be causing this issue?
Thanks :)
EDIT: @Majenko, my previous version did what I believe you are describing. The issue being I got an error that I struggled to resolve so attempted this version. The previous version is:
void SubmitHttpRequest()
{
Serial1.println("AT+CSQ");
delay(100);
ShowSerialData();
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+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
//Set up bearer profile identifier (NEW PART)
Serial1.println("AT+HTTPPARA=\"CID\",1");
delay(2000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"URL\",\"https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register\"");// setting the httppara, the second parameter is the website you want to access
delay(3000);
ShowSerialData();
Serial1.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
delay(3000);
ShowSerialData();
Serial1.println("AT+HTTPDATA=1000,10000");
delay(3000);
ShowSerialData();
Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");
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");// read the data from the website you access
delay(1000);
ShowSerialData();
Serial1.println("");
delay(100);
}
But the results I got from this was another error when attempting to post:
Setup CompleteAT+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
OK
AT+SAPBR=2,1
+SAPBR: 1,1,"19.177.18.205"
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=1000,10000
DOWNLOAD
ERROR
AT+HTTPREAD
OK
EDIT 2: Following HTTPS commands:
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
1 Answer 1
There is so many things wrong that I don't know where to start.
- You are trying to use a URL in place of a hostname.
- You are trying to connect to an HTTPS service which runs on port 443 not on port 80
- HTTPS is encrypted. You are opening a plain TCP socket to an encrypted service.
Your whole methodology is wrong. You need to use the SIM900 HTTPS AT Command Set to get the SIM900 to perform an HTTPS request on your behalf rather than opening a socket and sending / receiving data.
-
I have posted my previous version in an edit to the main question. I believe that version did what you are describing, but I also received errors on the result of this.Calco– Calco2016年08月08日 13:26:19 +00:00Commented Aug 8, 2016 at 13:26
-
Not quite. Close, but not quite. In that version you're using HTTP commands to access an HTTPS site. You need to use HTTPS commands not HTTP commands.Majenko– Majenko2016年08月08日 13:28:07 +00:00Commented Aug 8, 2016 at 13:28
-
Following the HTTPS commands I get very close, but with only errors occurring on the download. I have added "AT+HTTPSSL=1" to enable https. I have added another edit to reflect my new results.Calco– Calco2016年08月08日 13:43:29 +00:00Commented Aug 8, 2016 at 13:43
-
Are you actually sending 1000 bytes of data to the server?Majenko– Majenko2016年08月08日 13:57:03 +00:00Commented Aug 8, 2016 at 13:57
-
I am only sending
Serial1.println("{\"device_info\":\"breadcrum-prototype-a\"}");
. But I believe the issue is being caused by the URL being chopped, there are logs which say 'not found /bre'. Why would the command:Serial1.println("AT+HTTPPARA=\"URL\",\"https://rocky-garden-56471.herokuapp.com/breadcrum/lifecycle/register\"");
be cut down?Calco– Calco2016年08月08日 14:01:12 +00:00Commented Aug 8, 2016 at 14:01