2017-05-29 1 views
0

J'ai modifié le fichier d'exemple Adafruit Fona GPS pour montrer l'erreur entre mon emplacement et les emplacements GPS et GSM qu'il recueille. La partie d'erreur que je publie s'affiche correctement, mais les codes AT s'affichent également sur le moniteur série et je n'arrive pas à comprendre comment les supprimer. Le code est ci-dessous et la sortie est en dessous de cela. J'essaie de me débarrasser de tout ce qui n'est pas la ligne commençant par "Erreur GPS ...".Supress AT sortie de code dans le moniteur série sur Adafruit Fona

/** 
* ___ ___ _ _ _  ___ __ ___ ___ ___ ___ 
* | __/ _ \| \| | /_\ (_)/ \(_)/__| _ \/ __| 
* | _| (_) | .` |/ _ \/_ \()/_ \ | (_ | _/\__ \ 
* |_| \___/|_|\_/_/ \_\ \___/\__/\___/ \___|_| |___/ 
* 
* 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); 
} 

Et la sortie est:

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 

Répondre

0

Vous utilisez la bibliothèque de Adafruit/fonctions comme fona.getGPS et est codé pour renvoyer des informations.

Il peut être modifié dans le dossier "Adafruit_Fona" des bibliothèques.