Sim900 + Uno disconnection

I set up Sim900 and Uno to send data to Blynk.
It gets connection and disconnects a lot of times within a minute.
O obseved latency When connected about 900 ms.
I used the code proposed in Blynk library with serialsoftware.
In Blynk dashboard, data are not displayed frequently updated, but hardware is shown on line.
Any help from somebody would be great.
TKS.
Gilmar Oliveira _ Brazil

It is necessary to watch your code


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

// 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 <BlynkSimpleSIM800.h>
#define TINY_GSM_MODEM_SIM900   
char auth[] = "xxxxxxxxxx";

// Your GPRS credentials
// Leave empty, if missing user or pass

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

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

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2,3); // RX, TX

TinyGsm modem(SerialAT);

#include <SimpleTimer.h>
SimpleTimer timer;

WidgetLED led13(V0); 

int iLevelRaw;
int iLevelNorm;

void setup()
{
   timer.setInterval(5000L, sendUptime_1_0);    //LIVE LED
   timer.setInterval(10000L, sendUptime_2_0);   //Send data
   timer.setInterval(2000L, sendUptime_3_0);    //Read A0
    
  // Set console baud rate
  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()
  modem.restart();
  // Unlock your SIM card with a PIN
  //modem.simUnlock("8486");

   Blynk.begin(auth, modem, apn, user, pass);
}
void sendUptime_1_0() 
{
  if (led13.getValue()) 
  {
    led13.off();
   // digitalWrite(13,LOW); 
  } else 
  {
    led13.on();
  //  digitalWrite(13,HIGH);
  } 
}

void sendUptime_2_0() 
{
 Blynk.virtualWrite(V1, long(iLevelRaw));
 Blynk.virtualWrite(V2, long(iLevelNorm));
}

void sendUptime_3_0() 
{
 iLevelRaw = analogRead(A0); 
 iLevelNorm  = map(iLevelRaw, 0, 1023, 0, 100);  
}

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

I am using Blynk v0.4.6

Status of conncetion ae as follows:
[11767] Modem init…
[12576] Connecting to network…
[15148] Network: VIVO
[15148] Connecting to …
[31731] Connected to GPRS
[32001] Connecting to blynk-cloud.com:8442
[38523] Ready (ping: 932ms).
[86524] Heartbeat timeout
[87037] Connecting to blynk-cloud.com:8442
[88967] Ready (ping: 886ms).
[94102] Connecting to blynk-cloud.com:8442
[96884] Ready (ping: 1127ms).
… and continues connecting and disconnecting.

Please edit your post and format your code so it looks proper for all of us to read clearly. Thanks

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

// 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 <BlynkSimpleSIM800.h>
#define TINY_GSM_MODEM_SIM900   
char auth[] = "xxxxxxxxxx";

// Your GPRS credentials
// Leave empty, if missing user or pass

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

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

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2,3); // RX, TX

TinyGsm modem(SerialAT);

#include <SimpleTimer.h>
SimpleTimer timer;

WidgetLED led13(V0); 

int iLevelRaw;
int iLevelNorm;

void setup()
{
   timer.setInterval(5000L, sendUptime_1_0);    //LIVE LED
   timer.setInterval(10000L, sendUptime_2_0);   //Send data
   timer.setInterval(2000L, sendUptime_3_0);    //Read A0
    
  // Set console baud rate
  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()
  modem.restart();
  // Unlock your SIM card with a PIN
  //modem.simUnlock("8486");

   Blynk.begin(auth, modem, apn, user, pass);
}
void sendUptime_1_0() 
{
  if (led13.getValue()) 
  {
    led13.off();
   // digitalWrite(13,LOW); 
  } else 
  {
    led13.on();
  //  digitalWrite(13,HIGH);
  } 
}

void sendUptime_2_0() 
{
 Blynk.virtualWrite(V1, long(iLevelRaw));
 Blynk.virtualWrite(V2, long(iLevelNorm));
}

void sendUptime_3_0() 
{
 iLevelRaw = analogRead(A0); 
 iLevelNorm  = map(iLevelRaw, 0, 1023, 0, 100);  
}

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

Those ping times are high… that is probably your issue as it also clearly shows a heartbeat error but your code looks OK at a glance,

Thanks for your contribution.
Do you have any suggestion on how to reduce this latency time?

As it will be based entirely on your cellular connection… I would say location and surroundings… does the building the device is in have lots of concrete or metal? Perhaps place it closer to a window, preferably one facing an appropriate cell tower, if you can locate them.

Thank you for your help.
I have placed the GSM/Uno all around my home where good cell signals are available.
I will try another cell company by installing other cell chip in order to check response time.
Nice to talk to you.
Tks.

char apn[] = “”;

Here you need to write what is your connection cellular operator

eg – char apn[] = “internet”;

Your operator may have other options.

Why do not you do so

void sendUptime_2_0() 
{
 iLevelRaw = analogRead(A0); 
 iLevelNorm  = map(iLevelRaw, 0, 1023, 0, 100);  
 Blynk.virtualWrite(V1, long(iLevelRaw));
 Blynk.virtualWrite(V2, long(iLevelNorm));
}

And remove — timer.setInterval(2000L, sendUptime_3_0); //Read A0

And after a reboot, I would put a delay
modem.restart();
delay(5000);

what is it?

For scale conversion map() - Arduino Reference

Hi! It’s been a while since last reply but maybe this will help some other users. I’ve struggled with that problem for a long time, and the only solution I’ve found is to switch to Arduino Mega or better. The code is just fine, but it’s like Uno can’t handle it, maybe it runs out of RAM. How much percentage of memory was consumed right after compilation?