Hi, I am using Arduino Uno, Sim800l GSM Module and GPS Module in my project. I would like to ask why do Blynk keep connecting and ready as shown in the picture below? Is there any problem with my code? Thanks.
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 8
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
char auth[] = "lzmvNPytoZDW4FAl533xyxxG3fygWs5e";
char apn[] = "internet";
char user[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
#include <NMEAGPS.h>
NMEAGPS gps;
TinyGsm modem(SerialAT);
int Testing_Pin = 7;
int Testing_Value = LOW;
int Input_Pin = 12;
int Input_Value = LOW;
String responce = "";
String Link = "";
String Longitude = "";
String Latitude = "";
String Date = "";
String Month = "";
String Year = "";
String Hours = "";
String Minutes = "";
String Seconds = "";
WidgetTerminal terminal(V1);
String SerialAT_send(String incoming) //Function to communicate with SIM800 module
{
SerialAT.println(incoming);
delay(100); //Print what is being sent to GSM module
String result = "";
while (SerialAT.available()) //Wait for result
{
char letter = SerialAT.read();
result = result + String(letter); //combine char to string to get result
}
return result; //return the result
}
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set GSM module baud rate
altSerial.begin(9600);
SerialAT.begin(38400);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
//modem.restart();
responce = SerialAT_send("ATE1"); //Enable Echo if not enabled by default
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SerialAT_send("AT+CGATT=1"); //Set the SIM800 in GPRS mode
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SerialAT_send("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" "); //Activate Bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SerialAT_send("AT+SAPBR=3,1,\"APN\",\"RCMNET\" "); //Set VPN options => 'RCMNET' 'www'
Serial.print ("Responce:"); Serial.println(responce);
delay(2000);
responce = SerialAT_send("AT+SAPBR=1,1"); //Open bearer Profile
Serial.print ("Responce:"); Serial.println(responce); //Open bearer Profile
delay(2000);
responce = SerialAT_send("AT+SAPBR=2,1"); //Get the IP address of the bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
pinMode(Testing_Pin, INPUT);
pinMode(Input_Pin, INPUT);
}
void prepare_message()
{
Link = "The Location is https://www.google.com/maps/place/";
Link = Link + Latitude + "," + Longitude; //Update the Link with latitude and Logitude values
Serial.println(Link);
delay(1000);
}
void notification()
{
Blynk.notify("Emergency! Your mom need help! \n" + Link + "\n" + Date + "/" + Month + "/" + Year + "\n" + Hours + ":" + Minutes + ":" + Seconds);
delay(3000);
}
void terminal01()
{
terminal.print("\n" + Link + "\n" + Date + "/" + Month + "/" + Year + "\n" + Hours + ":" + Minutes + ":" + Seconds);
terminal.flush();
delay(3000);
}
void getgps()
{
if (gps.available( altSerial ))
{
gps_fix fix = gps.read();
Serial.print(F("LOCATION: Lat="));
if (fix.valid.location)
{
Serial.print( fix.latitude(), 6 );
Latitude = String ( fix.latitude(), 6 );
Serial.print( F(" Long=") );
Serial.print( fix.longitude(), 6 );
Longitude = String (fix.longitude(), 6 );
}
Serial.println();
Serial.print(F("DATE: "));
if (fix.valid.date && fix.valid.time)
{
// Shift the date/time to local time
NeoGPS::clock_t localSeconds;
NeoGPS::time_t localTime;
{
using namespace NeoGPS; // save a little typing below...
localSeconds = (clock_t) fix.dateTime; // convert structure to a second count
localSeconds += 8 * SECONDS_PER_HOUR + 0 * SECONDS_PER_MINUTE; // shift timezone
localTime = localSeconds; // convert back to a structure
}
Serial.print( localTime.date );
Date = String( localTime.date );
Serial.print( '/' );
Serial.print( localTime.month );
Month = String( localTime.month );
Serial.print( '/' );
Serial.println( localTime.year );
Year = String( localTime.year );
Serial.print( F("TIME: "));
Serial.print( localTime.hours );
Hours = String( localTime.hours );
Serial.print( ':' );
Serial.print( localTime.minutes );
Minutes = String( localTime.minutes );
Serial.print( ':' );
Serial.println( localTime.seconds );
Seconds = String( localTime.seconds );
}
}
}
void loop()
{
Blynk.run();
altSerial.listen();
if (altSerial.available() > 0)
{
getgps();
}
SerialAT.listen();
Testing_Value = digitalRead(Testing_Pin);
Input_Value = digitalRead(Input_Pin);
if ((Input_Pin == HIGH)|(Testing_Value == HIGH))
{
Testing_Value = HIGH;
delay(1000);
prepare_message();
notification();
terminal01();
Testing_Value = LOW;
}
}