我目前正在和我的一个朋友一起做一个涉及 GPS 跟踪的项目。这是我们使用的 Adafruit 的 FONA 3G GPS 板。https://www.adafruit.com/product/3147
我们还使用推荐的有源 GPS 天线。由于我的声誉低,我无法发布指向它的链接。
我们正在 mbed LPC1768 微控制器上对系统进行原型设计。我们编写了自己的 mbed 代码,通过 mbed 上的 UART 向 FONA 发送 AT 命令,然后通过 putty 在计算机上显示回复。我们尝试了几个 AT 简单的 AT 命令,例如制造商信息和 SIM 卡信息,都运行良好。我们还尝试了更复杂的 AT 命令来请求电池电量等,并且这些命令也有效。我们现在无法获得 GPS 响应。昨晚凌晨 1 点左右,我们能够使用 AT+CGPSINFO 命令获得 GPS 响应,该命令向我们显示经度、纬度、方位等。然而,它在大约 40 英里处是不准确的。今天,当我们回到它尝试解决这个问题时,我们无法从 GPS 收到任何响应。我们仍然可以收到来自电池电量和其他命令的响应。只是 GPS 没有响应。我们已经在室内和室外尝试过,并让模块在 GPSTEST 模式下运行了一个多小时,但无济于事。
这是我们到目前为止的代码。
#include "mbed.h"
#define FONA_RST p12
#define FONA_TX p13
#define FONA_RX p14
#define FONA_RI p11
Serial fona(FONA_TX, FONA_RX);
Serial pc(USBTX, USBRX);
Serial esp(p28, p27); // tx, rx
DigitalOut reset(p26);
Timer t;
int count,ended,timeout;
char buf[4024];
char snd[255];
char ssid[32] = "ycp-web-wifi"; // enter WiFi router ssid inside the quotes
char pwd [32] = "YCPnet2005"; // enter WiFi router password inside the quotes
void SendCMD(),getreply(),ESPconfig(),ESPsetbaudrate(),sendFONA(),getFONAreply(), FONAconfig(), FONAsetbaudrate();
int main()
{
reset=0; //hardware reset for 8266
pc.baud(9600); // set what you want here depending on your terminal program speed
pc.printf("\f\n\r-------------ESP8266 Hardware Reset-------------\n\r");
wait(0.5);
reset=1;
timeout=2;
getreply();
esp.baud(115200); // change this to the new ESP8266 baudrate if it is changed at any time.
fona.baud(115200);
//ESPsetbaudrate(); //****************** include this routine to set a different ESP8266 baudrate ******************
//ESPconfig(); //****************** include Config to set the ESP8266 configuration ***********************
FONAconfig();
while(1) {
/*
pc.printf("\n---------- GPS Test ----------\r\n");
strcpy(snd,"AT+CGPSFTM=1\r\n");
sendFONA();
timeout=10;
getFONAreply();
pc.printf(buf);
wait(5);*/
pc.printf("\n---------- Get Battery Information ----------\r\n");
strcpy(snd,"AT+CBC\r\n");
sendFONA();
timeout=5;
getFONAreply();
pc.printf(buf);
wait(1);
pc.printf("\n---------- Get GPS Coordinates ----------\r\n");
strcpy(snd,"AT+CGPSINFO\r\n");
sendFONA();
timeout=60;
getFONAreply();
pc.printf(buf);
/*
wait(2);
pc.printf("\n---------- Get Connected Devices ----------\r\n");
strcpy(snd, "AT+CWLIF\r\n");
SendCMD();
timeout=5;
getreply();
pc.printf(buf);
wait(2);*/
}
}
// Sets new ESP8266 baurate, change the esp.baud(xxxxx) to match your new setting once this has been executed
void ESPsetbaudrate()
{
strcpy(snd, "AT+CIOBAUD=115200\r\n"); // change the numeric value to the required baudrate
SendCMD();
}
void FONAsetbaudrate()
{
strcpy(snd, "AT+IPREX=115200\r\n"); // change the numeric value to the required baudrate
SendCMD();
}
// FONA Config
void FONAconfig()
{
pc.printf("---------- Starting FONA Config ----------\r\n\n");
strcpy(snd,"AT\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
wait(2);
strcpy(snd,"ATI\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
wait(2);
strcpy(snd,"AT+CGPSAUTO=1\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
// Test Mode (0=off / 1=on)
strcpy(snd,"AT+CGPSFTM=0\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
/*
wait(2);
strcpy(snd,"AT+CGPS=0,1\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
wait(5);
strcpy(snd,"AT+CGPSHOT\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);
strcpy(snd,"AT+CGPS=1,1\r\n");
sendFONA();
timeout=1;
getFONAreply();
pc.printf(buf);*/
}
// +++++++++++++++++++++++++++++++++ This is for ESP8266 config only, run this once to set up the ESP8266 +++++++++++++++
void ESPconfig()
{
wait(5);
strcpy(snd,"AT\r\n");
SendCMD();
wait(1);
strcpy(snd,"AT\r\n");
SendCMD();
wait(1);
strcpy(snd,"AT\r\n");
SendCMD();
timeout=1;
getreply();
wait(1);
pc.printf("\f---------- Starting ESP Config ----------\r\n\n");
pc.printf("---------- Reset & get Firmware ----------\r\n");
strcpy(snd,"AT+RST\r\n");
SendCMD();
timeout=5;
getreply();
pc.printf(buf);
wait(2);
pc.printf("\n---------- Get Version ----------\r\n");
strcpy(snd,"AT+GMR\r\n");
SendCMD();
timeout=4;
getreply();
pc.printf(buf);
wait(3);
// set CWMODE to 1=Station,2=AP,3=BOTH, default mode 1 (Station)
pc.printf("\n---------- Setting Mode ----------\r\n");
strcpy(snd, "AT+CWMODE_CUR=3\r\n");
SendCMD();
timeout=4;
getreply();
pc.printf(buf);
wait(2);
pc.printf("\n---------- SoftAP Configuration ----------\r\n");
strcpy(snd, "AT+CWSAP_CUR=\"ESP8266\",\"\",11,0\r\n");
SendCMD();
timeout=10;
getreply();
pc.printf(buf);
wait(2);
// set CIPMUX to 0=Single,1=Multi
pc.printf("\n---------- Setting Connection Mode ----------\r\n");
strcpy(snd, "AT+CIPMUX=1\r\n");
SendCMD();
timeout=4;
getreply();
pc.printf(buf);
wait(2);
/*
pc.printf("\n---------- Listing Access Points 2 ----------\r\n");
strcpy(snd, "AT+CWLAP\r\n");
SendCMD();
timeout=15;
getreply();
pc.printf(buf);*/
wait(2);
pc.printf("\n---------- Connecting to AP ----------\r\n");
pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd);
strcpy(snd, "AT+CWJAP=\"");
strcat(snd, ssid);
strcat(snd, "\",\"");
strcat(snd, pwd);
strcat(snd, "\"\r\n");
SendCMD();
timeout=10;
getreply();
pc.printf(buf);
wait(5);
pc.printf("\n---------- Get IP's ----------\r\n");
strcpy(snd, "AT+CIFSR\r\n");
SendCMD();
timeout=3;
getreply();
pc.printf(buf);
wait(1);
pc.printf("\n---------- Get Connection Status ----------\r\n");
strcpy(snd, "AT+CIPSTATUS\r\n");
SendCMD();
timeout=5;
getreply();
pc.printf(buf);
pc.printf("\n++++++++++ Pinging Site ++++++++++\r\n");
strcpy(snd, "AT+PING=\"172.31.5.67\"\r\n");
timeout=5;
SendCMD();
getreply();
pc.printf(buf);
strcpy(snd, "AT+PING=\"www.google.com\"\r\n");
timeout=5;
SendCMD();
getreply();
pc.printf(buf);
pc.printf("\n++++++++++ List of APs ++++++++++\r\n");
strcpy(snd, "AT+CWLAP\r\n");
timeout=5;
SendCMD();
getreply();
pc.printf(buf);
}
void SendCMD()
{
esp.printf("%s", snd);
}
void sendFONA()
{
fona.printf("%s", snd);
}
void getreply()
{
memset(buf, '\0', sizeof(buf));
t.start();
ended=0;
count=0;
while(!ended) {
if(esp.readable()) {
buf[count] = esp.getc();
count++;
}
if(t.read() > timeout) {
ended = 1;
t.stop();
t.reset();
}
}
}
void getFONAreply()
{
memset(buf, '\0', sizeof(buf));
t.start();
ended=0;
count=0;
while(!ended) {
if(fona.readable()) {
buf[count] = fona.getc();
count++;
}
if(t.read() > timeout) {
ended = 1;
t.stop();
t.reset();
}
}
}
这里还有我们正在使用的 ESP 模块的代码,但它已被注释掉,我认为这不是问题所在。
这是我们运行此代码时得到的响应。FONA 的输出
我们在室内和室外都试过了,调用函数之间的时间不同,但似乎没有什么能使它起作用。这尤其令人气愤,因为这至少给了我们昨晚的坐标,即使它是错误的。现在,正如你所看到的,它根本没有给我们坐标。
有谁知道这里可能是什么问题?似乎因为这个板子比较新而且未经测试,对于这些问题没有一个很大的支持小组。感谢您提供的任何帮助!
旁注:有人知道 AmpI/AmpQ 值是什么意思吗?我们认为它与信号强度有关,但似乎相当随意。