[EN] ESP Class

This article is a detailed look at the ESP.h file of esp8266 Arduino to learn the functions that are very useful for programming to control the operation of this microcontroller such as knowing the amount of memory remaining or the largest memory size that can be reserved. This is used if you want to write a program that uses dynamic memory to store a list of all found APs, for example, programmers can use this class directly from the ESP object.


The list of constants defined in ESP.h consists of 4 groups, and each group contains the following list of constants:

  • WDTO_t is a constant used to define a time interval for WDT (Watch-dog-Timer), including:
    • WDTO_0MS
    • WDTO_15MS
    • WDTO_30MS
    • WDTO_60MS
    • WDTO_120MS
    • WDTO_250MS
    • WDTO_500MS
    • WDTO_1S
    • WDTO_2S
    • WDTO_4S
    • WDTO_8S
  • RGMode is a constant to store the RF mode types, including
    • RF_CAL
    • RF_NO_CAL
  • ADCMode is the ADC’s mode constant.
    • ADC_TOUT
    • ADC_TOUT_3V3
    • ADC_VCC
    • ADC_VDD
  • FlashMode_t is the flash memory mode type value:
    • FM_QIO
    • FM_QOUT
    • FM_DIO
    • FM_DOUT

Commands about WDT

WDT or Watch Dog Timer is a microcontroller’s clock used for self-renewal if the running software does not send a response back to the system by calling a function ESP.wdtFeed(). This is to prevent the system from going idle without being able to do anything, such as a hang, etc. The list of commands in this group are:

  • ESP.wdtEnable( The time value required for the software to respond )
  • ESP.wdtDisable()
  • ESP.wdtFeed()

Power saving mode command

To order the microcontroller to go into power-saving mode consists of 3 commands as follows.

  • ESP.deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT)
  • ESP.deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT)
  • uint64_t ESP.deepSleepMax()

System reset command

If you want to reset the system or reboot the system, use the following commands :

  • ESP.reset()
  • ESP.reboot()
  • ESP.rebootIntoUartDownloadMode()
  • String ESP.getResetReason()
  • String ESP.getResetInfo()
  • struct rst_info * ESP.getResetInfoPtr()


The commands to read and write user memory data from the RTC module are as follows:

  • bool ESP.rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
  • bool ESP.rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);

Chip’s information

Instructions for reading the information of the ESP8266 chip to know the capacity of Flash/RAM or various model numbers, etc., including the following commands

  • uint16_t ESP.getVcc()
  • uint32_t ESP.getChipId()
  • uint32_t ESP.getFreeHeap()
  • uint16_t ESP.getMaxFreeBlockSize()
  • uint8_t ESP.getHeapFragmentation() percentage (%)
  • ESP.getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr)
  • uint32_t ESP.getFreeContStack()
  • ESP.resetFreeContStack()
  • const char * ESP.getSdkVersion()
  • String ESP.getCoreVersion()
  • String ESP.getFullVersion()
  • uint8_t ESP.getBootVersion()
  • uint8_t ESP.getBootMode()
  • uint8_t ESP.getCpuFreqMHz()
  • uint8_t *ESP.random(uint8_t *resultArray, const size_t outputSizeBytes)
  • uint32_t ESP.random()
  • uint32_t ESP.getCycleCount()
  • ESP.setDramHeap() heap from DRAM
  • ESP.setIramHeap() heap from IRAM
  • ESP.setExternalHeap() heap from external memory
  • ESP.resetHeap() heap from default memory

Flash memory commands

The list of instructions related to microcontroller flash memory is as follows.

  • uint32_t ESP.getFlashChipId()
  • uint8_t ESP.getFlashChipVendorId()
  • uint32_t ESP.getFlashChipRealSize()
  • uint32_t ESP.getFlashChipSize()
  • uint32_t ESP.getFlashChipSpeed()
  • FlashMode_t ESP.getFlashChipMode()
  • uint32_t ESP.getFlashChipSizeByChipId()
  • uint32_t ESP.magicFlashChipSize(uint8_t byte)
  • uint32_t ESP.magicFlashChipSize(uint8_t byte)
  • FlashMode_t ESP.magicFlashChipMode(uint8_t byte)
  • bool ESP.checkFlashConfig(bool needsEquals = false)
  • bool ESP.checkFlashCRC()
  • bool ESP.flashEraseSector(uint32_t sector)
  • bool ESP.flashWrite(uint32_t address, const uint32_t *data, size_t size)
  • bool ESP.flashWrite(uint32_t address, const uint8_t *data, size_t size)
  • bool ESP.flashRead(uint32_t address, uint32_t *data, size_t size
  • bool ESP.flashRead(uint32_t address, uint8_t *data, size_t size)
  • bool ESP.eraseConfig()

Program commands

The list of commands related to the program or Sketch is as follows.

  • uint32_t ESP.getSketchSize()
  • String ESP.getSketchMD5()
  • uint32_t ESP.getFreeSketchSpace()
  • bool ESP.updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true)

Examples of use such as

  Serial.print("ESP.getBootMode(); ");

  Serial.print("ESP.getResetReason(); ");
  Serial.print("ESP.getResetInfo(); ");

  Serial.print("ESP.getMaxFreeBlockSize(); ");
  Serial.print("ESP.getHeapFragmentation(); ");
  Serial.print("ESP.getFreeHeap(): ");
  Serial.print("ESP.getSdkVersion(); ");
  Serial.print("ESP.getBootVersion(); ");
  Serial.print("ESP.getChipId(); ");
  Serial.print("ESP.getFlashChipSize(); ");
  Serial.print("ESP.getFlashChipRealSize(); ");
  Serial.print("ESP.getFlashChipSizeByChipId(); ");
  Serial.print("ESP.getFlashChipId(); ");


This is a list of instructions within the ESP class which is the core class of the esp8266 microcontroller. Hopefully, it will be helpful in further study. Finally, have fun with programming.

If you want to talk with us, feel free to leave comments below!!


  1. esp8266 / Arduino : ESP.h

(C) 2021, By Jarut Busarathid and Danai Jedsadathitikul

Updated 2021-11-17