Solved: Read line from web, set relay acording to line

Hello.
Problem is to detect character. Web server is responding to "client.print(String("GET ")" with 010 where 2 first digits are relays and last one is to enter OTP mode. This works.

// Read all the lines of the reply from server and print them to Serial
while(client.available()){
line = client.readStringUntil('\r'); // String

Here i can do a " Serial.println(line); " and it will respond with 010
Then detect if first character is 0 or 1

// Relay 1
if (line.charAt(1) == "1") { do something...
Responds with "error: ISO C++ forbids comparison between pointer and integer [-fpermissive]"

or

if (line.substring(1,1) == "1") { do something...
Compiles OK, Serial responds with nothing

Neither works. How can I solve this?

check what type is returned by [

 line.charAt(1)

](charAt() - Arduino Reference)... you'll find your answer

(hint a cString with only 1 character is not the same as one character)

best is to not use the String class though...

Thank you for your reply.
We are now at the edge of my knowlege.
Can you explain further?

B4x4:
Can you explain further?

"a" is not the same as 'a'

the first one is a cString (a null terminated array of characters - first byte is the ASCII code of the letter a and then a 0 byte ) and the latter is just one byte in memory initialized with the ASCII code of the lettre a

when you have a cString in your code, it's actually represented by the pointer to the start of the memory array so the error you get when you do

if ([color=blue]line.charAt(1)[/color] == [color=red]"1"[/color]) { do something...}
error: ISO C++ forbids [color=red]comparison between pointer and integer[/color] [-fpermissive]

is because "1" is actually a pointer to the start of the array whereas [color=blue]line.charAt(1)[/color] returns just a character (an integral number)... you need to compare characters with characters

does this help ? see the issue?

Yes. Thank you.
The solution was

if ((line.charAt(1) == '0') && (line.charAt(2) == '0' ))

To use '0' not "0" or just 0

Good :slight_smile: