The code for this tutorial will be very simple. We will not need to include any libraries, since the functions we will use are already available by default.
The first thing we need to do in the Arduino setup function is opening a serial connection, so we can output the results of our program and later get them using the Arduino IDE serial monitor.
To get the SDK version, we can follow two distinct approaches. The first one corresponds to using the ESP extern variable that is available by default in our programs.
This extern variable is an object of class EspClass and its header file can be seen here. One of the methods that this class exposes is called getSdkVersion and, as its name suggests, allows to retrieve the SDK version that is being used under the hood by the Arduino core version running on the ESP32.
Note that the getSdkVersion method calls the esp_get_idf_version function under the hood, as can be seen in the file that contains its implementation. Thus, that method serves only as a wrapper for the lower level function call. Taking this into account, it is expected that both approaches return the same output.
To test the code, simply compile it and upload it to your device using the Arduino IDE. Once the procedure finishes, open the IDE serial monitor. You should get an output similar to the one shown in figure 1.
Figure 1 – Output of the program that prints the SDK version.
As expected, the output returned by both the getSdkVersion method and the esp_get_idf_version function are equal.
As explained in this GitHub issue, the version follows the format below, where version corresponds to SDK version, NNN to the number of commits since the development of that version started and XXXXXX to the commit ID.