arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
288 stars 172 forks source link

cannot If readString statements #8

Closed maco1717 closed 8 years ago

maco1717 commented 8 years ago

Hi,

I'm trying to do stuff on accordance to what i receive on readString but my if statement are not working.

I've also tried saving the result to a variable, when I do this, it appears empty, altough if a print the information is coming in...

section of the code:

while (client.connected()) {
    int messageSize = client.parseMessage();

    if (messageSize > 0) {
      //Serial.println(client.readString());
      //String input = client.readString();
      String state0 = "off";
      String state1 = "on";

     // if (client.readString() == "off") {
     //if (strcmp(client.readString(), state0){
     //if (input == "off"){
     if (client.readString().equals(state0)){

        Serial.println("low");
        digitalWrite(6, LOW);
      }
      if (client.readString() == "on")  {
        Serial.println("high");
        digitalWrite(6, HIGH);
      }
    }
  }

Commented you can see some of the alteration I have tried but no luck...

could you please suggest?

Thanks.

maco1717 commented 8 years ago

My problem was that was trying to use the readString() more than once. and apprently once used it empty's the buffer, I start by storing readString() on a String varible object and use that, that worked...

if (messageSize > 0) {
      //Serial.println(client.readString());
      String input = client.readString();
      Serial.println(input);
sandeepmistry commented 8 years ago

@maco1717 thanks for following up.