나는 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;
}}
'd'라는 두 개의 다른 변수가있는 것 같습니다. 또한 코드를 올바르게 형식화해야합니다. 현재는 거의 읽을 수 없습니다. –
당신의 코드는 글자 그대로, 그리고 알고리즘 적으로도 잘 어질 것입니다. 배열 요소를 배열로 간주되는 상수 문자열과 비교하려면 요소 (예 :'if (d [i] == "Misure"[i]))와 비교해야합니다. 그러나 수신 된 문자가 원하는 문자열로 시작한다고 가정 할 수 없으므로 이것은 잘 작동하지 않을 수 있습니다. 대신에 "Misure"[0]'에 대해 각 들어오는 문자를 검사하는 무언가가 필요할 수도 있습니다. 상태 변수를 증가 시키면 다음 문자를''Misure "[1]'과 비교하여 검사합니다. 끈. –
Misure 내가받은 SMS와 동등한 지 확인하고 싶은 char의 상수 집합입니다 ... 배열이 아닙니다 – user2464046