Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何防止其他电话/手机号码向Arduino发送SMS命令?_Arduino_Sms_At Command_Sim900 - Fatal编程技术网

如何防止其他电话/手机号码向Arduino发送SMS命令?

如何防止其他电话/手机号码向Arduino发送SMS命令?,arduino,sms,at-command,sim900,Arduino,Sms,At Command,Sim900,简介: 对于Arduino编程和使用AT命令,我是个新手。我已经试着搜索整个互联网,并在Arduino论坛上提问,但我运气不好,那里似乎没有人给我一个清晰的想法 问题: 所以,我有这个代码,一个SMS命令可以打开和关闭灯,它将只响应一个特定的电话号码。我的问题是,即使我使用不同的电话号码,程序也会响应。我希望有一种方法,它只能白名单上的具体数字,这样没有人可以恶作剧的程序,没有所有者的知识 例如: 车主的电话号码是+631234567890 一些随机电话号码:+63xxxxxxxxx 主人可

简介:

对于Arduino编程和使用AT命令,我是个新手。我已经试着搜索整个互联网,并在Arduino论坛上提问,但我运气不好,那里似乎没有人给我一个清晰的想法

问题:

所以,我有这个代码,一个SMS命令可以打开和关闭灯,它将只响应一个特定的电话号码。我的问题是,即使我使用不同的电话号码,程序也会响应。我希望有一种方法,它只能白名单上的具体数字,这样没有人可以恶作剧的程序,没有所有者的知识

例如:

  • 车主的电话号码是+631234567890
  • 一些随机电话号码:+63xxxxxxxxx
主人可以打开和关闭灯。[是]
但据推测,随机电话号码不可能也永远不会有权力打开和关闭电灯。只有所有者可以

这是我当前的代码:CCTO

#包括
软件串行GPRS(10,11);
字符串文本消息;
弦状态;
常数int继电器=12;
无效设置(){
pinMode(继电器、输出);
数字写入(继电器,高);
Serial.begin(9600);
GPRS.begin(9600);
延迟(5000);
串行打印(“GPRS就绪…\r\n”);
GPRS.print(“AT+CMGF=1\r\n”);
延迟(1000);
GPRS.print(“AT+CNMI=2,2,0,0,0\r\n”);
延迟(1000);
}
void循环(){
如果(GPRS.available()>0){
textMessage=GPRS.readString();
串行打印(文本消息);
延迟(10);
} 
如果(textMessage.indexOf(“ON”)>=0){
//打开继电器并保存当前状态
数字写入(继电器,高);
lampState=“ON”;
Serial.println(“灯设置为打开\r\n”);
textMessage=“”;
GPRS.println(“AT+CMGS=\”+631234567890\”;
延迟(500);
GPRS.print(“灯终于打开了。\r”);
GPRS.write(0x1a);
延迟(1000);
}
如果(textMessage.indexOf(“OFF”)>=0){
//关闭继电器并保存当前状态
数字写入(继电器,低电平);
lampState=“关”;
Serial.println(“灯设置为关闭\r\n”);
textMessage=“”;
GPRS.println(“AT+CMGS=\”+631234567890\”;
延迟(500);
GPRS.print(“灯最终关闭。\r”);
GPRS.write(0x1a);
延迟(1000);
}
如果(textMessage.indexOf(“状态”)>=0){
字符串消息=“灯为”+灯状态;
GPRS.print(“AT+CMGF=1”);
延迟(1000);
Serial.println(“灯状态请求”);
textMessage=“”;
GPRS.println(“AT+CMGS=\”+631234567890\”;
延迟(500);
GPRS.print(“灯当前为”);
GPRS.println(lampState?“开”:“关”);
GPRS.write(0x1a);
延迟(1000);
}
}

我该怎么做呢?

您的短信必须包含有关发件人和发送时间的信息。大概是这样的:

+CMGL:2,“REC未读”、“+63xxxxxxxxx”、“07/02/18,00:07:22+32”一个简单的短信演示


因此,您需要在提取电话号码时将其与授权号码进行比较。

您可以在代码中定义所需的电话号码,并将其与分配给传入SMS的号码进行比较。如果数字与代码中的数字匹配,请继续执行算法。否则,忽略该消息

从官方的Arduino论坛上获得了这段代码,你可以从最后给出的链接中查看。您可以对这两个函数进行编码:


String CellNumtemp;
String CellNum;


// check if there are incoming SMS
void ricezione(){
  Serial.println ("controllo ricezione SMS");
  // AT command to set mySerial to SMS mode
  mySerial.print("AT+CMGF=1\r");
  delay(100);
  // Read the first SMS saved in the sim
  mySerial.print("AT+CMGR=1\r");
  delay(10); 
  if(mySerial.available()>0){
    textMessage = mySerial.readString();
    Serial.print(textMessage); 
    delay(10);
  }
  // check if the SMS is "STATO"
  if(textMessage.indexOf("STATO")>=0){   
    Serial.println("Invio info stato arnia");
    //save the phone number of the senders in a string (this works with italian region you must adapt to   yours) 
    CellNumtemp = textMessage.substring(textMessage.indexOf("+39"));
    CellNum = CellNumtemp.substring(0,13);
    smsstato();
    CellNumtemp = "";
    textMessage = "";   
  }
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGD=2\r");
  delay(100);   
}


// Send sms with all the information to the number stored
void smsstato(){
  // delete the first SMS
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGF=1\r");   
  delay(1000);
  mySerial.print("AT+CMGS=\"");
  mySerial.print(CellNum);
  mySerial.print("\"\r"); 
  delay(1000);
  //The text of the message to be sent.
  mySerial.print("INFO: Latitudine: ");
  mySerial.print(latitude);
  mySerial.print(", Longitudine: ");
  mySerial.print(logitude);
  mySerial.print(", Ampere: ");
  mySerial.print(consumotemp);
  delay(1000);
  mySerial.write(0x1A);
  delay(1000);
  Serial.println("sms stato");
}```

Thanks to the user ilteo85 on the https://forum.arduino.cc.
Check this out for reference: https://forum.arduino.cc/index.php?topic=637264.0

有人建议,如果不是收件人,程序应该让它阅读并忽略邮件。嗨!请阅读。尝试包含一些示例代码(甚至可能是伪代码)来展示你的建议是什么样子的-尽量不要只发布外部链接,因为它们将来可能会脱机。好的,我会编辑它。谢谢你的建议!