SIM900 GSM/GPRS无法获得正确的AT + CREG?回答 [英] SIM900 GSM/GPRS not getting a proper AT+CREG? answer

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

问题描述

我正在使用带有IComsat SIM900 GSM/GPRS防护罩的Arduino UNO. 使用以下教程:

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"接收到的结果"值返回的是隐秘值,但没有网络状态(数字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...");
    }
  }
}

->请求调制解调器

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)
  1. By sending "AT+CREG=0" one can disable network registration code (which is your case)
  2. By sending "AT+CREG=1" one can enable network registration
  3. By sending "AT+CREG=2" one can enable network registration code with
    location information (location area code and cell 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天全站免登陆