Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/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进行比较_Arduino - Fatal编程技术网

如何将字符数组与arduino进行比较

如何将字符数组与arduino进行比较,arduino,Arduino,我想比较我在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:"); // G

我想比较我在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;
}}
//消息接收
无效接收MSG(浮子温度){
字符c;
chard[200];
int i;
{
Serial.println(“收到的消息:”);
//获取远程号码
sms.远程号码(发送方号码,20);
Serial.println(发送方编号);
//消息处理的一个示例
//任何以#开头的邮件都应丢弃
如果(sms.peek()='#')
{
Serial.println(“废弃短信”);
sms.flush();
}
//读取消息字节并打印它们
而(c=sms.read()){
d[i]=c;
连续打印(c);

//对于(i=0;i用单词声明新数组
char name[6]={'M'、'i'、's'、'u'、'r'、'e'}
然后

intx=0
对于(int i=0;i可以使用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。

您似乎有两个不同的变量名为
d
。您还需要正确设置代码格式-目前代码几乎无法读取。您的代码在字面上和算法上都被破坏。如果要将数组元素与常量strin进行比较g作为一个数组处理,您必须与它的元素进行比较,例如,
if(d[i]==“Misure”[i])
。但是这可能对您不起作用,因为您不清楚是否可以假定接收到的字符将以所需的字符串开头。您可能需要使用某种工具来根据
“Misure”[0]检查每个传入字符
,如果匹配,则增加一个状态变量,以便根据
“Misure”[1]
检查下一个字符,依此类推,直到找到完整的字符串。Misure是一组常量字符,我想检查它是否等于我收到的sms…而不是您可能想要的数组
String stringOne = "Content-Type: text/html";
    // substring(index) looks for the substring from the index position to the end:
  if (stringOne.substring(19) == "htm") {
   }