Can’t stay connected to Blynk server

I am trying to connect my Arduino Nano to Blynk server using sim800. But in Arduino serial monitor it shows this message and it does not exit Blynk.begin(); command to continue executing commands and shows online device in software. I have attached the images below, please help me.

TinyGSM lib version : 0.12.0
Blynk lib version : 1.3.2

This is my code:

#define BLYNK_TEMPLATE_NAME "xxxxxxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxx"

#define TINY_GSM_MODEM_SIM800
#define BLYNK_PRINT Serial
#define BLYNK_HEARTBEAT 30

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

char apn[] = "mcinet";
char user[] = "";
char pass[] = "";

SoftwareSerial sim800Serial (5, 4); // RX, TX

TinyGsm modem(sim800Serial);
BlynkTimer timer;

float sensorTemperature = 20.50;
#define VIRTUAL_PIN_Temp V1


void setup() {
 Serial.begin(9600);
sim800Serial.begin(9600);
modem.restart();
Blynk.begin(BLYNK_AUTH_TOKEN,modem,apn,user,pass);
timer.setInterval(10000L,sendFloatData);
}

void sendFloatData(){
  if(Blynk.connected()){
  sensorTemperature = sensorTemperature + 0.15;
  if(sensorTemperature>35.0){
    sensorTemperature=20.5;
  }
  }
  Blynk.virtualWrite(V1,sensorTemperature);
  Serial.print("sending temp: ");
  Serial.print(sensorTemperature,2);
}

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

monitor serial:

[17282] Connecting to mcinet ...

[23683] Connected to GPRS

[23755] Connecting to blynk.cloud:80

[26316] Redirecting to fral.blynk.cloud:80

[26408] Connecting to fral.blynk.cloud:80

[33196] Ready (ping: 350ms).

[40352] Connecting to fral.blynk.cloud:80

[100260] Connecting to fral.blynk.cloud:8080

[106206] Connecting to fral.blynk.cloud:80

[107610] Ready (ping: 358ms).

[114766] Connecting to fral.blynk.cloud:80

[175304] Connecting to fral.blynk.cloud:8080

[181316] Connecting to fral.blynk.cloud:80

[182902] Ready (ping: 536ms).

[190057] Connecting to fral.blynk.cloud:80

@Mostafa78 Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

I would also suggest that you replace the screenshot of your serial monitor output with the copied/pasted text from your serial monitor, once again with triple backticks at the beginning and end.

Pete.

I made the changes mentioned in the post. Please help me modify the program so that the loop becomes void.

I made the changes mentioned in the post. Please help me modify the program so that the loop becomes void.

Your long ping times indicate that you’re probably not getting a great signal for your GPRS module, you should consider adding an external antenna.

How are you powering your SIM800? The module can draw up to 2 amps when transmitting, so you may be having dropouts due to low power.

This if test is redundant, and may also be causing issues…

Pete.

In the tests I took, the signal quality of the module was 22 and also in the SMS test, the module works properly.

So I use the sim808 module shield, which itself has an lm2576 power regulator and its input is a 12V 4A adapter.

The module does not restart and the indicator light flashes 3 times per second correctly, indicating a connection to GPRS.

Is this problem caused by high ping?

What should the ping rate be to pass this command?

Is there a way to work with this ping rate?

Ping times in the hundreds of milliseconds tend to indicate that there is a GPRS coverage or signal strength issue.

Which country is this device operating in, and how long does your mobile ISP intend to continue 2G coverage?

Pete.

Iran and my operator offer 2G platform.

Can I take steps in the software to reduce ping, for example, if I can connect to an Asian server? How?

Your Blynk account is linked to one server, in your case it appears to be Fra1 which is located in Frankfurt.

You can’t change that, the only way would be to create a new Blynk account and try to force that to be on the Bangalore server Bir1.

Doing that would give you a “new style” Blynk free account, which is limited to 30,000 messages per month.
Your current code attempts to send a reading every 10 seconds, which would use-up around 8,640 messages per day, so the 30,000 message limit would be fully used-up after less than 3.5 days.

Pete.

So if it is connected, why doesn’t it exit the blynk.begin command to execute the rest of the program’s commands?
My problem is exactly this: this blynk.begin command keeps repeating.

From the limited information you’ve posted, the device is sometimes connecting to the Blynk server and the void loop is executing in those situations, but it is disconnecting before the BlynkTimer your sendFloatData function is called.
You can prove this by placing a Serial.print command in your void loop.

Turning-on timestamps in your void loop would help you (and others) to understand the timings better.

Pete.

Unfortunately, even with the timer section removed, the program remains at the blynk.begin(); command and does not exit.
Is there another command I can use instead of blynk.begin(); so that it exits the command once it connects and runs the rest of the commands? I saw somewhere that blynk.config(); commands were used. If possible, please give me an example of the inputs to this command.

I wasn’t suggesting that you “remove the timer section”.
Have you done what I suggested to verify that when you see a ping time in your serial monitor the void loop is executing, and enabling timestamps?

Yes, you could use Blynk.config(), but the only way that will help is to display readings in the serial monitor even if the device can’t connect to Blynk.

Here’s an example of using Blynk.config()…

But you’d need to change the default connection timeout, and prevent Blynk.run() from executing if Blynk.connected() is false. An example and discussion is here….

Pete.