如何比较字符数组与arduino

时间:2013-07-21 14:17:47

标签: arduino

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

//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;
}}

2 个答案:

答案 0 :(得分: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;
 }
}

答案 1 :(得分:0)

您可以使用subString()函数

只有一个参数的

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

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。