Hello,
I am creating a simple project of temperature monitoring. The equipment used are Arduino Mega 2560 + Shield GSM Sim900 + DHT + DS18B20 probe. Everything works but every 1-2min reconnects with the server, sometimes several times in 1min. When I started this project and managed to work it was about 3 weeks working perfectly, towards some reconnection to the server 1 time a day. I’ve been having the reconnection problem for about 1 month and when he’s been working for several hours he is not able to connect to Blynk-Cloud again. Attached a screenshot of the team working 2min, and the complete code that I use. I have 3 sim cards, 2 from a company and both have the same problem, and 1 from another company that constantly gives me “login timeout” problems. I also tried this sketch on an arduino 1 and the result is the same.
The power supply of the Sim900 is 12VDC 2A
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
Attention! Please check out TinyGSM guide:
http://tiny.cc/tiny-gsm-readme
WARNING: GSM modem support is for BETA testing.
This example shows how value can be pushed from Arduino to
the Blynk App.
WARNING :
For this example you'll need Adafruit DHT sensor libraries:
https://github.com/adafruit/Adafruit_Sensor
https://github.com/adafruit/DHT-sensor-library
App project setup:
Value Display widget attached to V5
Value Display widget attached to V6
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM900
// 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>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "21ad99f32b6d479b83cdd30ff8c30d0a";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "internetmas"; //MASMOVIL
//char apn[] = "airtelwap.es"; //VODAFONE
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(10, 11); // RX, TX
TinyGsm modem(SerialAT);
#define DHTPIN 2 // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
//Formalizar pines de activación de LEDS
int pin7 = 7;
int pin4 = 4;
int pin5 = 5;
int value = 0;
//Establecer entradas OneWire
OneWire ourWire1(3);
DallasTemperature sensors1(&ourWire1);
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
pinMode( pin5, OUTPUT);
int h = dht.readHumidity();
int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
int alarm = 28;
sensors1.requestTemperatures(); //Se envía el comando para leer la temperatura
float temp1= sensors1.getTempCByIndex(0); //Se obtiene la temperatura en ºC del sensor 1
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h);
Blynk.virtualWrite(V6, t);
Blynk.virtualWrite(V7, temp1);
if (t > alarm)
{
digitalWrite(5, HIGH);
}
else
{
digitalWrite(5, LOW);
}
}
void setup()
{
// Debug console
Serial.begin(9600); //9600
//Iniciar modulo sim900
digitalWrite(9, HIGH); // Descomentar para activar la alimentación de la tarjeta por Software
delay(1000);
digitalWrite(9, LOW);
delay (5000); //Nos damos un tiempo para encender el GPRS y la alimentación de la tarjeta
sensors1.begin();
delay(10);
// Set GSM module baud rate
//SerialAT.begin(19200);
SerialAT.begin(19200);
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("9073"); //sim masmovil de puebas
//modem.simUnlock("3310"); //telefono trabajo
//modem.simUnlock("6367"); //sim personal Vodafone
Blynk.begin(auth, modem, apn, user, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(2000L, sendSensor); //1000L
//Condicion de fallo de corriente, apaga led verde y manda sms
pinMode( pin7, INPUT);
pinMode( pin4, OUTPUT);
value = digitalRead(pin7);
if (value == LOW)
{
digitalWrite(4, HIGH);
}
if (value == HIGH)
{
Serial.println("Enviando SMS...");
SerialAT.print("AT+CMGF=1\r"); //Configura el modo texto para enviar o recibir mensajes
delay(1000);
SerialAT.println("AT+CMGS=\"656690402\""); //Numero al que vamos a enviar el mensaje
delay(1000);
SerialAT.println("Fallo de corriente en el sistema."); // Texto del SMS
delay(100);
SerialAT.println((char)26); //Comando de finalización ^Z
delay(100);
SerialAT.println();
delay(5000); // Esperamos un tiempo para que envíe el SMS
Serial.println("SMS enviado");
}
}
void loop()
{
Blynk.run();
timer.run();
}