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");
}
}
}