I have been trying to make an HTTPs request with the SIM A7672X module using the tinyGSM lib but am having issues, i was following the example from: randomnerdtutorials with minor modifications as we use a different SIMCOM model, below is my code:
#include <Arduino.h>
#define TINY_GSM_MODEM_A7672X
// #define TINY_GSM_MODEM_SIM7000SSL
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
#define SerialAT Serial0
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>
#define TINY_GSM_DEBUG SerialMon
const char apn[] = "internet.ng.airtel.com";
// const char apn[] = "web.gprs.mtnnigeria.net";
const char gprsUser[] = "";
const char gprsPass[] = "";
// Server details
const char server[] = "gist.githubusercontent.com";
const char resource[] = "/RuiSantosdotme/7db8537cef1c84277c268c76a58d07ff/raw/d3fe4cd6eff1ed43e6dbd1883ab7eba8414e2406/gistfile1.txt";
const int port = 443;
// const int port = 80;
TinyGsm modem(SerialAT);
TinyGsmClientSecure client(modem);
HttpClient http(client, server, port);
#define UART_BAUD 115200
#define PIN_TX RX
#define PIN_RX TX
void setup()
{
// Set Serial Monitor baud rate
SerialMon.begin(115200);
delay(10);
SerialMon.println("Wait...");
// Set GSM module baud rate and Pins
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
delay(6000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
// modem.restart();
// modem.init();
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);
Serial.println("Make sure your LTE antenna has been connected to the SIM interface on the board.");
delay(5000);
}
void loop()
{
modem.gprsConnect(apn, gprsUser, gprsPass);
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork())
{
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" success");
if (modem.isNetworkConnected())
{
SerialMon.println("Network connected");
}
SerialMon.print(F("Performing HTTPS GET request... "));
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
int err = http.get(resource);
if (err != 0)
{
SerialMon.println(F("failed to connect"));
delay(10000);
return;
}
int status = http.responseStatusCode();
SerialMon.print(F("Response status code: "));
SerialMon.println(status);
if (!status)
{
delay(10000);
return;
}
SerialMon.println(F("Response Headers:"));
while (http.headerAvailable())
{
String headerName = http.readHeaderName();
String headerValue = http.readHeaderValue();
SerialMon.println(" " + headerName + " : " + headerValue);
}
int length = http.contentLength();
if (length >= 0)
{
SerialMon.print(F("Content length is: "));
SerialMon.println(length);
}
if (http.isResponseChunked())
{
SerialMon.println(F("The response is chunked"));
}
String body = http.responseBody();
SerialMon.println(F("Response:"));
SerialMon.println(body);
SerialMon.print(F("Body length is: "));
SerialMon.println(body.length());
// Shutdown
http.stop();
SerialMon.println(F("Server disconnected"));
modem.gprsDisconnect();
SerialMon.println(F("GPRS disconnected"));
// Do nothing forevermore
while (true)
{
delay(1000);
}
}
and bellow is the output from the serail monitor:
Initializing modem...
Modem Info: ATI Manufacturer: INCORPORATED Model: A7672E-FASE Revision:
A7672M7_V1.11.1 IMEI: 867255079839140 +GCAP: +CGSM,+FCLASS,+DS
Make sure your LTE antenna has been connected to the SIM interface on the board.
Waiting for network... success
Network connected
Performing HTTPS GET request... failed to connect
3