Arduino compiling error (looking for "true" in response form server)

Hi, I have a problem with my program. Program reads a rfid tag, sends it to server and waiting for response. If respons is true, Program will open the door. I have problem with part of programm which looking for "true "in respons. I have compiling error.
Error:

rfid_.ino: In function 'boolean ServerRequest()':
rfid_.ino:52:11: error: no match for 'operator=' (operand types are 'String' and 'void')
rfid_.ino:52:11: note: candidates are:
In file included from /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Arduino.h:222:0,
                 from /Users/tgglab/Documents/Arduino/libraries/Wiegand/Wiegand.h:5,
                 from rfid_.ino:1:
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:86:11: note: String& String::operator=(const String&)
  String & operator = (const String &rhs);
           ^
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:86:11: note:   no known conversion for argument 1 from 'void' to 'const String&'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:87:11: note: String& String::operator=(const char*)
  String & operator = (const char *cstr);
           ^
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:87:11: note:   no known conversion for argument 1 from 'void' to 'const char*'
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:88:11: note: String& String::operator=(const __FlashStringHelper*)
  String & operator = (const __FlashStringHelper *str);
           ^
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/WString.h:88:11: note:   no known conversion for argument 1 from 'void' to 'const __FlashStringHelper*'
Error compiling.

Arduino program:

#include <Wiegand.h>
#include <UIPEthernet.h>
WIEGAND wg;
int door = 1;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 179); 
byte server[] = { 192, 168, 1, 18 }; // ip serwera
EthernetClient client;

void setup() {
    wg.begin();
    
     pinMode(7, OUTPUT);
     pinMode(8, OUTPUT);
     pinMode(9, OUTPUT);
     
     Serial.begin(9600);
}

void loop() {
  if(wg.available()){
            unsigned long cardId = wg.getCode(); //kod karty
            Serial.print(cardId);
            
            String a = getHttpHeader(cardId,door); //string z get
            Serial.println("connecting...");
            
              if (client.connect(server, 80)) {
                  Serial.println("connected");
                  client.println(a);
                  client.println();
                  boolean result = ServerRequest(); 
                    if(result == true){
                         AccessGranted();
                    }
                    else{
                         AccessDenied();
                    }
              }
              else {
                  Serial.println("connection failed");
                  loop();
              }
  }
  

}
boolean ServerRequest(){  
  while (client.available() > 0){
     String line = client.readStringUntil('\n');
     line = line.trim();
     Serial.print(line);
         if (line == "true"){
           return true;
         }
         else{
           return false;
   }
 }
}

void AccessDenied() {  //zamykanie
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  loop();;
  
}

void AccessGranted() {  //otwieranie
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  delay(5000);
  digitalWrite(9, LOW);
  digitalWrite(7, LOW);
  loop();
}

String getHttpHeader(unsigned long CardId, word door) {  //Tworzenie zapytania get
 String getBegin = F("GET /auth/door.php");
 String getId = F("?id=");
 String getDoor = F("&door=");
 String getEnd = F(" HTTP/1.1\r\nHost: 10.0.0.22\r\n\r\n");
 return getBegin + getId + CardId + getDoor + door + getEnd;
}

I have a problem with this part:

boolean ServerRequest(){  
  while (client.available() > 0){
     String line = client.readStringUntil('\n');
     line = line.trim();
     Serial.print(line);
         if (line == "true"){
           return true;
         }
         else{
           return false;
   }
 }
}

I guess there is no == operator overload for the String type. Look up the String documentation. I have no need of Strings, so I can't say. I would guess an isEqual method.

Dont you need a concluding return statement in your function ServerRequest ?

The compiler might complain, but the if statement prevents the function from falling off the end.

What value does line.trim() return?

So you don't know the String methods either. I would guess it trims whitespace from the begin and end of the String.

KeithRB: So you don't know the String methods either. I would guess it trims whitespace from the begin and end of the String.

And probably remove duplicate blanks as well wthin the text. You also find this trim function in Microsft Excel.

@Anders53 and KeithRB

Re-read the error in the original post! It refers to the = op NOT the == op !!!!

So christop is right you need to look at what the trim method returns

Mark

holmes4: @Anders53 and KeithRB

Re-read the error in the original post! It refers to the = op NOT the == op !!!!

So christop is right you need to look at what the trim method returns

Mark

Sorry to be a newbie, I really hope I'm not a nuisance to you.

I have looked and looked again at first error post, but cannot see where an operand = is inserted instead of a == operand. Please teach me.

void AccessDenied() {  //zamykanie
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  loop();;
  
}

Oh, I'm not liking that call to loop ()

I have looked and looked again at first error post, but cannot see where an operand = is inserted instead of a == operand.

rfid_.ino:52:11: error: no match for 'operator=' (operand types are 'String' and 'void')

     line = line.trim();

Mark

Thanks Mark - now my nose hurts and I still dont have a clue.

Could you please explain threadowner, what is wrong in his code, leaving me alone with my hurting nose for a while.

According to http://arduino.cc/en/Reference/StringTrim

the trim method acts on the class object

So to trim your String, the code should be

line.trim() ;

and not

line = line.trim() ;

Thanks for help. But i have one more problem. Code actually look like this:

#include <Wiegand.h>
#include <UIPEthernet.h>
WIEGAND wg;
int door = 1;
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 179); 
byte server[] = { 192, 168, 1, 18 }; // ip serwera
EthernetClient client;
 
void setup() {
    wg.begin();
    
     pinMode(7, OUTPUT);
     pinMode(8, OUTPUT);
     pinMode(9, OUTPUT);
     
     Serial.begin(9600);
}
 
void loop() {
  if(wg.available()){
    Ethernet.begin(mac, ip);
            unsigned long cardId = wg.getCode(); //kod karty
            Serial.print(cardId);
            
            String a = getHttpHeader(cardId,door); //string z get
            Serial.println("connecting...");
            
              if (client.connect(server, 80)) {
                  Serial.println("connected");
                  client.println(a);
                  client.println();
                  boolean result = ServerRequest(); 
                    if(result == true){
                         AccessGranted();
                    }
                    else{
                         AccessDenied();
                    }
              }
              else {
                  Serial.println("connection failed");
                  loop();
              }
  }
  
 
}
boolean ServerRequest(){  //zosta ta funkcja 
 if (client.available()) {
    char c = client.read();
   
    
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;);
  }
}
 
void AccessDenied() {  //zamykanie
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  delay(100);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  loop();;
  
}
 
void AccessGranted() {  //otwieranie
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
  delay(5000);
  digitalWrite(9, LOW);
  digitalWrite(7, LOW);
  loop();
}
 
String getHttpHeader(unsigned long CardId, word door) {  //Tworzenie zapytania get
 String getBegin = F("GET /auth/door.php");
 String getId = F("?id=");
 String getDoor = F("&door=");
 String getEnd = F(" HTTP/1.1\r\nHost: 10.0.0.22\r\n\r\n");
 return getBegin + getId + CardId + getDoor + door + getEnd;
}

Reciving request from server doesn’t work. And i have no idea how to serch for true in response.

Thanks for help. But i have one more problem.

Besides cross-posting and ignoring the advice you are getting? Get over it.

Still not liking the indirect recursion.