Blynk via GSM Fails to Connect

I am currently trying to get Blynk working over a cellular connection. I am using a Arduino Mega 2560 with a Botletics SIM7000A shield. So far, my program is a spitting image of the TinyGSM BlynkClient example except for some changes made based on the Botletics LTE_Demo program. The Botletics example sets the baud rate of the SIM7000A to 9600, so I used the commands in the TinyGSM library to make the same changes. I am using the newest Blynk library version, v1.1.0. The program progresses through the startup commands at a painfully slow pace, and then appears to aquire connection. The program then passes off to Blynk, which starts up, but then crashes. My first hint that something was not right was that the getModemInfo() function returned nothing in the console print. Secondly, after the Blynk logo is printed to the console, I get a few lines of blank space, and then the program reattempts to connect to the GSM board, states that it cannot initialize the GSM board, and resets the board.

Console Output:
image

The program then repeats itself and retries to connect, over and over, repeating this same printout. Are the codes before and after the Blynk logo error codes? If so, is there a refrence someone can point me to for decoding?

The Botletics example program changes the baud rate to 9600 because of the limitations of software serial (per Botletics), so I continued that practice in my program. I see that the TinyGSM program does uses hardware serial for the Mega, which therefore can handle the 115200 baud rate, so my best guess is that something isn’t happy with the new 9600 baud rate in either the TinyGSM library, the actual SIM7000 chip, or the means of which attempt to change the baud rate. For reference, the default baud rate of the SIM7000A is 115200.

Here is my program:

#define TEST_LED 53   // pin for test LED

// Console Settings:
#define BAUD_RATE 9600    // baud rate for Botletics & statup info
#define SerialMon Serial

// Blynk Settings
#define BLYNK_TEMPLATE_ID "****************"
#define BLYNK_DEVICE_NAME "***************"
#define BLYNK_AUTH_TOKEN  "***************"
#define BLYNK_FIRMWARE_VERSION        "1.1.0"
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

#define SIMCOM_7000
#define TINY_GSM_MODEM_SIM7000
#define SerialAT Serial1

// For botletics SIM7000 shield
#define BOTLETICS_PWRKEY 6
#define RST 7
#define TX 10 // Microcontroller RX
#define RX 11 // Microcontroller TX

/////////////////////////////////////////////////////////
// Preprocessor Files:
/////////////////////////////////////////////////////////
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <SoftwareSerial.h>

////////////////////////////////////////////////////////////
// Global Vars
////////////////////////////////////////////////////////////
volatile bool ledCommand = false;
const char apn[]  = "hologram";
const char user[] = "";
const char pass[] = "";
const char auth[] = BLYNK_AUTH_TOKEN;

////////////////////////////////////////////////////////////
// Instance Declarations
////////////////////////////////////////////////////////////
//BlynkTimer timer;                                           // timer created for handing IoT data transfer freq
//SoftwareSerial SerialAT(TX, RX);                  // SW serial for modem comms
TinyGsm modem(SerialAT);                             // init modem

////////////////////////////////////////////////////////////
// Application Startup Tasks
////////////////////////////////////////////////////////////
void setup() {

  SerialMon.begin(BAUD_RATE);               // set baud rate for Console

  // turn on GSM modem
  SerialMon.println("Turn on modem...");  
  pinMode(RST, OUTPUT);
  digitalWrite(RST, HIGH); // Default state
  pinMode(BOTLETICS_PWRKEY, OUTPUT);
  digitalWrite(BOTLETICS_PWRKEY, LOW);
  delay(1100); // At least 1s, per botleticsSIM7000.h
  digitalWrite(BOTLETICS_PWRKEY, HIGH);
  delay(4000);
  SerialMon.println("Modem On");
  SerialAT.begin(115200); // Default SIM7000 shield baud rate
  modem.restart();
  SerialMon.println("Modem Restart");
  modem.factoryDefault();
  SerialMon.println("Factory Default");

  // set GSM baud rate
  SerialMon.println("Configuring to 9600 baud");
  modem.setBaud(9600);
  delay(100); // Short pause to let the command run
  SerialAT.begin(BAUD_RATE);
  delay(6000);

  // init modem
  SerialMon.println("Initializing modem...");
  modem.restart();
  SerialMon.println("Wait for Net...");
  modem.waitForNetwork(300000L);  // 30s timeout

  //get modem info
  String modemInfo = modem.getModemInfo();
  Serial.print("Modem Info: ");
  Serial.println(modemInfo);
  delay(2000);

  // connect to Blynk
  Serial.println("Connecting to Blynk...");
  Blynk.begin(auth, modem, apn, user, pass);

  // Setup Test LED           
  pinMode(TEST_LED, OUTPUT);       // enable as output
  digitalWrite(TEST_LED, LOW);     // turn off

}// End Application Startup Tasks
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Application Run Tasks
////////////////////////////////////////////////////////////
void loop() {
  // ACTIONS THAT ARE CONTINUOUS
  Blynk.run();
}// End Application Run Tasks
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Function Declarations
////////////////////////////////////////////////////////////
// Function called every time the light button changes virtual pin V0 (LightVirtual)
BLYNK_WRITE(V0)         
{
  ledCommand = param.asInt(); // assigns value to ledCommand
  digitalWrite(TEST_LED, ledCommand);
}

I can connect to the internet using the Botletics demo program without issue, and in roughly 1/10th the time the TinyGSM program takes to connect to Blynk. Anything I am missing that could be causing this?

Here is the SIM7000A board I am using, and the example program that is working correctly:
Botletics Example
Botletics Home

And the TinyGSM example:
TinyGSM Blynk

Just a note; the TinyGSM example also crashes the same way, which I originally thought was an issue with not sending a on/off/reset command to the SIM7000A and also using the 115200 baud rate. The only difference is the codes around the Blynk logo. See the picture below for reference.
image

Any help is greatly appreciated, thanks in advance

These should be at the VERY TOP of your sketch.

Pete.

Pete, I always appreciate the fast response and your expertise. I moved all the Blynk settings to line #1, but had the exact same results as I expected. With all due respect, I doubted that three other #defines prior to the Blynk settings would cause these issues. If I am flat out wrong, show me, as I am still new to this, but have had multiple projects run without issue with the Blynk #defines in a similar placement.
image

After messing with this some more, it looks like the TinyGSM format/library is not compatible with how the Botletics board is setup or the SIM7000A at all, as the TinyGSM Blynk host does not actually preform any of the necessary AT commands to get the Botletics board online. If anyone has gotten that example to work with the Botletics SIM7000A board, I’d really appreciate hearing how you did it and what modifications were needed. For now, I am going Frankenstein the Botletics example to port a connection to Blynk instead of trying to modify the TinyGSM library to fit my needs.

I really appreciate the extra sets of eyes making sure I didn’t just miss something simple in my program. Thanks again,

It’s all about how the Blynk library parses the code to decide which server to try to connect to.
If you’re having problems and you don’t have these three lines of code at the top of your sketch then that’s the first thing to check…

Pete.