Please read it. I never can know this.

String command = client.readStringUntil('/');
  Serial.print("TOKEN IS TAKEN  :  "); Serial.println(command);
  if (command != "read") {
    Serial.println("COMMAND IS SUCCEED");
    readSensorValue(client);
  }

this is a part of my code and in the serial monitor i can see it

CONNETED TOKEN IS TAKEN : read

COMMAND IS SUCCEED READ FUCTION IS LOADED DISCONNETED

it means the "command" is "read" and it is the same as "read" but it enter the function.

why dose it happen? I cannot find any problems. Please help me

You cannot compare strings like that. Look at strcmp()

PS, next time use code tags!

septillion: You cannot compare strings like that.

But you can compare Strings.

Please post your code - use code tags.

I missed it was the stupid String class. Blegg

yyy5857: it means the "command" is "read" and it is the same as "read" but it enter the function.

I don't understand this

...R

it means the “command” is “read” and it is the same as “read”

Is it possible that command has a trailing space ? Try printing something immediately after the command such as “<”.

Ahhhh, wait! Notice the blank line? Where does that come from? My guess, command is indeed not "read" but "read\n", with an extra new line character at the end. And indeed, "read" != "read\n" ;)

I’m sorry about my english skill. it is about yuns REST call.

I connent to http://192.168.10.60/arduino/read/


#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

YunServer server;

void setup() {
  Serial.begin(9600);

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  Bridge.begin();
  digitalWrite(13, LOW);

  server.noListenOnLocalhost();
  server.begin();

}

void loop() {
  Serial.print("Moisture Sensor Value:");
  Serial.println(analogRead(0));
  Serial.println(digitalRead(13));
  delay(5000);
  
  YunClient client = server.accept();

  if (client) {
    Serial.println("CONNETED");
    process(client);
    client.stop();
    Serial.println("DISCONNETED");
  }
  delay(50);
}

void process(YunClient client) {
  String command = client.readStringUntil('/');
  Serial.print("TOKEN IS TAKEN  :  "); Serial.println(command);
  if (command != "read") {
    Serial.println("COMMAND IS SUCCEED");
    readSensorValue(client);
  }
  else if (command == "set"){
    Serial.println("SET IS SUCCEED");
    setArduino(client);
  }
}

void readSensorValue(YunClient client) {
  int temp, humi, soil_humi;
  Serial.println("READ FUCTION IS LOADED");
  soil_humi = analogRead(0);
  client.print(F("SOIL_HUMI : "));
  client.println(soil_humi);
  Bridge.put(String(A0), String(soil_humi));
 }

this is my code and actually, I wanted to connect to http://192.168.10.60/arduino/read/

and the condition was if(command == “read”) but it did not work. I mean it did not enter into the condtion.

I do not know why the command and “read” are different.

Please edit your post and add code tags (see forum howto).

And I think I already gave you the answer :wink:

I did not know why the command and "read" are different.

Because the String in "command" is actually "read\n".

Instead of "==", use startsWith or something similar.

And please, use code tags when posting code.

Please put your code in its own window as seen in other posts. This can be done by placing

[code]  and [/code]

around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

If you want help you need to follow the rules. Reply #1 asked you to use code tags but the last response failed to do so. Please Edit both responses and put the code tags as requested.

Weedpharma

thank you guys. I will use the code tag and I tried it

 if(command == "read\n")

but when i connect to http://192.168.10.60/arduino/read/

both

 if(command == "read\n")

if(command == "read")

do not work. What did I miss guys? T.T

yyy5857:
What did I miss guys? T.T

UKHeliBob:
Try printing something immediately after the command such as “<”.

Or better still, print the whole String out in hex.
“read\r” ?

 Serial.print("TOKEN IS TAKEN  :  "); Serial.println(command+"<");

i saw in the serial monitor

CONNETED
TOKEN IS TAKEN : read
<
DISCONNETED

I understood the command is “read\n” thank you very much about it.

so I tried

if(command == "read\n")

why does it not work?

Print the length of command. Maybe there is a carriage return in there as well as the newline. Where is the input coming from ?

The value in command might be “read\r”, rather than “read\n”. Rather than fight it, use String::trim() to get rid of the crap following the useful information.