I'm trying to run a project where I'm going to send data to AWS IOT Core with an Esp32 WROOM32 but using the Arduino IDE.
One of the libraries I'm going to use is WiFiClientSecure.h. When checking a script model from this library, the following compilation error appears:
In file included from c:\Users\vinic\Documents\Arduino\libraries\WiFiClientSecure\src/WiFiClientSecure.h:26,
from C:\Users\vinic\AppData\Local\Temp.arduinoIDE-unsaved2025317-7644-5xoi6g.b2geg\WiFiClientSecure\WiFiClientSecure.ino:9:
c:\Users\vinic\Documents\Arduino\libraries\WiFiClientSecure\src/ssl_client.h:8:10: fatal error: mbedtls/net.h: No such file or directory
8 | #include "mbedtls/net.h"
| ^~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Before anything else, read the pinned post re 'How to get the most from the forum'. That error is how we say 'missing library', which may mean that the board is not compatible, but since we can't see the code, it's difficult to know.
That's the old version of the library, in the wrong place.
Your Documents/Arduino directory is your sketchbook. The libraries there are for user-installed libraries, installed with the Library Manager.
WiFiClientSecure is already part of the ESP32 board platform. Having the extra library has confused things. Try moving the WiFiClientSecure folder out of the sketchbook libraries to somewhere not Arduino-related (Downloads, Pictures, it doesn't really matter -- or you can just delete it so it goes in the Recycle Bin, and it can be restored from there, if necessary). Then try the Verify/Compile/Upload again, with the appropriate ESP32 board selected.
(FYI, ssl_client.h requires mbedtls/net.h in the old v2 of the ESP32 board; but no longer in the current v3, which has been out for like a year.)
My purpose with this library is to communicate with the AWS IoT Core system. From what I understand, this library is installed in the wrong location and your suggestion is to change its directory, correct?
First I made this change and it reported an error saying that the WiFi.h library is not in scope.
After mentioning the WiFi.h library, there was no error when compiling.
WiFiClientSecure is already part of the ESP32 board's core platform. If you can compile and upload an empty sketch, you can use that header and the corresponding code without installing anything else.
The fact that you have another (old) copy installed (elsewhere) has confused matters. The simplest thing is to delete it. (If it gets moved to the Recycle Bin, then you should be able to get it back, if you need it for whatever reason.)
I would guess the error actually said 'WiFi' was not declared in this scope. These sorts of details matter.
You mean after #include-ing it?
This do-nothing sketch
#include <WiFi.h>
#include <WiFiClientSecure.h>
WiFiClientSecure client;
void setup() {
// put your setup code here, to run once:
WiFi.begin("", ""); // Needs SSID and password
}
void loop() {
// put your main code here, to run repeatedly:
}
Doesn't help much to resolve the issue though does it? Just saying, so it's regression to R2 of the ESP32 board driver I suppose. ..
I'm still in V3.0 and I too installed the incriminated library, ran thru my code at least 3 to 5 times in Verify mode (error every time), then deleted the folder as suggested by kenb4, rebooted the IDE and reran Verify; sorted.
Dunno why but it worked... and that is not good, even though i'm happy it does work.
When you compile a sketch, the Arduino sketch build system searches through all the installed libraries to find the ones that contain each of the header files specified by the #include directives in the sketch code. Multiple libraries might contain a header file with the specified filename. In this case, the sketch build system must decide which of the libraries to use.
The decision is made via a sophisticated algorithm, so it usually chooses the correct library, but sometimes it does get it wrong. That is what happened here. All other factors the same, the algorithm will give preference to a standalone library explicitly installed by the user over the library incidentally installed along with the boards platform. So when you installed an incompatible standalone version of the library, you caused that to be used when compiling your sketch instead of the compatible version that was already present in the "esp32" boards platform.
In order to facilitate troubleshooting in cases like this, Arduino IDE displays a list of the matching libraries it found and which it used in the compilation output printed in the black "Output" panel at the bottom of Arduino IDE window. When it thinks the information is not critical, it may only show it if you have File > Preferences > Show verbose output during compile enabled. So if you're in doubt, it's a good idea to turn that option on at least for one compilation. Whenever multiple libraries were found, you will see a "Multiple libraries were found for ..." message in that output. Although it was a problem in this specific case, such a message is not necessarily a sign that something has gone wrong. It is a good idea to check to see whether the intended library was chosen, but otherwise you can safely ignore the message.
Well that's an explanation worth something, thanx ptillisch. However, what I didn't mention was that before I installed the dodgy lib, my sketch never ever complied. It's only after I did the trickery and insisted that it finally compiled. Never looked back since I can now recomplile and no longer have isssues. And after many years of coding using the IDE, I've learnt today that a useful option is available... that I've now enabled, ripper.
This fact does not contradict what I wrote. When Arduino IDE selects an inappropriate library, it might result in either of the two outcomes:
compilation error
runtime fault
The compilation error you encountered is expected in the case where the inappropriately selected library is either incompatible with the architecture of the board you are compiling for, or with the API used by the sketch being compiled.
Arduino IDE will typically show the list of candidates of library dependencies it identified, and which it selected even in cases where the compilation failed (and in fact it will show these even when the verbose compilation output is not enabled in that case).
Nice!
Although I do recommend always keeping the Show verbose output during: ☐ upload preference enabled, the verbose compilation output can be quite massive. So you might find that you prefer to enable Show verbose output during: ☐ compile only when you want to get some deeper insight into the sketch build process, such as in the case where you suspect Arduino IDE might have selected the wrong library.