I have an Arduino Uno with a Sim808 GRPS + GPS shield. I can get GRPS and GPS to function and connect to Blynk normally until I include BlynkTimer. When I include, I cannot connect to Blynk. If I do not enable GPS and include BlynkTimer, I get a normal connection. For some reason these two are interfering with each other. This is my first Blynk project, love the app. Any ideas? Thanks for the help.
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define FONA_RX 3
#define FONA_TX 2
#define FONA_RST 4
// 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 "Adafruit_FONA.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "wholesale";
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial
float centerlat = 34.2; //Find Heading
float centerlon = -101.7; //Find Heading
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
//float GPSlat=latitude;
//float GPSlon=longitude;
int sprinklerdegree;
int startnow;
int stopnow;
int onforat;
int onrevat;
int forat;
int revat;
int fordegree;
int revdegree;
int forRev;
int safetyout;
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(3, 2); // RX, TX
SoftwareSerial fonaSS = SoftwareSerial(FONA_RX, FONA_TX); //for FONA808 GPS
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
TinyGsm modem(SerialAT);
BlynkTimer timer;
//#include<simpletimer.h>
BLYNK_CONNECTED()
{
Blynk.syncAll();
}
void getHeading()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
float y = sin(centerlon - longitude) * cos(latitude);
float x = cos(centerlat) * sin(latitude) - sin(centerlat)*cos(latitude)*cos(centerlon-longitude);
float b = atan2(y,x);
const float pi = 3.14159267;
float bearingdeg = b *(180 / pi);
// int sprinklerdegree;
if (bearingdeg < 0) { //turn negative into correct degree bearing
sprinklerdegree = (360 + bearingdeg);
}
Blynk.virtualWrite(V2, sprinklerdegree);
}
void turnongps()
{
Serial.begin(9600);
delay(10);
while (! Serial);
Serial.begin(9600);
Serial.println(F("Adafruit FONA 808 & 3G GPS demo"));
Serial.println(F("Initializing FONA... (May take a few seconds)"));
fonaSerial->begin(9600);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
Serial.println(F("FONA is OK"));
// Try to enable GPRS
Serial.println(F("Enabling GPS..."));
fona.enableGPS(true);
fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
while(!(fona.GPSstatus() == 3)) //fona.getGPS is run until fona.GPSstatus() == 3
{
boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
delay(1000);
}
if(fona.GPSstatus() == 3) //when fona.GPSstatus() == 3, coordinates have been extracted
{
boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
if (gps_success){
Serial.print("GPS lat:");
// GPSlat = latitude, 6;
Serial.println(latitude,4); //Serial.print() only limits to show 2 d.p
Serial.print("GPS long:");
// GPSlon = longitude, 6;
Serial.println(longitude,4);
Serial.print("GPS speed KPH:");
Serial.println(speed_kph);
Serial.print("GPS speed MPH:");
speed_mph = speed_kph * 0.621371192;
Serial.println(speed_mph);
Serial.print("GPS heading:");
Serial.println(heading);
Serial.print("GPS altitude:");
Serial.println(altitude);
}
}
fonaSerial->end(); //end serial communication with GPS to avoid conflict
}
void setup()
{
Serial.begin(9600);
turnongps();
// Debug console
// Set GSM module baud rate
SerialAT.begin(9600); //Begin GSM
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
Blynk.begin(auth, modem, apn, user, pass);
//Blynk.config(modem,auth,"blynk-cloud.com");
//Blynk.connect();
Serial.print("done");
}
void loop()
{
if(!Blynk.connected())
{
// Serial.print("Blynk has disconnected");
modem.restart();
Blynk.begin(auth, modem, apn, user, pass);
}
Blynk.run();
// timer.run();
}