GPS Tracker Using Fona808 Shield NOT WORKING! Help

Adafruit cellular platform - SMS and IoT over celluar

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

Hi, no I haven't yet, as like said it may be the API which I am unsure how to change so I'll have to use adafruit.io instead of freeboard.io through another code. I'll have to take parts out of the code for that. It's a nightmare

User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

Can someone please help me implement io.adafruit dashback into my code rather than Dweet.io. asap

User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

Guys, I really need some help asap please. I've tried everything. GPS Test code works, i get my location but won't send the data to the website using my code, it worked before.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by adafruit_support_mike »

The code doesn't seem to be related to the hardware, or to the software handling communication between the microcontroller and the FONA. It seems to be a protocol issue related to the way the data gets sent to the online service where you want to display it.

The best suggestion I can give you is to back out from the existing code and write the simplest code you can that sends a hard-coded block of data to the online service, and focus on getting that to work. That will eliminate most of the distractions created by other parts of the code.

Once you have the microcontroller sending information to the online service in general, you can start playing around with the kinds of message you send. You should be able to work your way up to hard-coded GPS data, then switch over to values taken from the GPS module in real time.

The fact that the code worked at one time is njo longer relevant to what you're trying to do. If that was the controlling issue, the same code would still work now. The fact that the existing code doesn't work now means something has changed, and you need to find out what will work now.

User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

I believe I have if we read the previous comments.

I was requesting help on implementing io.adafruit dashboard to my code so I can use that to have my dashboard such as Google maps as I do with freeboard.io.

I want to remove dweet.io which is what sends the data to the dashboard freeboard.io.... instead I want to use io.adafruit as I do not know how to change and apis or why it won't send data to it.

So require assistance to implement this to my code. I have checked websites and pdf about it but need help with my specific code.

Thank you

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by adafruit_support_mike »

Post the code you have now and we'll take a look. What's the last thing it does correctly before the first thing that doesn't work the way it should?

User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

Code: Select all

// Libraries
#include "Adafruit_FONA.h"
#include <SoftwareSerial.h>

// Pins
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

// Dweet.io Thing
String dweetThing = "hellobob";

// Variables
boolean GPSloc;

// Instances
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

void setup() {
  
  while (!Serial);

  Serial.begin(115200);
  Serial.println(F("FONA GPS tracker"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while(1);
  }
  Serial.println(F("FONA is OK"));

  }

  // Setup GPRS APN (username/password optional)
  fona.setGPRSNetworkSettings(F("uk.lebara.mobi"), F("wap"), F("wap"));
  //fona.setGPRSNetworkSettings(F("your_APN"), F("your_username"), F("your_password"));
  
   // GPS
    Serial.println(F("[O] Turn GPS on (FONA 808 & 3G)"));
    Serial.println(F("[o] Turn GPS off (FONA 808 & 3G)"));
    Serial.println(F("[L] Query GPS location (FONA 808 & 3G)"));
  if (!fona.enableGPS(true)) {
    Serial.println(F("Failed to turn on GPS"));
  } 

  // Turn GPRS on
  fona.enableGPRS(true);

  // Decide between GPS or GPRS location
  int8_t stat;
  
  // Check GPS fix
  stat = fona.GPSstatus();
  if (stat < 0) {
    GPSloc = false;
  }
  if (stat == 0 || stat == 1) {
    GPSloc = false;
  }
  if (stat == 2 || stat == 3) {
    GPSloc = true;
  }

  // Print which location method is used
  Serial.print("Location method: ");
  if (GPSloc) {Serial.println("GPS");}
  else {Serial.println("GPRS");}
 
}

