我修改了Adafruit Fona GPS示例文件,以显示我的位置与其收集的GPS和GSM位置之间的错误。我输出的错误部分正确显示,但AT代码也显示在串行监视器上,我无法弄清楚如何抑制它们。代码如下,输出低于该值。我试图摆脱一切不是以#34; GPS错误开始的行..."。
/**
* ___ ___ _ _ _ ___ __ ___ ___ ___ ___
* | __/ _ \| \| | /_\ ( _ )/ \( _ ) / __| _ \/ __|
* | _| (_) | .` |/ _ \ / _ \ () / _ \ | (_ | _/\__ \
* |_| \___/|_|\_/_/ \_\ \___/\__/\___/ \___|_| |___/
*
* This example is meant to work with the Adafruit
* FONA 808 or 3G Shield or Breakout
*
* Copyright: 2015 Adafruit
* Author: Todd Treece
* Licence: MIT
*
*/
#include "Adafruit_FONA.h"
// standard pins for the shield, adjust as necessary
#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4
const float CURR_LAT = 28.086084;
const float CURR_LON = -82.401916;
float GPS_LAT;
float GPS_LON;
float GSM_LAT;
float GSM_LON;
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Have a FONA 3G? use this object type instead
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
void setup() {
while (! Serial);
Serial.begin(115200);
// Serial.println(F("Adafruit FONA 808 & 3G GPS demo"));
// Serial.println(F("Initializing FONA... (May take a few seconds)"));
fonaSerial->begin(4800);
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);
}
void loop() {
delay(1000);
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);
GPS_LAT = latitude;
GPS_LON = longitude;
} 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);
GSM_LAT = latitude;
GSM_LON = longitude;
} 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"));
}
}
}
//const float CURR_LAT = 28.086084;
//const float CURR_LON = -82.401916;
//float GPS_LAT;
//float GPS_LON;
//float GSM_LAT;
//float GSM_LON;
float GPS_DIFF = sqrt((GPS_LAT - CURR_LAT)*(GPS_LAT - CURR_LAT) + (GPS_LON - CURR_LON)*(GPS_LON - CURR_LON));
float GSM_DIFF = sqrt((GSM_LAT - CURR_LAT)*(GSM_LAT - CURR_LAT) + (GSM_LON - CURR_LON)*(GSM_LON - CURR_LON));
Serial.print("GPS Error: ");
Serial.print(GPS_DIFF,6);
Serial.print(" GSM Error: ");
Serial.println(GSM_DIFF,6);
}
输出是:
GPS Error: 87.056900 GSM Error: 87.056900
---> AT+CGNSINF
<--- +CGNSINF: 1,0,20170529194222.000,,,,0.20,78.0,0,,,,,,12,3,,,25,,
---> AT+CREG?
<--- +CREG: 0,1
---> AT+CIPGSMLOC=1,1
<--- +CIPGSMLOC: 601
---> AT+CIPSHUT
<--- SHUT OK
---> AT+SAPBR=0,1
<--- ERROR
---> AT+CIPSHUT
<--- SHUT OK
---> AT+CGATT=1
<--- OK
---> AT+SAPBR=3,1,"CONTYPE","GPRS"
<--- OK
---> AT+SAPBR=3,1,"APN","FONAnet"
<--- OK
---> AT+CSTT="FONAnet"
<--- OK
---> AT+SAPBR=1,1
<--- OK
---> AT+CIICR
<--- OK
GPS Error: 87.056900 GSM Error: 87.056900
答案 0 :(得分:0)
您正在使用Adafruit的库/函数,例如fona.getGPS,并且已编码为返回信息。
它可以在图书馆编辑&#34; Adafruit_Fona&#34;文件夹中。