[SOLVED] FONA808 sending GPS data to ubidots server


#1

I’m trying to use Fona 808 GSM + GPS module to send its GPS data to ubidots server.

Here is my code combining Fona’s GPS library and UbidotsSendmultiplevlaues but I just can’t seem to make it work.

#include <UbidotsFONA.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"

#define APN  "internet.globe.com.ph" 
#define USER ""  
#define PASS ""  
#define TOKEN "A1E-IrSd1VHUgdSCq4XPklNE1ncmAKFbzE" 
#define VARIABLE_LABEL_1 "lat1"
#define VARIABLE_LABEL_2 "lon1" 

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

Ubidots client(TOKEN);

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println(F("Enabling GPS..."));
  fona.enableGPS(true);
}

void loop() {
  boolean tapos = false;;
  delay(2000);

  float latitude, longitude, speed_kph, heading, speed_mph, altitude;

  // if you ask for an altitude reading, getGPS will return false if there isn't a 3D fix
  boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);

  if (gps_success) {

    Serial.print("GPS lat:");
    Serial.println(latitude, 6);
    Serial.print("GPS long:");
    Serial.println(longitude, 6);
    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);

  } else {
    Serial.println("Waiting for FONA GPS 3D fix...");
  }

  // Fona 3G doesnt have GPRSlocation :/
  if ((fona.type() == FONA3G_A) || (fona.type() == FONA3G_E))
    return;
  // Check for network, then GPRS 
  Serial.println(F("Checking for Cell network..."));
  if (fona.getNetworkStatus() == 1) {
    // network & GPRS? Great! Print out the GSM location to compare
    boolean gsmloc_success = fona.getGSMLoc(&latitude, &longitude);

    if (gsmloc_success) {
      Serial.print("GSMLoc lat:");
      Serial.println(latitude, 6);
      Serial.print("GSMLoc long:");
      Serial.println(longitude, 6);
      tapos = true;
    } else {
      Serial.println("GSM location failed...");
      Serial.println(F("Disabling GPRS"));
      fona.enableGPRS(false);
      Serial.println(F("Enabling GPRS"));
      if (!fona.enableGPRS(true)) {
        Serial.println(F("Failed to turn GPRS on"));  
      }
    }
  }
  if(tapos == true)
  {
  client.setDebug(true);
  while(!client.setApn(APN, USER, PASS));
  float value1 = 14;
  float value2 = 13;
  client.add(VARIABLE_LABEL_1, value1);
  client.add(VARIABLE_LABEL_2, value2);
  if(client.sendAll()){
    Serial.println("values sent properly");
  }
  }

}

#2

Dear @jppallarca,

Regrettably at the moment is out of my scope trying to replicate your issue because I don’t have the GPS module, but I can give you some tips in order to make it work!!!

As I can see you are trying to combine the Adafruit_FONA library with the Ubidots one which already use the Adafuit_FONA. Maybe, both library are trying to initialize the module and the issue can be related with this, it’s an option.

First, I recommend you see the following guide to ensure that the step by step it’s okay.

Then, you should try using one of the examples provided in the Adafruit_FONA library in order to test if the module is able to make request to any server(e.i: google.com (8.8.8.8)). If everything works okay, modify the successful request to the Ubidots Server, for the documentation please see here.

I hope this would help you.

All the best,
Maria C.


#3

Yes, thank you for the help. :slight_smile: We are now trying to edit the library so it works in our favor :slight_smile:


#4

Where you able to solve the problem? And if so how?