I am working with a GPRS Shield, an Arduino UNO and a DHT11 for the temperature. When I am testing it in mi office it works pretty well, but when I connect it in the same socket as the refrigerator it works for like 30min - 1hr and then it disconnect from the Blynk Server.
I have tried to change the way I connect it to the socket with different voltage sources and buck converters, but I keep having the same problem.
Now I want to try to reset the Arduino when it disconnect but I dont know if there is any function or something that I can use to know when it disconnects.
Someone can help me please.
Thanks.
/**************************************************************
* 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
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
*
* This example shows how to use SIM800 or SIM900 modem series
* to connect your project to Blynk.
*
* Attention! Please check out TinyGSM guide:
* http://tiny.cc/tiny-gsm-readme
*
* WARNING: SIM module support is for BETA testing.
*
* Change GPRS apm, user, pass, and Blynk auth token to run :)
* Feel free to apply it to any other example. It's simple!
*
**************************************************************/
#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
#define TINY_GSM_MODEM_SIM900
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include "DHT.h"
#define DHTTYPE DHT11
const int DHTPin = 3;
DHT dht(DHTPin, DHTTYPE);
// Temporary variables
static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];
float h, t;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "9e942b9c1c114a6b8689e880f5f9d0bb";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "broadband.tigo.gt"; //APN of your service provider
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(7, 8); // RX, TX
TinyGsm modem(SerialAT);
void powerUpOrDown()
{
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
delay(1000);
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(3000);
}
void setup()
{
// Set console baud rate
Serial.begin(19200);
delay(10);
// Set GSM module baud rate
SerialAT.begin(19200);
delay(3000);
Serial.println("Enciende GPRS Shield");
powerUpOrDown();
// Restart takes quite some time
// To skip it, call init() instead of restart()
modem.init();
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
}
void loop()
{
Blynk.run();
h = dht.readHumidity();
// Read temperature as Celsius (the default)
t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
// float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) ) {
Serial.println("Failed to read from DHT sensor!");
strcpy(celsiusTemp,"Failed");
strcpy(fahrenheitTemp, "Failed");
strcpy(humidityTemp, "Failed");
tempErrBlynk();
} else {
// Computes temperature values in Celsius + Fahrenheit and Humidity
float hic = dht.computeHeatIndex(t, h, false);
dtostrf(hic, 6, 2, celsiusTemp);
// float hif = dht.computeHeatIndex(f, h);
// dtostrf(hif, 6, 2, fahrenheitTemp);
dtostrf(h, 6, 2, humidityTemp);
// You can delete the following Serial.print's, it's just for debugging purposes
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C ");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.println(" *C ");
sendBlynk();
}
delay(30000);
}
void sendBlynk() {
Blynk.virtualWrite(V5,h);
Blynk.virtualWrite(V6,t);
if(t>30){ //set temperatur level for notificat
//Blynk.email("josesagas94@gmail.com", "ESP8266 Alert", "Temperature Increased over limit");
Blynk.notify("Temperatura mayor a 30°C");
}
}
void tempErrBlynk() {
Blynk.notify("Error lectura de sensor");
}