Skip to content

Instantly share code, notes, and snippets.

@kiddtang
Last active June 27, 2021 07:23
Show Gist options
  • Save kiddtang/c50d03ff3b6eca6a75ab72d603f10e2a to your computer and use it in GitHub Desktop.
Save kiddtang/c50d03ff3b6eca6a75ab72d603f10e2a to your computer and use it in GitHub Desktop.
SIM7600x samples
#if TINY_GSM_TEST_TCP && defined TINY_GSM_MODEM_HAS_TCP
if (!modem.isGprsConnected()) {
DBG("... not connected");
} else {
DBG("Connecting to ", server);
// Make a HTTPS GET request:
Serial.println("Making GET request securely...");
client.get(resource);
int status_code = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(status_code);
Serial.print("Response: ");
Serial.println(response);
client.stop();
}
#endif
#if TINY_GSM_TEST_TCP && defined TINY_GSM_MODEM_HAS_TCP
// Retrieve Time
String time;
do {
time = modem.getGSMDateTime(DATE_FULL).substring(0, 17);
delay(100);
} while (!time);
DBG("Current Network Time:", time);
// Retrieve Temperature
float temp;
do {
temp = modem.getTemperature();
delay(100);
} while (!temp);
DBG("Modem Temp:", temp);
if (!modem.isGprsConnected()) {
DBG("... not connected");
} else {
DBG("Connecting to ", server);
// Make a HTTPS POST request:
Serial.println("Making POST request securely");
String contentType = "Content-Type: application/json";
String postData = "{\"time\": \""+ time + "\", \"temp\": \"" + temp + "\"}";
client.post(resource, contentType, postData);
int status_code = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(status_code);
Serial.print("Response: ");
Serial.println(response);
client.stop();
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment