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