Has anybody been able to go an HTTPS POST/GET request on the Fona SIM 5320A?
I'm aware the library doesn't support it. But I've been reading the ATC manual on my own, discovered that there are some SSL commands that need to be performed before any "XXXS" action, including HTTPS Get request i.e.
HTTPS POST/GET ?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 194
- Joined: Thu Dec 10, 2015 7:25 am
Re: HTTPS POST/GET ?
You can try these simple Arduino sketches out, check out the "Programming help needed thread..." it has lots of http and https stuff in it.
an example on calling those AT command functions:
Code: Select all
//////////////////////////////////////////////////////
// sendReceiveATCommand function send a command to 3G module and only expect for a defined time and waits for the result.
String sendReceiveATCommand(const char *toSend, unsigned long milliseconds)
{
String result;
Serial.print("Sending: ");
Serial.println(toSend);
fonaSS.println(toSend);
unsigned long startTime = millis();
Serial.print("Received: ");
while (millis() - startTime < milliseconds)
{
if (fonaSS.available())
{
char c = fonaSS.read();
Serial.write(c);
result += c; // append to the result string
} // end of if (fonaSS.available())
} // end of while (millis() - startTime < milliseconds)
Serial.println(); // new line after timeout.
return result;
} // end of string
//////////////////////////////////////////////////////
// sendReceiveATCommand2 function send a command to 3G module and compare the result to a given string, when there's a match it stops waiting.
String sendReceiveATCommand2(const char *toSend, const char *toCheck1, const char *toCheck2, unsigned long milliseconds)
{
char answer_check [3];
String result;
char result_char[50];
Serial.print("Sending: ");
Serial.println(toSend);
fonaSS.println(toSend);
unsigned long startTime = millis();
Serial.print("Received: ");
while (millis() - startTime < milliseconds)
{
if (fonaSS.available())
{
char c = fonaSS.read();
Serial.write(c);
result += c; // append to the result string
result.toCharArray(result_char, 50);
if(strcasestr(result_char,toCheck1) || strcasestr(result_char,toCheck2))
{
milliseconds = 0;
} // end of if(strcasestr(result_char,toCheck1) || strcasestr(result_char,toCheck2))
} // if (fonaSS.available())
} // end of while (millis() - startTime < milliseconds)
Serial.println(); // new line after timeout.
return result;
} // end of string
Code: Select all
void sendPHP() //magic number sent as part of the string temporarily
{
// *********************************
// Notes on the AT command functions
// sendReceiveATCommand function send a command to 3G module and only expect for a defined time and waits for the result.
// sendReceiveATCommand2 function send a command to 3G module and compare the result to a given string, when there's a match it stops waiting.
// *********************************
//Send URL Request
Serial.println("\r\nChecking that things are set up now...\r\n");
sendReceiveATCommand("AT+CREG?",2000);
delay(1000);
sendReceiveATCommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", 4000); // Internet is for the optus WAN
Serial.println("\r\nStarting to send commands...\r\n");
sendReceiveATCommand2("AT+CHTTPACT=\"my.sqlserver\",80", "\r\n+CHTTPACT: REQUEST","\r\nERROR", 5000);
delay(100);
Serial.print("GET /mysqlserver.php?ID=");
Serial.print("AssetID");
Serial.print("&PH=");
Serial.print("UserPhoneNumber");
Serial.print(" HTTP/1.1\r\n");
fonaSS.print("GET /mysqlserver.php?ID=");
fonaSS.print("AssetID");
fonaSS.print("&PH=");
fonaSS.print("UserPhoneNumber");
fonaSS.print(" HTTP/1.1\r\n");
delay(100);
Serial.print("Host: my.sqlserver\r\n");
fonaSS.print("Host: my.sqlserver\r\n");
delay(100);
Serial.print("Connection: close\r\n\r\n");
fonaSS.print("Connection: close\r\n\r\n");
delay(100);
fonaSS.write(0x1A);
delay(100);
} // end of sendPHP
- gerrit
- Posts: 21
- Joined: Tue Nov 08, 2016 6:17 am
Re: HTTPS POST/GET ?
Before you use https I believe you need to upload the corresponding SSL certificate. I don't know if the chip as any preinstalled.
- PabloOyarzo
- Posts: 36
- Joined: Sat Mar 01, 2014 7:42 am
Re: HTTPS POST/GET ?
That's my understanding thus far, but I haven't been able to make it work yet. Specially with the Key filegerrit wrote:Before you use https I believe you need to upload the corresponding SSL certificate. I don't know if the chip as any preinstalled.
- PabloOyarzo
- Posts: 36
- Joined: Sat Mar 01, 2014 7:42 am
Re: HTTPS POST/GET ?
The solution I saw on that post used only HTTP, not HTTPSsmgs wrote:You can try these simple Arduino sketches out, check out the "Programming help needed thread..." it has lots of http and https stuff in it.
an example on calling those AT command functions:Code: Select all
////////////////////////////////////////////////////// // sendReceiveATCommand function send a command to 3G module and only expect for a defined time and waits for the result. String sendReceiveATCommand(const char *toSend, unsigned long milliseconds) { String result; Serial.print("Sending: "); Serial.println(toSend); fonaSS.println(toSend); unsigned long startTime = millis(); Serial.print("Received: "); while (millis() - startTime < milliseconds) { if (fonaSS.available()) { char c = fonaSS.read(); Serial.write(c); result += c; // append to the result string } // end of if (fonaSS.available()) } // end of while (millis() - startTime < milliseconds) Serial.println(); // new line after timeout. return result; } // end of string ////////////////////////////////////////////////////// // sendReceiveATCommand2 function send a command to 3G module and compare the result to a given string, when there's a match it stops waiting. String sendReceiveATCommand2(const char *toSend, const char *toCheck1, const char *toCheck2, unsigned long milliseconds) { char answer_check [3]; String result; char result_char[50]; Serial.print("Sending: "); Serial.println(toSend); fonaSS.println(toSend); unsigned long startTime = millis(); Serial.print("Received: "); while (millis() - startTime < milliseconds) { if (fonaSS.available()) { char c = fonaSS.read(); Serial.write(c); result += c; // append to the result string result.toCharArray(result_char, 50); if(strcasestr(result_char,toCheck1) || strcasestr(result_char,toCheck2)) { milliseconds = 0; } // end of if(strcasestr(result_char,toCheck1) || strcasestr(result_char,toCheck2)) } // if (fonaSS.available()) } // end of while (millis() - startTime < milliseconds) Serial.println(); // new line after timeout. return result; } // end of string
Code: Select all
void sendPHP() //magic number sent as part of the string temporarily { // ********************************* // Notes on the AT command functions // sendReceiveATCommand function send a command to 3G module and only expect for a defined time and waits for the result. // sendReceiveATCommand2 function send a command to 3G module and compare the result to a given string, when there's a match it stops waiting. // ********************************* //Send URL Request Serial.println("\r\nChecking that things are set up now...\r\n"); sendReceiveATCommand("AT+CREG?",2000); delay(1000); sendReceiveATCommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", 4000); // Internet is for the optus WAN Serial.println("\r\nStarting to send commands...\r\n"); sendReceiveATCommand2("AT+CHTTPACT=\"my.sqlserver\",80", "\r\n+CHTTPACT: REQUEST","\r\nERROR", 5000); delay(100); Serial.print("GET /mysqlserver.php?ID="); Serial.print("AssetID"); Serial.print("&PH="); Serial.print("UserPhoneNumber"); Serial.print(" HTTP/1.1\r\n"); fonaSS.print("GET /mysqlserver.php?ID="); fonaSS.print("AssetID"); fonaSS.print("&PH="); fonaSS.print("UserPhoneNumber"); fonaSS.print(" HTTP/1.1\r\n"); delay(100); Serial.print("Host: my.sqlserver\r\n"); fonaSS.print("Host: my.sqlserver\r\n"); delay(100); Serial.print("Connection: close\r\n\r\n"); fonaSS.print("Connection: close\r\n\r\n"); delay(100); fonaSS.write(0x1A); delay(100); } // end of sendPHP
- gerrit
- Posts: 21
- Joined: Tue Nov 08, 2016 6:17 am
Re: HTTPS POST/GET ?
To start an HTTP connection you need the following command
the port is either 443 for HTTPS or 80 for HTTP and HTTPSon is 2 for HTTPS and 1 for HTTP.
host would the url.
Code: Select all
"AT+CHTTPSOPSE=\"" + host + "\"," + port + ',' + HTTPSon;
host would the url.
Please be positive and constructive with your questions and comments.