0

$USD

$USD
TUTORIALS ESP32

ESP32 Espruino Tutorial: Get SDK version, free heap and software reset

DFRobot Jul 30 2018 1545

Introduction

In this esp32 tutorial we will check how to use some ESP32 specific functionalities on Espruino. We will analyze how to obtain the SDK version, the number of free bytes available on the heap and how to perform a software reset on the device.

These tasks are very easy to perform since Espruino offers a simple interface for them. More precisely, we can use some methods of the ESP32 class to do all of the above, as we will see on the code.

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

The code

In order to get the SDK version and the free heap, we will first need to get the data structure that holds that information.

To do it, we need to call the getState method of the ESP32 class. This method receives no arguments and returns an object containing some information, which includes the SDK version and the free heap.

We will store the output of this method call in a variable.

var state = ESP32.getState();

The first thing we are going to print is the SDK version. To do it, we need to access the sdkVersion attribute of the returned object.

console.log("SDK: " + state.sdkVersion);

To get the available free heap, in bytes, we need to access the freeHeap attribute of our object.

console.log("Free heap: " + state.freeHeap);

Finally, to finish the code, we will perform a reboot on the ESP32. We do this by calling the reboot method also on the ESP32 class.

ESP32.reboot();

The final code can be seen below.

var state = ESP32.getState();

console.log("SDK: " + state.sdkVersion);
console.log("Free heap: " + state.freeHeap);

ESP32.reboot();

 

Testing the code

To test the code, simply run the previous script on the Espruino IDE. The expected result is illustrated in figure 1.

ESP32 Espruino software reset sdk version and free heap.png

Figure 1 – Result of running the Espruino script.

As can be seen in the first highlighted area, the script outputs the SDK version and the number of bytes available on the heap.

After that, a software reset is performed. As can be seen in the second highlighted area, the typical reset message is printed and then the Espruino prompt starts again.