i doing gps program using fona libraries lonet gps/gprs card
im getting gps fix , gprs connection getting gps data not sure how pass on sparkfun data services. i'm getting readout in serial monitor of location when try , pass sparkfun showing lat 0.00, lon 0.00 heading 0.00 speed 0.00
full code below
to make lonet card work had edit of @ commands in fona libraries (but @ commands nothing else)
the readout shows value of latitude, longitude, heading, speed_mph
but when try post values show zeros
why values doing this??
thanks in advance
im getting gps fix , gprs connection getting gps data not sure how pass on sparkfun data services. i'm getting readout in serial monitor of location when try , pass sparkfun showing lat 0.00, lon 0.00 heading 0.00 speed 0.00
full code below
code: [select]
#include "adafruit_fona.h"
#include <phant.h>
// arduino example stream
// https://data.sparkfun.com/streams/**********
// https://data.sparkfun.com/*******
// delete key = ***************
// host, public key, private key
phant phant("data.sparkfun.com", "**********", "***********");
#define sparkfun_public_key "**********"
#define sparkfun_private_key "************"
// pins lonet shield
#define fona_rx 11
#define fona_tx 10
#define fona_rst 9
// handle absence of software serial on platforms
// arduino due. modify code if using different
// hardware serial port, or if using non-avr platform
// supports software serial.
#ifdef __avr__
#include <softwareserial.h>
softwareserial fonass = softwareserial(fona_tx, fona_rx);
softwareserial *fonaserial = &fonass;
#else
hardwareserial *fonaserial = &serial1;
#endif
adafruit_fona fona = adafruit_fona(fona_rst);
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
void setup() {
while (! serial);
serial.begin(115200);
serial.println(f("adafruit fona 808 gps demo"));
serial.println(f("initializing fona... (may take few seconds)"));
fonaserial->begin(9600);
if (! fona.begin(*fonaserial)) {
serial.println(f("couldn't find fona"));
while (1);
}
serial.println(f("fona ok"));
serial.println(f("enabling gps..."));
fona.enablegps(true);
delay(5000);
if (!fona.enablegprs(true))
serial.println(f("failed turn on"));
}
void loop() {
float latitude, longitude, speed_kph, heading, speed_mph;
// if ask altitude reading, getgps return false if there isn't 3d fix
boolean gps_success = fona.getgps(&latitude, &longitude, &speed_kph, &heading);
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);
//postlocation();
} else {
serial.println("waiting fona 808 gps 3d fix...");
}
// print out gsm location 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);
} else {
serial.println("gsm location failed...");
}
char url[160];
uint16_t statuscode;
int16_t length;
sprintf (url, "http://data.sparkfun.com/input/%s?private_key=%s&heading=%s&latitude=%s&longitude=%s&speed_mph=%s",
sparkfun_public_key, sparkfun_private_key, heading, latitude, longitude, speed_mph);
serial.print("getting signal strenth");
sigstrenth();
delay(2000);
serial.print("get network status");
getnetstats();
delay(2000);
serial.print("trying send location internet");
sendlocation ();
delay(20000);
}
void getnetstats(){
// read network/cellular status
uint8_t n = fona.getnetworkstatus();
serial.print(f("network status "));
serial.print(n);
serial.print(f(": "));
if (n == 0) serial.println(f("not registered"));
if (n == 1) serial.println(f("registered (home)"));
if (n == 2) serial.println(f("not registered (searching)"));
if (n == 3) serial.println(f("denied"));
if (n == 4) serial.println(f("unknown"));
if (n == 5) serial.println(f("registered roaming"));
}
void readweb() {
}
void flushserial() {
while (serial.available())
serial.read();
}
char readblocking() {
while (!serial.available());
return serial.read();
}
uint16_t readnumber() {
uint16_t x = 0;
char c;
while (! isdigit(c = readblocking())) {
//serial.print(c);
}
serial.print(c);
x = c - '0';
while (isdigit(c = readblocking())) {
serial.print(c);
x *= 10;
x += c - '0';
}
return x;
}
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
uint16_t buffidx = 0;
boolean timeoutvalid = true;
if (timeout == 0) timeoutvalid = false;
while (true) {
if (buffidx > maxbuff) {
//serial.println(f("space"));
break;
}
while (serial.available()) {
char c = serial.read();
//serial.print(c, hex); serial.print("#"); serial.println(c);
if (c == '\r') continue;
if (c == 0xa) {
if (buffidx == 0) // first 0x0a ignored
continue;
timeout = 0; // second 0x0a end of line
timeoutvalid = true;
break;
}
buff[buffidx] = c;
buffidx++;
}
if (timeoutvalid && timeout == 0) {
//serial.println(f("timeout"));
break;
}
delay(1);
}
buff[buffidx] = 0; // null term
return buffidx;
}
void sendlocation () {
char url[160];
uint16_t statuscode;
int16_t length;
http://data.sparkfun.com/input/******?
private_key=******&latitude=&longitude=&hdop=&altitude
sprintf (url, "http://data.sparkfun.com/input/%s?private_key=%s&heading=%s&latitude=%s&longitude=%s&speed_mph=%s",
sparkfun_public_key, sparkfun_private_key, heading, latitude, longitude, speed_mph);
serial.println(f("sending: ")); serial.println(url);
serial.print(" heading ");
serial.print(heading);
serial.print(" lattitude ");
serial.print(latitude);
serial.print(" longitude ");
serial.print(longitude);
serial.print(" speed ");
serial.print(speed_mph);
serial.println(" ");
// make fona listen, think need this
fonass.listen();
uint8_t rssi = fona.getrssi();
if (rssi > 3) {
// make attempt turn gprs mode on. fona gets freaked out , gprs doesn't turn off.
// when happens can't turn on aagin, don't need because it's on. don't sweat
// error case here -- gprs on -- keep on keeping on , let http_get_start()
// error if there's problem gprs.
if (!fona.enablegprs(true)) {
serial.println(f("failed turn gprs on!"));
}
if (fona.http_get_start(url, &statuscode, (uint16_t *)&length)) {
while (length > 0) {
while (fona.available()) {
char c = fona.read();
delay(3000);
// serial.write slow, we'll write directly serial register!
loop_until_bit_is_set(ucsr0a, udre0); /* wait until data register empty. */
udr0 = c;
length--;
if (! length) break;
}
}
fona.http_get_end();
} else {
serial.println(f("failed send gprs data!"));
}
if (!fona.enablegprs(false)) {
serial.println(f("failed turn gprs off!"));
}
} else {
serial.println(f("can't transmit, network signal strength crap!"));
}
// put gps listen mode
fonass.listen();
}
void sigstrenth(){
// read rssi
uint8_t n = fona.getrssi();
int8_t r;
serial.print(f("rssi = ")); serial.print(n); serial.print(": ");
if (n == 0) r = -115;
if (n == 1) r = -111;
if (n == 31) r = -52;
if ((n >= 2) && (n <= 30)) {
r = map(n, 2, 30, -110, -54);
}
serial.print(r); serial.println(f(" dbm"));
}
to make lonet card work had edit of @ commands in fona libraries (but @ commands nothing else)
the readout shows value of latitude, longitude, heading, speed_mph
code: [select]
<--- +cgpsinf: 32,203559.000,a,5146.9829,n,00129.3548,w,0.000,354.02,180915,,,a
gps lat:51.783046
gps long:-1.489247
gps speed kph:0.00
gps speed mph:0.00
gps heading:354.02
but when try post values show zeros
why values doing this??
thanks in advance
code: [select]
get network status ---> at+creg?
<--- +creg: 2,1,"08fe","c47c"
network status 1: registered (home)
trying send location internetsending:
http://data.sparkfun.com/input/9jlrzyvqldhr88888888?private_key=9jlrzyvqldhr88888888&heading=&latitude=&longitude=&speed_mph=
heading 0.00 lattitude 0.00 longitude 0.00 speed 0.00
code: [select]
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
void loop() {
float latitude, longitude, speed_kph, heading, speed_mph;
stupid! read on scope. now!
Arduino Forum > Using Arduino > Programming Questions > GPS data not posting to sparkfun data pages
arduino
Comments
Post a Comment