Hi,
Recently I have obtained the FONA808 arduino shield, I plugged it onto my Arduino Uno and everything works fine with the example sketches provided by the FONA library. I was able to obtain GPS coordinates and connect to the internet with GSM.
Since I want to use it with Blynk, I installed the TinyGSM library and loaded up the BlynkClient.ino, it had connected to the server smoothly, interactions were possible at that point.
However, when I tried to obtain a GPS coordinates as well as connecting to the Blynk server in the same sketch, it doesn’t work. I can see from the serial monitor that the GPS coordinates have been extracted, also it has connected to GPRS, but the problem is that it is stuck at Blynk.begin(auth, modem, apn, user, pass);
and it will not connect to the blynk-cloud.com server. I am using the latest version of Blynk. Does anyone know what the issue might be?
#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM808
#define FONA_RX 3
#define FONA_TX 2
#define FONA_RST 4
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include "Adafruit_FONA.h"
char auth[] = "";
char apn[] = "giffgaff.com";
char user[] = "giffgaff";
char pass[] = "";
#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);
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
float GPSlat;
float GPSlon;
void turnOnGPS(){
Serial.println(F("Adafruit FONA 808 & 3G GPS demo"));
Serial.println(F("Initializing FONA... (May take a few seconds)"));
fonaSerial->begin(9600); //Software Serial fona begins
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);
delay(1000);
Serial.print("GPSstatus: ");
Serial.println(fona.GPSstatus());
while(!(fona.GPSstatus() == 3)) //fona.getGPS is run until fona.GPSstatus() == 3
{
Serial.print("GPSstatus: ");
Serial.println(fona.GPSstatus());
Serial.print("getNetworkStatus: ");
Serial.println(fona.getNetworkStatus());
boolean gps_success = 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(GPSlat); //Serial.print() only limits to show 2 d.p
Serial.print("GPS long:");
GPSlon = longitude, 6;
Serial.println(GPSlon);
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);
delay(100);
fona.enableGPS(false);
}else{
Serial.println("Waiting for FONA GPS 3D fix...");
}
}
}
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
delay(2000);
turnOnGPS(); //obtain GPS coordinates
// Set GSM module baud rate
fonaSerial->end(); //end serial communication with GPS to avoid conflict
delay(500);
SerialAT.begin(9600); //serial communication for blynk starts
delay(3000);
Serial.println("Initializing modem...");
modem.restart();
String modemInfo = modem.getModemInfo();
Serial.print("Modem: ");
Serial.println(modemInfo);
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, user, pass);
}
void loop()
{
delay(2000);
Blynk.run();
Serial.println("Loop is over!");
}