接收来自特定号码的短信

Receiving a sms from a specific number

本文关键字:号码      更新时间:2023-10-16

我正在做一个项目,我的Arduino ATMEGA328在SIM900 GSM Shield中接口,将收到来自特定号码的短信。

我能够收到消息。但我希望我的GSM只从特定号码接收。例如,我只想从 +639123456789 号码接收。像 +639111112222 和 +639998887777 等数字将被丢弃。谁能帮我?

编辑:这是我的代码。

    #include <SoftwareSerial.h> 
    #include <string.h>
    char inchar; // Will hold the incoming character from the GSM shield
    String s = "";
    SoftwareSerial SIM900(2, 3);
    void setup()
    {
      Serial.begin(9600);
      // wake up the GSM shield
      SIM900power(); 
      SIM900.begin(9600);
      delay(20000);  // give time to log on to network.
      SIM900.print("AT+CMGF=1r");  // set SMS mode to text
      delay(100);
      SIM900.print("AT+CNMI=2,2,0,0,0r"); 
      // blurt out contents of new SMS upon receipt to the GSM shield's serial out
      delay(100);
      Serial.println("Ready...");
    }
    void SIM900power()
    // software equivalent of pressing the GSM shield "power" button
    {
      digitalWrite(9, HIGH);
      delay(1000);
      digitalWrite(9, LOW);
      delay(7000);
    }
    void loop() 
    {
    if(SIM900.available() > 0)
{
if(SIM900.find("+639123456789 ") && SIM900.find("AUTO"))
{
Serial.println("AUTOMATIC asd");
SIM900.println("AT+CMGD=1,4");
}
}
    }

我能够收到消息。但我希望我的 GSM 只接收 从特定数字。

您是否希望阻止GSM接收来自未知号码的SMS,还是要在满足条件时输出为串行?

如果是前者,您可能需要与您的网络提供商交谈,并考虑这种方法中的体系结构陷阱。

一旦邮件不满足 条件

在相同的 if 条件下,如果不是从 numXXX 发送,则丢弃短信,添加一个

else{
SIM900.print("AT+CNMI=2,2,0,0,0r");
Serial.println("AUTOMATIC asd");
SIM900.println("AT+CMGD=1,4");
// or write high to led pin if that's what you want.......
}

当然,如果我们能看到那张草图会有所帮助......