ESP32 (7) – menuconfig

luca 23/01/2017 0

You’ve already learned in the previous tutorials that all the configuration of the esp-idf framework is done using a configuration menu:



You can use the same menu to set options/parameters for the program you’re developing: in today’s tutorial I’m going to explain how to do it!


The framework‘s config menu is configured via some text files. The syntax of those files is similar to the one used to configure the Linux kernel, known as the kconfig language.

To be able to add your own configuration items, first you have to create a file named Kconfig.projbuild in the same folder of your source code:


All the content of the file is enclosed by the following two lines:

menu "Nome menu"

which define the name of the menu that will group all your custom parameters. For example is you type

menu "Custom configuration"

you’ll see:


The most common configuration parameters have the following structure:

config <parameter name>
  <parameter type> <prompt>
  range min max
  default <default value>
    <help text>

Parameter type can have the following values:

  • string, text parameters
  • int, parameters with integer values
  • hex, parameters displayed in hexadecimal format
  • bool, parameters with boolean values

If for example you need to configure the TCP port a server is listening on, you can define the corresponding parameter as it follows:

config TcpPort
  int "Server TCP port"
  range 1 65535
  default 80
    Enter the TCP port the server is listening on

You can also create menu items with multiple choices:

  config <choice_1>
    bool <prompt>
  config <choice_2>
    bool <prompt>
  default <default choice>

Once configured, the parameter values are saved in the sdkconfig file within the project’s main folder:


The name of the constants that correspond to the different parameters is CONFIG_<parameter name>. For the example above, the constant that corresponds to the TCP port you have to use in your program is CONFIG_TcpPort.

In my Github repository you can find a complete example. The Kconfig.projbuild file defines some parameters to demonstrate the use of the different types:


Once configured, you can find the parameters’ values in the sdkconfig file:


and if you run the program, the values are also displayed on the serial port:



The ability to extend the use of the menuconfig of the framework to include also custom parameters of your program allows to configure all the aspects of your project in a handy, unified way. In the previous tutorial the configuration of the wifi network (SSID and password) was hardcoded in the source of the program: a better choice is now to move  those parameters out of the code and insert them in the configuration menu… as exercise, try to do it!

Leave A Response »

This website uses cookies to ensure you get the best experience on our website maggiori informazioni

Questo sito utilizza i cookie per fonire la migliore esperienza di navigazione possibile. Continuando a utilizzare questo sito senza modificare le impostazioni dei cookie o clicchi su "Accetta" permetti al loro utilizzo.