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

In this 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. The tests from this tutorial were performed using a DFRobot’s ESP32 module integrated in a ESP32 development board.


Introduction

In this 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.

Advertisements
This entry was posted in ESP32 and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s