Editing
esp
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==ESP-specific functions== Here is a description of the [[deep sleep|ESP specific API's]].<br> <br> ===ESP.deepSleep()=== ESP.deepSleep(microseconds, mode) will put the chip into deep sleep. mode is one of WAKE_RF_DEFAULT WAKE_RFCAL WAKE_NO_RFCAL WAKE_RF_DISABLED. (GPIO16 needs to be tied to RST to wake from deepSleep.) The chip can sleep for at most <b>ESP.deepSleepMax()</b> microseconds. If you implement deep sleep with WAKE_RF_DISABLED and require WiFi functionality on wake up, you will need to implement an additional WAKE_RF_DEFAULT before WiFi functionality is available. ESP.deepSleepInstant(microseconds, mode) works similarly to ESP.deepSleep but sleeps instantly without waiting for WiFi to shutdown. ;Steps to use the Deep-sleep mode: # Connect the module with the Wi-Fi AP # Perform a task like reading a sensor value, publishing an MQTT message, etc. # Sleep for a defined number of microseconds # Repeat the above process again Sleep time is defined in microseconds. According to the ESP8266 SDK, you can only sleep for 4,294,967,295 µs which is about ~71 minutes. Example: Serial.println("deep sleep for 15 seconds"); ESP.deepSleep(15e6); The system goes into Deep-sleep mode via the following interface: ESPdeepSleep(uint32 time_in_us) If time is == 0, then the chip won’t be woken up at regular intervals, i.e., won’t wake up automatically. ESP.dsleep(0) //Will cause the ESP to sleep forever. The mode WAKE_RF_DISABLED doesn't change how deep-sleep works, the mode changes what happens when the device wakes up. In deep-sleep WiFi is always off, no matter what mode you give it. WAKE_RF_DISABLED disables WiFi when you reset the device/it wakes up. {{template:toponly}} ===ESP.reset=== ESP.reset() is a hard reset and can leave some of the registers in the old state which can lead to problems, it's more or less like the reset button on the PC. <br> {{template:toponly}} ===ESP.restart=== ESP.restart() tells the SDK to reboot, so it's a more clean reboot, use this one if possible.<br> {{template:toponly}} ===ESP.getResetReason()=== ESP.getResetReason() returns a String containing the last reset reason in human readable format.<br> ;Sample code: <nowiki>#include "ESP8266WiFi.h" #include <Kaywinnet.h> const char ssid[] = MYSSID; const char password[] = MYPASSWORD; void setup() { Serial.begin(115200); while (!Serial); //Wait for serial to be ready delay(500); Serial.println("..."); Serial.println(F("WiFi_Test.ino")); Serial.print(F("WiFi Connecting to: ")); Serial.print(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(WiFi.status()); Serial.print(F(" ")); } Serial.println(""); Serial.print(F("ResetReason= ")); Serial.println(ESP.getResetReason()); } void loop() { }</nowiki> ;Reset Reasons: ;rst cause: :REASON_DEFAULT_RST = 0, /* normal startup by power on */ :REASON_WDT_RST = 1, /* hardware watch dog reset */ :REASON_EXCEPTION_RST = 2, /* exception reset, GPIO status won’t change */ :REASON_SOFT_WDT_RST = 3, /* software watch dog reset, GPIO status won’t change */ :REASON_SOFT_RESTART = 4, /* software restart ,system_restart , GPIO status won’t change */ :REASON_DEEP_SLEEP_AWAKE = 5, /* wake up from deep-sleep */ :REASON_EXT_SYS_RST = 6 /* external system reset */ <br> {{template:toponly}} ===ESP.getFreeHeap()=== ESP.getFreeHeap() returns the free heap size.<br> {{template:toponly}} ===ESP.getHeapFragmentation()=== ESP.getHeapFragmentation() returns the fragmentation metric (0% is clean, more than ~50% is not harmless)<br> {{template:toponly}} ===ESP.getMaxFreeBlockSize()=== ESP.getMaxFreeBlockSize() returns the maximum allocatable ram block regarding heap fragmentation<br> {{template:toponly}} ===ESP.getChipId()=== ESP.getChipId() returns the ESP8266 chip ID as a 32-bit integer.<br> {{template:toponly}} ===ESP.getCoreVersion()=== ESP.getCoreVersion() returns a String containing the core version.<br> {{template:toponly}} ===ESP.getSdkVersion()=== ESP.getSdkVersion() returns the SDK version as a char.<br> {{template:toponly}} ===ESP.getCpuFreqMHz()=== ESP.getCpuFreqMHz() returns the CPU frequency in MHz as an unsigned 8-bit integer.<br> {{template:toponly}} ===ESP.getSketchSize()=== ESP.getSketchSize() returns the size of the current sketch as an unsigned 32-bit integer.<br> {{template:toponly}} ===ESP.getFreeSketchSpace()=== ESP.getFreeSketchSpace() returns the free sketch space as an unsigned 32-bit integer.<br> {{template:toponly}} ===ESP.getSketchMD5()=== ESP.getSketchMD5() returns a lowercase String containing the MD5 of the current sketch.<br> {{template:toponly}} ===ESP.getFlashChipId()=== ESP.getFlashChipId() returns the flash chip ID as a 32-bit integer.<br> {{template:toponly}} ===ESP.getFlashChipSize()=== ESP.getFlashChipSize() returns the flash chip size, in bytes, as seen by the SDK (may be less than actual size).<br> {{template:toponly}} ===ESP.getFlashChipRealSize()=== ESP.getFlashChipRealSize() returns the real chip size, in bytes, based on the flash chip ID.<br> {{template:toponly}} ===ESP.getFlashChipSpeed(void)=== ESP.getFlashChipSpeed(void) returns the flash chip frequency, in Hz.<br> {{template:toponly}} ===ESP.getCycleCount()=== ESP.getCycleCount() returns the cpu instruction cycle count since start as an unsigned 32-bit. This is useful for accurate timing of very short actions like bit banging.<br> {{template:toponly}} ===ESP.getVcc()=== ESP.getVcc() may be used to measure supply voltage. ESP needs to reconfigure the ADC at startup in order for this feature to be available. Add the following line to the top of your sketch to use getVcc: ADC_MODE(ADC_VCC); TOUT pin has to be disconnected in this mode.<br> ''Note'' that by default ADC is configured to read from TOUT pin using analogRead(A0), and ESP.getVCC() is not available.<br> {{template:top}}
Summary:
Please note that all contributions to Notebook may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Notebook:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Home Page
C++ Reference
ESP Hardware
ESPHome
Home Assistant
Network Stuff
Tools
What links here
Related changes
Special pages
Page information