Hello everybody
I would need help with my arduino - SIM800 project.
I’ve tried to search anywhere and it seems I can only find some similar issue but not exactly the same as I would need.
I am using Blynk IoT (and not the old Blynk)
The issue is that basically it works for 6-7 hours then it disconnects (I believe from the network) and the code starts to loop trying to connect to Blynk server but not able to reconnect to internet.
If I reset the modem or the arduino he restarts to work.
Since I know it disconnects every 6-7 hours I’ve tried to setup a timer that resets every 5 hours and it works but I don’t like this way.
It must be a way to detects that it’s not connected and reconnects automatically.
Could you please help?
//Blynk setup
#define BLYNK_TEMPLATE_ID "ciao"
#define BLYNK_DEVICE_NAME "ciao"
#define BLYNK_AUTH_TOKEN "ciao"
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_HEARTBEAT 300
//DHT setup
#include <DHT.h>
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
// Cellular setup:
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
//data manipulation
String signalS;
int signalRSSI;
//-----------------------------------------------------------------------------------
//SERIAL STUFF AND ARDUINO TYPE STUFF
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Hardware Serial on Mega, Leonardo, Micro
#ifndef __AVR_ATmega328P__
#define SerialAT Serial2
// or Software Serial on Uno, Nano
#else
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
#endif
//------------------------------------------------------------------------------------
// Your GPRS credentials, if any
const char apn[] = "simbase";
const char user[] = "";
const char pass[] = "";
char auth[] = BLYNK_AUTH_TOKEN;
TinyGsm modem(SerialAT);
BlynkTimer timer;
void setup()
{
//DHT
dht.begin();
//timer
timer.setInterval(300000L, sendSensor); // 5 minutes
timer.setInterval(300000L, signalStrenght); // 5 minutes
// Set console baud rate
SerialMon.begin(9600);
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(6000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);
Blynk.begin(auth, modem, apn, user, pass);
}
void sendSensor() {
float h = dht.readHumidity();
float t = dht.readTemperature();
//
// Please don't send more that 10 values per second.
//
// humidity is V1 and temperature is V0
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V0, t);
}
void signalStrenght() {
signalS = modem.getSignalQuality( );
signalRSSI = signalS.toInt();
Blynk.virtualWrite(V2, signalRSSI*3);
SerialMon.println(signalRSSI);
}
void loop()
{
Blynk.run();
timer.run();
}