【发布时间】:2015-02-04 21:37:37
【问题描述】:
我正在做一个项目,我的 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=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// 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");
}
}
}
【问题讨论】:
-
先接收,再核对号码,不匹配什么都不做?在收到之前丢弃是行不通的。
-
@deviantfan 我正在寻找正确的语法格式。我试过 SoftwareSerial.find("+639123456789") 但它不起作用。你有其他方法检测发件人号码吗?
-
deviantfan 是对的,这与 GSM 无关。贴一小段 C++ 代码,试图过滤掉数字,人们可以指出你哪里出错了。
-
@SList 我已经输入了我的代码。随意编辑。 :))
-
@Vonne:你的问题不清楚。该评论听起来像您正在为
IF this THEN that逻辑而苦苦挣扎。但是你已经在代码中写了一个if语句,并且可能在你的生活中成千上万。这个具体有什么问题?