1

我想将我从 arduino 中的 gsm 板上收到的文本与 Misure 和 Reset 一词进行比较,并根据请求在不同的情况下回复,但 arduino 跳转到 ams.flush() 时没有回复。请帮帮我谢谢

//Message REceiving
void receivemsg(float temperature){
 char c;
    char d[200];
    int i;


  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while(c=sms.read()){
       d[i]=c;
      Serial.print(c);
//      for (i=0;i<200;i++){
//      d[i]=c;}
}
          Serial.println("\nEND OF MESSAGE");


      // interpreter of the message
      for (i=0;i<200;i++){
      if (d[i]=='Misure')
      // part of reply message 
      {


 String t="Hello i'm Arduino: Umidità del terreno attuale (0-50): "+ String(sensorValue);
 String f= " Temeratura attuale: ";
 String d= ftoa(temperature,2,6);

String txt=t+f+d;
 char txtMsg[200];
 txt.toCharArray(txtMsg,140);
  sms.beginSMS(senderNumber);
  sms.print(txtMsg);
  sms.endSMS(); 
  Serial.println("\nCOMPLETE!\n");}}

      for (i=0;i<200;i++){      
if (d[i]=='Reset'){
    char txtMsg[200]={"Reset Received... i'm resetting now please be patient thanks"};
    sms.beginSMS(senderNumber);
    sms.print(txtMsg);
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");
     //calling watchdog
      Reset_AVR();}}


    // Delete message from modem memory to prevent full  memory space error
    sms.flush();
    Serial.println("MESSAGE DELETED");
  delay(1000);
  return;
}}
4

2 回答 2

0

char name[6]={'M','i','s','u','r','e'} 然后用你的话声明新数组

int x=0
for(int i=0;i<7;i++){
 if(name[i]=d[i]){
   int x=1;         
 }else{
   x=0;
   break;
 }
}
于 2017-11-02T11:13:00.060 回答
0

您可以使用 subString() 函数

只有一个参数的 substring() 从给定位置到字符串末尾查找给定子字符串。它期望子字符串一直延伸到字符串的末尾。例如:

String stringOne = "Content-Type: text/html";



// substring(index) looks for the substring from the index position to //the end:
  if (stringOne.substring(19) == "html") {
   }

是真的,而

String stringOne = "Content-Type: text/html";
    // substring(index) looks for the substring from the index position to the end:
  if (stringOne.substring(19) == "htm") {
   }

不正确,因为字符串中的 htm 后面有一个 l。

于 2018-02-08T22:02:42.950 回答