Introduction

In this tutorial, we will check how to get the ESP32 SDK version used in the Arduino core from our programs.

Since the Arduino core uses the IDF (Espressif IoT Development Framework) under the hood, we will be basically retrieving this framework’s version. You can read IDF’s programming guide here.

The tests were performed using a DFRobot’s ESP32 module integrated in a ESP32 development board.

The code

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.

Serial.begin(115200)

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.

Serial.println("Using ESP object:");
Serial.println(ESP.getSdkVersion());

 Alternatively, we can use a lower level function called esp_get_idf_version, which does exactly the same. You can check the implementation of this function at the IDF source code here.

Serial.println("Using lower level function:");
Serial.println(esp_get_idf_version());

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.

You can check the complete source code below.

void setup() {

  Serial.begin(115200);

  Serial.println("Using ESP object:");
  Serial.println(ESP.getSdkVersion());

  Serial.println("Using lower level function:");
  Serial.println(esp_get_idf_version());
}

void loop() {}

 Testing the code

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.

ESP32 Print IDF SDK version.png

            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.

version-dev-NNN-gXXXXXX