gpt4 book ai didi

arduino - SIM900 GSM/GPRS 未获得正确的 AT+CREG?回答

转载 作者:行者123 更新时间:2023-12-02 16:27:55 28 4
gpt4 key购买 nike

我使用的是带有 IComsat SIM900 GSM/GPRS 扩展板的 Arduino UNO。使用以下教程:Arduino Live GPS Tracker我被 AT+CREG 困住了?命令,该命令检查 SIM 卡是否已在提供商处注册。

使用以下逻辑:在 GSM_HTTP.INO 文件中的“void setup()”函数中,执行以下行 modem.checkNetwork();

void setup() {           
Serial.begin(9600);
Serial.println("GM862 monitor");
modem.switchOn(); // switch the modem on
delay(4000); // wait for the modem to boot
modem.init(); // initialize the GSM part of Module
modem.version(); // request modem version info
while (!modem.isRegistered()) {
delay(1000);
modem.checkNetwork(); // check the network availability
}
}

函数“checkNetwork()”是包含的库 GSM862.cpp 的一部分,如下所示:

void GM862::checkNetwork() {
char buf[BUF_LENGTH];
char result;
requestModem("AT+CREG?", 1000, true, buf);
result = buf[21];

if (result == '1') {
state |= STATE_REGISTERED;
}
else {
state &= ~STATE_REGISTERED;
}
}

现在这是重要的部分:函数“requestModem”收到的“result”值返回神秘值,但没有网络状态(数字0-5),这就是为什么有一个无限循环尝试注册没有错误或成功消息。

由于该函数从 GSM862.cpp 中的“requestModem”函数中获取“buf”变量,因此我也查看了它:

byte GM862::requestModem(const char *command, uint16_t timeout, boolean check, char *buf) {

byte count = 0;

*buf = 0;

modem->flush();
modem->println(command);
count = getsTimeout(buf, timeout);
return count;
}

为了查看相关变量以进行调试,我将最后两个函数更改为以下代码:

-->检查网络

void GSM862::checkNetwork() {
char buf[BUF_LENGTH];
char result;
requestModem("AT+CREG?", 1000, true, buf);
result = buf[21];

Serial.print("Debugging buf2:");
Serial.print(buf[21]);
Serial.print("Debugging buf2:");
Serial.print(buf[1]);
Serial.print("Debugging buf2:");
Serial.print(buf[0]);
Serial.print("Debugging result2:");
Serial.println(result);

if (result == '1') {
state |= STATE_REGISTERED;

Serial.println("Network registered, home network...");
}
else {
state &= ~STATE_REGISTERED;

if(result == '0'){
Serial.println("Network not registered, not searching for a new operator to register to...");
}
if(result == '2'){
Serial.println("Still searching for an operators network to register to...");
}
if(result == '3'){
Serial.println("Network registration denied...");
}
if(result == '4'){
Serial.println("Network registration state unknown, probably still starting up...");
}
if(result == '5'){
Serial.println("Network registered, roaming...");
}
}
}

--> 请求调制解调器

byte GSM862::requestModem(const char *command, uint16_t timeout, boolean check, char *buf) {

byte count = 0;

*buf = 0;

modem->flush();
modem->println(command);
count = getsTimeout(buf, timeout);

Serial.print("Debugging command1:");
Serial.println(command);
Serial.print("Debugging count1:");
Serial.println(count);
Serial.print("Debugging buf1:");
Serial.println(buf);
Serial.print("Debugging timeout1:");
Serial.println(timeout);

return count;
}

就像我上面提到的,似乎函数“checkNetwork”的“结果”中的值实际上是“buf[21]”的值,当通过串行显示在终端上时显示一个神秘的值.println();

您知道原因或确切的问题是什么吗?

最佳答案

网络注册信息 (CREG) 输出取决于调制解调器配置。

  1. 通过发送“AT+CREG=0”可以禁用网络注册码(这是您的情况)
  2. 发送“AT+CREG=1”即可启用网络注册
  3. 通过发送“AT+CREG=2”可以启用网络注册码
    位置信息(位置区域代码和小区ID)

选项 2. 和 3. 还将在调制解调器启动/网络更改时自动发出 +CREG 消息。


ps:不要忘记通过执行AT&W来保存当前的AT配置

关于CREG的更多详细信息可以在《SIM900 AT命令手册》中找到

关于arduino - SIM900 GSM/GPRS 未获得正确的 AT+CREG?回答,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17546116/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com