SIM900 GSM/GPRS 没有得到正确的 AT+CREG?回答 [英] SIM900 GSM/GPRS not getting a proper AT+CREG? answer

查看:43
本文介绍了SIM900 GSM/GPRS 没有得到正确的 AT+CREG?回答的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using an Arduino UNO with attached IComsat SIM900 GSM/GPRS shield. Using the following tutorial: Arduino Live GPS Tracker I'm stuck with the AT+CREG? command, which checks if the SIM-card is registered at the provider.

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

The following logic is used: In the GSM_HTTP.INO file within the "void setup()" function, the following line gets executed 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 的一部分,如下所示:

The function "checkNetwork()" is part of the included library GSM862.cpp and looks like this:

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),这就是尝试注册的无限循环的原因没有错误或成功消息.

Now this is the important part: The value of "result" that gets received by the function "requestModem" returns cryptic values, but no netword status (number 0-5) which is why there is a endless loop trying to register without error or success message.

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

As this function gets the "buf" variable out of the function "requestModem" in GSM862.cpp, I've had a look at it as well:

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;
}

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

In order to have a look into the relevant variables for debugging purposes I've changed the last two functions into the following code:

-->checkNetwork

-->checkNetwork

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...");
    }
  }
}

--> 请求调制解调器

--> request Modem

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();

Like I've mentioned above, it seems that the value out of "result" of the function "checkNetwork" which is actually the value of "buf[21]", displays a cryptic value when displayed on the terminal via Serial.println();

你知道为什么或确切的问题是什么吗?

Do you have any idea why or what the exact problem is?

推荐答案

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

Network registration information (CREG) output depends on modem configuration.

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

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

Options 2. and 3. will also automatically emit +CREG messages upon modem boot/network change.


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


ps: one should not forget to save current AT configuration by executing AT&W

关于CREG的更多细节可以在SIM900 AT COMMAND MANUAL"中找到

more details on CREG can be found in "SIM900 AT COMMAND MANUAL"

这篇关于SIM900 GSM/GPRS 没有得到正确的 AT+CREG?回答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