Auto connect to blynk ((gsm))

Hi
Friends. I want to automatically when access to the system is lost. Reconnect to the system

I use sim800 and esp32

*I am currently successfully connecting to the network in a stup . But once the network is down, I can not reconnect to the network

I want it when my connection to the GSM network is lost and I do not have access to Blynk. Automatically connect to GSM and Blynk after a few minutes

my cod

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPL32RWKy1E"
#define BLYNK_DEVICE_NAME "GSM"
#define LED 10

// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE

// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "skD_QKoTMfn2KJobfnIoeyVoKRGAzO-E";

// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[]  = "mtnirancell";
char user[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(9,8); // RX, TX
//RX sim800 conecct to 8
//TX sim800 conecct to 9
TinyGsm modem(SerialAT);

BLYNK_WRITE(V0){ 
  int pinvalue=param.asInt();
  digitalWrite(LED,pinvalue);
  }
void setup()
{

  
  pinMode(LED,OUTPUT);
  digitalWrite(LED,HIGH);
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  modem.restart();

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  Blynk.begin(auth, modem, apn, user, pass);
}

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

Thanks.

I don’t think you’re going to get much assistance until you provide the basic information that was requested when you created this topic, such as whether you are using Blynk Legacy or Blynk IoT, and the code that you are running in your ESP32.

Pete.

1 Like

I put the code in the first message.

I want it to be detected by the microcontroller when the GSM network connection is lost.
And run SETUP commands again

Blynk IoT then I guess?

Blynk.begin is a blocking command, and the code won’t progress beyond this point if it cant establish a GSM connection or a connection to the Blynk server.

I’d suggest that you manually establish your GSM connection then use Blynk.config and Blynk.connect to establish your connection to the Blynk server.
This will have the advantage of attempting to re-connecting to Blynk whenever the Blynk.run command is encountered and there is no connection already.

If you search the forum then you’ll find examples of how to do this. Examples designed for Blynk Legacy will need blynk-cloud.com to be replaced with blynk.cloud if indeed you are using Blynk IoT.

If your real problem is that the GSM connection is being dropped then you may need to add a timed function that checks the status of the connection and re-connects if needed.

Pete.