Skip to content

Commit

Permalink
Update HTTPS example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 6, 2024
1 parent 425de1f commit 6950818
Showing 1 changed file with 54 additions and 22 deletions.
76 changes: 54 additions & 22 deletions examples/HttpsBuiltlnGet/HttpsBuiltlnGet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ TinyGsm modem(debugger);
TinyGsm modem(SerialAT);
#endif

// It depends on the operator whether to set up an APN. If some operators do not set up an APN,
// It depends on the operator whether to set up an APN. If some operators do not set up an APN,
// they will be rejected when registering for the network. You need to ask the local operator for the specific APN.
// APNs from other operators are welcome to submit PRs for filling.
// #define NETWORK_APN "CHN-CT" //CHN-CT: China Telecom

const char *server_url = "https://httpbin.org/get";
const char *request_url[] = {
"https://httpbin.org/get",
"https://vsh.pp.ua/TinyGSM/logo.txt",
"https://ipapi.co/json"
};

void setup()
{
Expand Down Expand Up @@ -164,30 +168,58 @@ void setup()
// Initialize HTTPS
modem.https_begin();

// Set GET URT
if (!modem.https_set_url(server_url)) {
Serial.println("Failed to set the URL. Please check the validity of the URL!");
return;
}
// If the status code 715 is returned, please see here
// https://github.com/Xinyuan-LilyGO/LilyGO-T-A76XX/issues/117

// Send GET request
int httpCode = 0;
httpCode = modem.https_get();
if (httpCode != 200) {
Serial.print("HTTP get failed ! error code = "); Serial.println(httpCode); return;
}
for (int i = 0; i < sizeof(request_url) / sizeof(request_url[0]); ++i) {

// Get HTTPS header information
String header = modem.https_header();
Serial.print("HTTP Header : ");
Serial.println(header);
int retry = 3;

delay(5000);
while (retry--) {

Serial.print("Request URL : ");
Serial.println(request_url[i]);

// Set GET URT
if (!modem.https_set_url(request_url[i])) {
Serial.print("Failed to request : "); Serial.println(request_url[i]);

// Debug
// modem.sendAT("+CSSLCFG=\"enableSNI\",0,1");
// modem.waitResponse();
delay(3000);
continue;
}

// Send GET request
int httpCode = 0;
httpCode = modem.https_get();
if (httpCode != 200) {
Serial.print("HTTP get failed ! error code = ");
Serial.println(httpCode);
delay(3000);
continue;
}

// Get HTTPS header information
String header = modem.https_header();
Serial.print("HTTP Header : ");
Serial.println(header);

// Get HTTPS response
String body = modem.https_body();
Serial.print("HTTP body : ");
Serial.println(body);
delay(1000);

// Get HTTPS response
String body = modem.https_body();
Serial.print("HTTP body : ");
Serial.println(body);

delay(3000);

break;
}

Serial.println("-------------------------------------");
}
}

void loop()
Expand Down

0 comments on commit 6950818

Please sign in to comment.