如何从Arduino SIM800C GSM屏蔽接收来电号码?

时间:2017-12-13 11:15:52

标签: arduino gsm atmega

我正在尝试编码GSM来电号码接收器。当我(作为电话应答者)接听电话时,它应该打印出来电号码。

我无法找到正确的AT命令来接收来电号码。我尝试AT+CLIP=1\r并在循环+CLIP上,但没有成功。

这是我的代码:

#include <GSMSim.h>
#include <SoftwareSerial.h>

#define RX 7
#define TX 8
#define RESET 2
#define BAUD 9600

GSMSim gsm;
SoftwareSerial mySerial =  SoftwareSerial(RX, TX);
/*
 * Also you can this types:
 * GSMSim gsm(RX, TX);
 * GSMSim gsm(RX, TX, RESET);
 * GSMSim gsm(RX, TX, RESET, LED_PIN, LED_FLAG);
 */

void setup() {
  Serial.begin(9600);
  Serial.println("GSMSim Library - Call Example");
  Serial.println("");
  delay(1000);

  gsm.start(); // baud default 9600
  mySerial.read();
  mySerial.print("AT+CLIP=1\r");
}

void loop() {
  Serial.println(gsm.callStatus());
  gsm.callAnswer();
  Serial.println("Number:");
  Serial.println(mySerial.print("+CLIP"));
  delay(1000);
}

1 个答案:

答案 0 :(得分:0)

我通过使用mySerial,(ATDevice)读取功能并使用命令功能准确地将其打印出来,任何查找它如何工作的人,这里是我的代码

#include <GSMSim.h>
#include <SoftwareSerial.h>
#include <string.h>



#define RX 7
#define TX 8
#define RESET 2
#define BAUD 9600

char outArray;
char inData[20]; 
char inChar=-1; 
byte index = 0; 
char * pch;
char* substring(char*, int, int);

GSMSim gsm;
  SoftwareSerial ATDevice =  SoftwareSerial(RX, TX);
/*
 * Also you can this types:
 * GSMSim gsm(RX, TX);
 * GSMSim gsm(RX, TX, RESET);
 * GSMSim gsm(RX, TX, RESET, LED_PIN, LED_FLAG);
 */

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  ATDevice.begin(9600);

  command("AT+CLIP=1",1000);
  delay(1000);


}


  String command(const char *toSend, unsigned long milliseconds) {
    String result;
    ATDevice.println(toSend);
    unsigned long startTime = millis();
    Serial.print("Return: ");
    while (millis() - startTime < milliseconds) {
      if (ATDevice.available()) {
        char c = ATDevice.read();
        result += c;  // append to the result string
      }
    }
  Serial.println();  // new line after timeout.
  return result;
  }


void loop() {

      command("+CLIP",1000);



     delay(2000);



}