void loop() {

  // Location variables
  String location;
  String latitude;
  String longitude;
  double latitudeNumeric;
  double longitudeNumeric;
 
  // Get location
  if (GPSloc) {
    location = getLocationGPS();
    latitude = getLatitudeGPS(location);
    longitude = getLongitudeGPS(location);
    latitudeNumeric = convertDegMinToDecDeg(latitude.toFloat());
    longitudeNumeric = convertDegMinToDecDeg(longitude.toFloat());
  }
  else {
    location = getLocationGPRS();
    latitude = getLatitudeGPRS(location);
    longitude = getLongitudeGPRS(location);
    latitudeNumeric = latitude.toFloat();
    longitudeNumeric = longitude.toFloat();
  }
  Serial.print("Latitude, longitude: ");
  Serial.print(latitudeNumeric, 6);
  Serial.print(",");
  Serial.println(longitudeNumeric, 6);

  // Prepare request
  uint16_t statuscode;
  int16_t length;
  char url[80];
  String request = "www.dweet.io/dweet/for/" + dweetThing + "?latitude=" + String(latitudeNumeric) + "&longitude=" + String(longitudeNumeric);
  request.toCharArray(url, request.length());
  
  // Send location to Dweet.io
  if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) {
    Serial.println("Failed!");
  }
  while (length > 0) {
    while (fona.available()) {
      char c = fona.read();
           
      // Serial.write is too slow, we'll write directly to Serial register!
      #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
        loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
        UDR0 = c;
      #else
        Serial.write(c);
      #endif
      length--;
    }
  }
  fona.HTTP_GET_end();

  // Wait for 10 seconds before next location
  Serial.println(F("Waiting until next message..."));
  delay(10000);

}

String getLocationGPRS() {

  // Buffer for reply & returncode
  char replybuffer[255];
  uint16_t returncode;

  // Get & return location
  if (!fona.getGSMLoc(&returncode, replybuffer, 250))
    return String("Failed!");
  if (returncode == 0) {
    return String(replybuffer);
  } else {
    return String(returncode);
  }
  
}

String getLocationGPS() {

  // Buffer
  char gpsdata[255];

  // Get data
  fona.getGPS(0, gpsdata, 255);
  return String(gpsdata);
}

String getLatitudeGPS(String data) {

  // Find commas
  int commaIndex = data.indexOf(',');
  int secondCommaIndex = data.indexOf(',', commaIndex+1);
  int thirdCommaIndex = data.indexOf(',', secondCommaIndex+1);
  
  return data.substring(commaIndex + 1, secondCommaIndex);
}


String getLongitudeGPS(String data) {

  // Find commas
  int commaIndex = data.indexOf(',');
  int secondCommaIndex = data.indexOf(',', commaIndex+1);
  int thirdCommaIndex = data.indexOf(',', secondCommaIndex+1);
  
  return data.substring(secondCommaIndex + 1, thirdCommaIndex);
}

String getLongitudeGPRS(String data) {

  // Find commas
  int commaIndex = data.indexOf(',');
  int secondCommaIndex = data.indexOf(',', commaIndex+1);

  return data.substring(0, commaIndex);
}


String getLatitudeGPRS(String data) {
  
  // Find commas
  int commaIndex = data.indexOf(',');
  int secondCommaIndex = data.indexOf(',', commaIndex+1);

  return data.substring(commaIndex + 1, secondCommaIndex);
}

double convertDegMinToDecDeg (float degMin) {
  double min = 0.0;
  double decDeg = 0.0;
 
  //get the minutes, fmod() requires double
  min = fmod((double)degMin, 100.0);
 
  //rebuild coordinates in decimal degrees
  degMin = (int) ( degMin / 100 );
  decDeg = degMin + ( min / 60 );
 
  return decDeg;
}
Well, on the serial monitor it used to display my location and send the data to Dweet.io using Freeboard.io but now it doesn't send any data. It actually now says 601.0000 as my location. The GPS Test code shows my location.

User avatar
Remix23
 
Posts: 36
Joined: Wed May 10, 2017 4:40 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by Remix23 »

Need help today :(

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: GPS Tracker Using Fona808 Shield NOT WORKING! Help

Post by adafruit_support_mike »

Add Serial.print() statements in the code where you take the raw output from the GPS module and format it for transmission across the network. Work your way along, printing every intermediate value until you find the place where you get output you don't expect. That will help you zero in on the code that's causing the problem.

Locked
Please be positive and constructive with your questions and comments.

Return to “FONA”