Hi,
I hope this is the right place to post found mistakes in the documentation.
I stumbled upon the Reference for the "connect()" function of the class "Client" that can be found here.
My question concerns the example code on the page.
First of all the "[Get Code]" link does not work.
Secondly: Every non-zero integer is evaluated as true in c++ and connect() only returns non-zero characters. Therefore client.connect() will always return true when evaluated as a condition. This means the else part of the following code will never be reached:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
I would suggest to change the code to
if (client.connect(server, 80) == 1) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
It is not a big mistake, but it bothered me enough to create an account just to post this ![]()