arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
282 stars 170 forks source link

Error on building : "HttpClient.cpp:87:61: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses] if (!iClient->connect(iServerName, iServerPort) > 0)" #97

Open genotix opened 3 years ago

genotix commented 3 years ago

There is this Mobile library TinyGSM that uses that ArduinoHttpClient library for an HTTPS example. I have been working to try and do a HTTPS PUT with the TTGO T-Call v1.4 ; an ESP32 WROVER-B with a SIM800L GPRS module.

I have tried this https://github.com/vshymanskyy/TinyGSM/blob/master/examples/HttpsClient/HttpsClient.ino but immediately receive the following error in Arduino IDE:

Warning: Board breadboard:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp: In member function 'int HttpClient::startRequest(const char*, const char*, const char*, int, const byte*)':
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp:87:61: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
             if (!iClient->connect(iServerName, iServerPort) > 0)
                                                             ^
/Users/genotix/Documents/Arduino/libraries/ArduinoHttpClient-0.4.0/src/HttpClient.cpp:97:64: error: logical not is only applied to the left hand side of comparison [-Werror=logical-not-parentheses]
             if (!iClient->connect(iServerAddress, iServerPort) > 0)
                                                                ^
cc1plus: some warnings being treated as errors
exit status 1
Error compiling for board ESP32 Dev Module.

Since it is the demo example I am wondering what could be in err here. Would appreciate any hints. :) 👍

per1234 commented 3 years ago

The ESP32 platform authors used an innovative approach to advocating for warning-free code: https://github.com/espressif/arduino-esp32/blob/1.0.4/platform.txt#L18-L21

compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Werror=all
compiler.warning_flags.all=-Wall -Werror=all -Wextra

What this does is add the -Werror=all flag to the compilation command when you have the Arduino IDE's File > Preferences > Compiler warnings set to "More" or "All". The -Werror=all flag causes compiler warnings to be upgraded to errors.

You can see this is the cause of the error you got:

some warnings being treated as errors

Of course, the solution is to fix the library code that is causing the warning. But if you need a provisional workaround you can set the Arduino IDE's File > Preferences > Compiler warnings to "Default" when compiling sketches that use this library. Since the extra warnings you get from the "More" or "All" settings can be very useful, I recommend changing your compiler warnings setting to the higher level when you are working with clean code that doesn't generate warnings under normal conditions.

genotix commented 3 years ago

Thank you very much for this clear explanation! I have been able to change it and could continue!