Faced problem after continuous running in 15 to 30 hours

I have build a project for switching on and off two relay that is used in my father’s agriculture pumps, it is running fine but after continuous running of 15 to 30 hours it stop working showing offline until I restart or reset.
I have used TTGO T call for this project and below is program code:-

#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

#define BLYNK_PRINT Serial    

#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

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

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial

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

const char apn[]  = "airtelgprs.com";
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[] = "my auth key pasted here";

TinyGsm modem(SerialAT);

//me below
#define PIN_UPTIME V5
  Blynk.virtualWrite(PIN_UPTIME, millis() / 60000);
#define Pin_pump            13

   Blynk.virtualWrite(V6, !digitalRead(Pin_pump));

  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  digitalWrite(Pin_pump, pinValue);
#define Pin_pump_t           14

   Blynk.virtualWrite(V16, !digitalRead(Pin_pump_t));
  int pinVal = param.asInt(); // assigning incoming value from pin V2 to a variable
  digitalWrite(Pin_pump_t, pinVal);

void setup()

  // Set console baud rate

  // 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

  digitalWrite(MODEM_PWKEY, LOW);
  digitalWrite(MODEM_RST, HIGH);
  digitalWrite(MODEM_POWER_ON, HIGH);
  pinMode(Pin_pump, OUTPUT);
  pinMode(Pin_pump_t, OUTPUT);

  digitalWrite(Pin_pump, HIGH);
  digitalWrite(Pin_pump_t, HIGH);

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

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

  String modemInfo = modem.getModemInfo();
  SerialMon.print("Modem: ");

  // Unlock your SIM card with a PIN

   SerialMon.print("Waiting for network...");
  if (!modem.waitForNetwork(240000L)) {
    SerialMon.println(" fail");
  SerialMon.println(" OK");

  if (modem.isNetworkConnected()) {
    SerialMon.println("Network connected");

  SerialMon.print(F("Connecting to APN: "));
  if (!modem.gprsConnect(apn, user, pass)) {
    SerialMon.println(" fail");
  SerialMon.println(" OK");

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

void loop()

and now here is program for utilities.h below:-

#define IP5306_REG_SYS_CTL0  0x00

bool setPowerBoostKeepOn(int en)
  if (en) {
    Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
  } else {
    Wire.write(0x35); // 0x37 is default reg value
  return Wire.endTransmission() == 0;

One more thing I want to add when the problem occurred I verified network connection was okay by calling inserted sim.
Please guide for resolving issue.
Thank You.

somebody please help on this @PeteKnight @Dmitriy

Please don’t tag the Blynk developers in posts like this, if you persist then your account will be suspended.
As your query is regarding Blynk Legacy, then the developers won’t help anyway, as the product is no longer supported.

What does your serial monitor show when a disconnection event occurs?


1 Like

I am sorry for tagging you.
I have not connected pc permanently so serial Monitor data not available. Since this problem occurred random after 15 to 30 hours.

I am not from core programming branch, I am Electrical Engineer so little difficult to find solution.
But I have alternative solution to reset board using sms which can fulfill my requirements.
Someone please guide me to add sms reset or call reset(software reset) in this program.

The problem seems to be in your GPRS connection. It checked only once at start of the device. Why don’t you try to set watchdog timer + blynk timer and check your connection, say, once a minute. In case of GPRS fail (or any other Blynk network connection fail, set by timer rules) your device could reset GSM connection or reset itself completely.

Thanks @Alegz
You are right, could you please guide for coding for the same.

I’m not familiar with SIM800 modem. I’m using Ai-Thinker A9G based Pudding GSM/GPRS board. So, just an explanation, not an exact guide.

in micropython code it looks like this:

machine.watchdog_on(60)  #setting up watchdog timer for 60 seconds

def send_data: #block which receive/send some data once a minute by blynk timer
get some data

#send data to server
    cellular.gprs("internet", "", "")  #check whether gprs connection is ON 
#(actually - command to connect to gprs network. If already connected - return message "connected")
except Exception as e:
            print(0, 'Exception:\n  ' + repr(e) )#print explanation of error

        r = urequests.get(url + token + "update/V14?value=0&value=" + str(lat) + "&value=" + str(lon) + "&value=GPS") #send HTTP request to blynk server using API
        if r.status_code == 200:
            print("Blynk OK") #if sent - everything is OK
            machine.watchdog_reset() #reset watchdog
            print(r.status_code, r.text) #if not - print what's wrong

except Exception as e:
            print(0, 'Exception:\n  ' + repr(e))  # print explanation of error


So, watchdog timer is set to 60 seconds. If data is not send or received during this period due to network error or some other reason like endless loop, watchdog timer can’t get reset and the MCU will reset completely. It is not perfect code because A9G is a new toy for me and I’m still playing with it for about a month. However it is work for me.

I do not know whether your MCU support watchdog timer, so refer to yor device’s code examples. E.g. you can try to check if blynk server is connected instead of check gprs network, if not - reset your modem and reconnect blynk.

Thanks @Alegz

hi brother. how you can use “#include <BlynkSimpleSIM800.h”?? My program keeps getting an error when compiling.

@kiloalfa45 instead of tagging one line comments onto existing topics, I’d suggest that you create a new “need help with my project” topic and explain in full the hardware you are using, the sketch you are using and exact errors or issues that you are encountering, along with details of which version of Blynk you are using.