[SOLVED] TTGO T-Call - Help with reconnecting

I have searched the forum and found some info but I am not very sure about it and that is why I am creating this topic. I am using a TTGO T-Call (SIM800) board and I found an example sketch that works with Blynk, however when GPRS disconnects it does not reconnect and this where I need help.

Example sketch by manufacturer (without Blynk) - https://github.com/Xinyuan-LilyGO/TTGO-T-Call/blob/master/examples/Arduino_TinyGSM/Arduino_TinyGSM.ino

Example sketch which works with Blynk but does not reconnect on disconnect - https://github.com/Xinyuan-LilyGO/TTGO-T-Call/blob/e38c71e9756bb643192283c0488a5b3d69042eea/examples/Blynk_App/Blynk_App.ino

  1. I was under the impression that Blynk handles the reconnect part, am I wrong?
  2. I assume the example Blynk sketch is failing to reconnect because GPRS is connected in the setup() function, shouldnt Blynk.run() in the loop() function handle the disconnect and reconnect as needed?
  3. How do I modify the sketch to get the board to reconnect when it disconnects?

Thanks for any help!

Edit - The steps listed below didn’t work :confused:

Will something like this help?

  1. Adding a timer in setup() - timer.setInterval(5000L, checkGPRS);
  2. Include in loop() - timer.run();
  3. Add the function,
    void checkGPRS()
    {
    	if (!modem.gprsConnect(apn, user, pass)) {
    		modem.gprsConnect(apn, user, pass);
    	}
    }

Is there any other way to get Blynk to handle the process?

Seems like the example sketch posted on Gitthub’s pull request had some unnecessary code. I cleaned what was not needed and added a function to reconnect GPRS when disconnected. In order to test it just send any data to Virtual Pin 5 once the hardware is connected to Blynk, it should disconnect the GPRS and then the checkGPRS() function should reconnect. Posting the code below for anyone who needs it,

utilities.h can be found from - https://github.com/Xinyuan-LilyGO/TTGO-T-Call/blob/master/examples/Arduino_TinyGSM/utilities.h

// TTGO T-Call pin definitions
#define MODEM_RST            5
#define MODEM_PWKEY          4
#define MODEM_POWER_ON       23
#define MODEM_TX             27
#define MODEM_RX             26
#define I2C_SDA              21
#define I2C_SCL              22
// Other define
#define BLYNK_PRINT Serial    
#define TINY_GSM_MODEM_SIM800

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1

// Include
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <Wire.h>
#include "utilities.h"

// Vars
const char apn[]  = "";
const char user[] = "";
const char pass[] = "";
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "";

TinyGsm modem(SerialAT);
BlynkTimer timer;

// For testing purpose, remove if not needed
BLYNK_WRITE(V5) {
  modem.gprsDisconnect();
}


void checkGPRS()
{
  SerialMon.println("GPRS check running");

  if (!modem.isGprsConnected()) {
    if (!modem.gprsConnect(apn, user, pass)) {
      delay(10000);
      return;
    }
  }
}


void setup()
{
  // Set console baud rate
  SerialMon.begin(115200);
  delay(10);

  // Keep power when running from battery
  Wire.begin(I2C_SDA, I2C_SCL);
  bool   isOk = setPowerBoostKeepOn(1);
  SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));

  // Set-up modem reset, enable, power pins
  pinMode(MODEM_PWKEY, OUTPUT);
  pinMode(MODEM_RST, OUTPUT);
  pinMode(MODEM_POWER_ON, OUTPUT);

  digitalWrite(MODEM_PWKEY, LOW);
  digitalWrite(MODEM_RST, HIGH);
  digitalWrite(MODEM_POWER_ON, HIGH);

  // Set GSM module baud rate and UART pins
  SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
  delay(3000);

  Blynk.begin(auth, modem, apn, user, pass);
  
  // For GPRS reconnect
  timer.setInterval(10000L, checkGPRS);
  
}


void loop()
{
  Blynk.run();
  timer.run();
}