2013-07-21 2 views
0

나는 arduino의 gsm 보드에서받은 단어를 Misure 및 Reset으로 비교하고 요청에 따라 다른 경우 응답하지만 arduino는 ams.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; 
}} 
+0

'd'라는 두 개의 다른 변수가있는 것 같습니다. 또한 코드를 올바르게 형식화해야합니다. 현재는 거의 읽을 수 없습니다. –

+0

당신의 코드는 글자 그대로, 그리고 알고리즘 적으로도 잘 어질 것입니다. 배열 요소를 배열로 간주되는 상수 문자열과 비교하려면 요소 (예 :'if (d [i] == "Misure"[i]))와 비교해야합니다. 그러나 수신 된 문자가 원하는 문자열로 시작한다고 가정 할 수 없으므로 이것은 잘 작동하지 않을 수 있습니다. 대신에 "Misure"[0]'에 대해 각 들어오는 문자를 검사하는 무언가가 필요할 수도 있습니다. 상태 변수를 증가 시키면 다음 문자를''Misure "[1]'과 비교하여 검사합니다. 끈. –

+0

Misure 내가받은 SMS와 동등한 지 확인하고 싶은 char의 상수 집합입니다 ... 배열이 아닙니다 – user2464046

답변

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

당신이 사용할 수있는 문자열() 함수

문자열()는 주어진를 검색하여 단어로 새로운 배열을 선언 덕분에 나에게 도움을 주시기 바랍니다 문자열의 끝에 주어진 위치에서 부분 문자열. 하위 문자열은 문자열 끝까지 확장됩니다. 예를 들어 :

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 후 리터가 있기 때문에

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



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

는 사실이다.

관련 문제