The maximum sleep time is 4294967295us, ~71 minutes. This is an SDK limitation.
Theoretical maximum deep sleep duration can be found with [`node.dsleepMax()`](#nodedsleepmax). ["Max deep sleep for ESP8266"](https://thingpulse.com/max-deep-sleep-for-esp8266/) claims the realistic maximum be around 3.5h.
Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes.
!!! caution
!!! caution
...
@@ -107,10 +106,7 @@ Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes.
...
@@ -107,10 +106,7 @@ Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes.
- 1, RF_CAL after deep-sleep wake up, there will be large current
- 1, RF_CAL after deep-sleep wake up, there will be large current
- 2, no RF_CAL after deep-sleep wake up, there will only be small current
- 2, no RF_CAL after deep-sleep wake up, there will only be small current
- 4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current
- 4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current
-`instant` number (integer) or `nil`. If present and non-zero, do not use
-`instant` number (integer) or `nil`. If present and non-zero, the chip will enter Deep-sleep immediately and will not wait for the Wi-Fi core to be shutdown.
the normal grace time before entering deep sleep. This is a largely
undocumented feature, and is only briefly mentioned in Espressif's
[low power solutions](https://espressif.com/sites/default/files/documentation/9b-esp8266_low_power_solutions_en.pdf#page=10) document (chapter 4.5).
#### Returns
#### Returns
`nil`
`nil`
...
@@ -131,6 +127,37 @@ node.dsleep(nil,4)
...
@@ -131,6 +127,37 @@ node.dsleep(nil,4)
-[`wifi.suspend()`](wifi.md#wifisuspend)
-[`wifi.suspend()`](wifi.md#wifisuspend)
-[`wifi.resume()`](wifi.md#wifiresume)
-[`wifi.resume()`](wifi.md#wifiresume)
-[`node.sleep()`](#nodesleep)
-[`node.sleep()`](#nodesleep)
-[`node.dsleepMax()`](#nodedsleepmax)
## node.dsleepMax()
Returns the current theoretical maximum deep sleep duration.
!!! caution
While it is possible to specify a longer sleep time than the theoretical maximum sleep duration, it is not recommended to exceed this maximum. In tests documented at ["Max deep sleep for ESP8266"](https://thingpulse.com/max-deep-sleep-for-esp8266/) the device never woke up again if the specified sleep time was beyond `dsleepMax()`.
!!! note
This theoretical maximum is dependent on ambient temperature: lower temp = shorter sleep duration, higher temp = longer sleep duration
#### Syntax
`node.dsleepMax()`
#### Parameters
none
#### Returns
`max_duration`
#### Example
```lua
node.dsleep(node.dsleepMax())
```
#### See also
-[`node.dsleep()`](#nodedsleep)
## node.flashid()
## node.flashid()
...
@@ -158,6 +185,27 @@ none
...
@@ -158,6 +185,27 @@ none
#### Returns
#### Returns
flash size in bytes (integer)
flash size in bytes (integer)
## node.getcpufreq()
Get the current CPU Frequency.
#### Syntax
`node.getcpufreq()`
#### Parameters
none
#### Returns
Current CPU frequency (number)
#### Example
```lua
do
localcpuFreq=node.getcpufreq()
print("The current CPU frequency is "..cpuFreq.." MHz")
end
```
## node.heap()
## node.heap()
Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible.
Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible.
...
@@ -333,30 +381,32 @@ Put NodeMCU in light sleep mode to reduce current consumption.
...
@@ -333,30 +381,32 @@ Put NodeMCU in light sleep mode to reduce current consumption.
* NodeMCU can not enter light sleep mode if wifi is suspended.
* NodeMCU can not enter light sleep mode if wifi is suspended.
* All active timers will be suspended and then resumed when NodeMCU wakes from sleep.
* All active timers will be suspended and then resumed when NodeMCU wakes from sleep.
* Any previously suspended timers will be resumed when NodeMCU wakes from sleep.
!!! attention
!!! attention
This is disabled by default. Modify `PMSLEEP_ENABLE` in `app/include/user_config.h` to enable it.
This is disabled by default. Modify `PMSLEEP_ENABLE` in `app/include/user_config.h` to enable it.
-`duration` Sleep duration in microseconds(μs). If a sleep duration of `0` is specified, suspension will be indefinite (Range: 0 or 50000 - 268435454 μs (0:4:28.000454))
<!--- timed light_sleep currently does not work, the 'duration' parameter is here as a place holder--->
-`wake_pin` 1-12, pin to attach wake interrupt to. Note that pin 0(GPIO 16) does not support interrupts.
<!--- * `duration` Sleep duration in microseconds(μs). If a sleep duration of `0` is specified, suspension will be indefinite (Range: 0 or 50000 - 268435454 μs (0:4:28.000454))--->
- If sleep duration is indefinite, `wake_pin` must be specified
- Please refer to the [`GPIO module`](gpio.md) for more info on the pin map.
*`wake_pin` 1-12, pin to attach wake interrupt to. Note that pin 0(GPIO 16) does not support interrupts.
-`int_type` type of interrupt that you would like to wake on. (Optional, Default: `node.INT_LOW`)
<!---* If sleep duration is indefinite, `wake_pin` must be specified--->
- valid interrupt modes:
* Please refer to the [`GPIO module`](gpio.md) for more info on the pin map.
-`node.INT_UP` Rising edge
*`int_type` type of interrupt that you would like to wake on. (Optional, Default: `node.INT_LOW`)
-`node.INT_DOWN` Falling edge
* valid interrupt modes:
-`node.INT_BOTH` Both edges
*`node.INT_UP` Rising edge
-`node.INT_LOW` Low level
*`node.INT_DOWN` Falling edge
-`node.INT_HIGH` High level
*`node.INT_BOTH` Both edges
-`resume_cb` Callback to execute when WiFi wakes from suspension. (Optional)
*`node.INT_LOW` Low level
-`preserve_mode` preserve current WiFi mode through node sleep. (Optional, Default: true)
*`node.INT_HIGH` High level
- If true, Station and StationAP modes will automatically reconnect to previously configured Access Point when NodeMCU resumes.
*`resume_cb` Callback to execute when WiFi wakes from suspension. (Optional)
- If false, discard WiFi mode and leave NodeMCU in `wifi.NULL_MODE`. WiFi mode will be restored to original mode on restart.
*`preserve_mode` preserve current WiFi mode through node sleep. (Optional, Default: true)
* If true, Station and StationAP modes will automatically reconnect to previously configured Access Point when NodeMCU resumes.
* If false, discard WiFi mode and leave NodeMCU in `wifi.NULL_MODE`. WiFi mode will be restored to original mode on restart.
#### Returns
#### Returns
-`nil`
-`nil`
...
@@ -379,15 +429,15 @@ Put NodeMCU in light sleep mode to reduce current consumption.
...
@@ -379,15 +429,15 @@ Put NodeMCU in light sleep mode to reduce current consumption.
cfg.preserve_mode=false
cfg.preserve_mode=false
node.sleep(cfg)
node.sleep(cfg)
```
<!---
--Put NodeMCU in light sleep mode for 10 seconds with resume callback
--Put NodeMCU in light sleep mode for 10 seconds with resume callback
cfg={}
cfg={}
cfg.duration=10*1000*1000
cfg.duration=10*1000*1000
cfg.resume_cb=function() print("WiFi resume") end
cfg.resume_cb=function() print("WiFi resume") end
node.sleep(cfg)
node.sleep(cfg)
--->
```
#### See also
#### See also
-[`wifi.suspend()`](wifi.md#wifisuspend)
-[`wifi.suspend()`](wifi.md#wifisuspend)
...
@@ -484,7 +534,7 @@ provides more detailed information on the EGC.
...
@@ -484,7 +534,7 @@ provides more detailed information on the EGC.
-`mode`
-`mode`
-`node.egc.NOT_ACTIVE` EGC inactive, no collection cycle will be forced in low memory situations
-`node.egc.NOT_ACTIVE` EGC inactive, no collection cycle will be forced in low memory situations
-`node.egc.ON_ALLOC_FAILURE` Try to allocate a new block of memory, and run the garbage collector if the allocation fails. If the allocation fails even after running the garbage collector, the allocator will return with error.
-`node.egc.ON_ALLOC_FAILURE` Try to allocate a new block of memory, and run the garbage collector if the allocation fails. If the allocation fails even after running the garbage collector, the allocator will return with error.
-`node.egc.ON_MEM_LIMIT` Run the garbage collector when the memory used by the Lua script goes beyond an upper `limit`. If the upper limit can't be satisfied even after running the garbage collector, the allocator will return with error.
-`node.egc.ON_MEM_LIMIT` Run the garbage collector when the memory used by the Lua script goes beyond an upper `limit`. If the upper limit can't be satisfied even after running the garbage collector, the allocator will return with error. If the given limit is negative, it is interpreted as the desired amount of heap which should be left available. Whenever the free heap (as reported by `node.heap()` falls below the requested limit, the garbage collector will be run.
-`node.egc.ALWAYS` Run the garbage collector before each memory allocation. If the allocation fails even after running the garbage collector, the allocator will return with error. This mode is very efficient with regards to memory savings, but it's also the slowest.
-`node.egc.ALWAYS` Run the garbage collector before each memory allocation. If the allocation fails even after running the garbage collector, the allocator will return with error. This mode is very efficient with regards to memory savings, but it's also the slowest.
-`level` in the case of `node.egc.ON_MEM_LIMIT`, this specifies the memory limit.
-`level` in the case of `node.egc.ON_MEM_LIMIT`, this specifies the memory limit.
...
@@ -495,6 +545,23 @@ provides more detailed information on the EGC.
...
@@ -495,6 +545,23 @@ provides more detailed information on the EGC.
`node.egc.setmode(node.egc.ALWAYS, 4096) -- This is the default setting at startup.`
`node.egc.setmode(node.egc.ALWAYS, 4096) -- This is the default setting at startup.`
`node.egc.setmode(node.egc.ON_ALLOC_FAILURE) -- This is the fastest activeEGC mode.`
`node.egc.setmode(node.egc.ON_ALLOC_FAILURE) -- This is the fastest activeEGC mode.`
`node.egc.setmode(node.egc.ON_MEM_LIMIT, 30720) -- Only allow the Lua runtime to allocate at most 30k, collect garbage if limit is about to be hit`
`node.egc.setmode(node.egc.ON_MEM_LIMIT, -6144) -- Try to keep at least 6k heap available for non-Lua use (e.g. network buffers)`
## node.egc.meminfo()
Returns memory usage information for the Lua runtime.
-`total_allocated` The total number of bytes allocated by the Lua runtime. This is the number which is relevant when using the `node.egc.ON_MEM_LIMIT` option with positive limit values.
-`estimated_used` This value shows the estimated usage of the allocated memory.
@@ -9,7 +9,7 @@ This module depens on [SQLite3](http://www.sqlite.org/) library developed by Dwa
...
@@ -9,7 +9,7 @@ This module depens on [SQLite3](http://www.sqlite.org/) library developed by Dwa
For instruction on how to use this module or further documentation, please, refer to [LuaSQLite3 Documentation](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki).
For instruction on how to use this module or further documentation, please, refer to [LuaSQLite3 Documentation](http://lua.sqlite.org/index.cgi/doc/tip/doc/lsqlite3.wiki).
This module is a stripped down version of SQLite, with every possible OMIT_\* configuration enable. The enabled OMIT_\* directives are available in the module's [Makefile](../../../app/sqlite3/Makefile).
This module is a stripped down version of SQLite, with every possible OMIT_\* configuration enable. The enabled OMIT_\* directives are available in the module's [config file](../../../app/sqlite3/config_ext.h).
The SQLite3 module vfs layer integration with NodeMCU was developed by me.
The SQLite3 module vfs layer integration with NodeMCU was developed by me.
@@ -62,11 +62,9 @@ Functions supported in timer object:
...
@@ -62,11 +62,9 @@ Functions supported in timer object:
-[`t:alarm()`](#tmralarm)
-[`t:alarm()`](#tmralarm)
-[`t:interval()`](#tmrinterval)
-[`t:interval()`](#tmrinterval)
-[`t:register()`](#tmrregister)
-[`t:register()`](#tmrregister)
-[`t:resume()`](#tmrresume)
-[`t:start()`](#tmrstart)
-[`t:start()`](#tmrstart)
-[`t:state()`](#tmrstate)
-[`t:state()`](#tmrstate)
-[`t:stop()`](#tmrstop)
-[`t:stop()`](#tmrstop)
-[`t:suspend()`](#tmrsuspend)
-[`t:unregister()`](#tmrunregister)
-[`t:unregister()`](#tmrunregister)
#### Parameters
#### Parameters
...
@@ -184,61 +182,6 @@ mytimer:start()
...
@@ -184,61 +182,6 @@ mytimer:start()
-[`tmr.create()`](#tmrcreate)
-[`tmr.create()`](#tmrcreate)
-[`tmr.alarm()`](#tmralarm)
-[`tmr.alarm()`](#tmralarm)
## tmr.resume()
Resume an individual timer.
Resumes a timer that has previously been suspended with either `tmr.suspend` or `tmr.suspend_all`
#### Syntax
`tmr.resume(id/ref)`
#### Parameters
`id/ref` timer id (0-6) or object, obsolete for OO API (→ [`tmr.create()`](#tmrcreate))
#### Returns
`true` if timer was resumed successfully
#### Example
```lua
--resume timer mytimer
mytimer:resume()
--alternate metod
tmr.resume(mytimer)
```
#### See also
-[`tmr.suspend()`](#tmrsuspend)
-[`tmr.suspend_all()`](#tmrsuspendall)
-[`tmr.resume_all()`](#tmrresumeall)
## tmr.resume_all()
Resume all timers.
Resumes all timers including those previously been suspended with either `tmr.suspend` or `tmr.suspend_all`
#### Syntax
`tmr.resume_all()`
#### Parameters
none
#### Returns
`true` if timers were resumed successfully
#### Example
```lua
--resume all previously suspended timers
tmr.resume_all()
```
#### See also
-[`tmr.suspend()`](#tmrsuspend)
-[`tmr.suspend_all()`](#tmrsuspendall)
-[`tmr.resume()`](#tmrresume)
## tmr.softwd()
## tmr.softwd()
Provides a simple software watchdog, which needs to be re-armed or disabled before it expires, or the system will be restarted.
Provides a simple software watchdog, which needs to be re-armed or disabled before it expires, or the system will be restarted.
...
@@ -336,72 +279,6 @@ if not mytimer:stop() then print("timer not stopped, not registered?") end
...
@@ -336,72 +279,6 @@ if not mytimer:stop() then print("timer not stopped, not registered?") end
-[`tmr.stop()`](#tmrstop)
-[`tmr.stop()`](#tmrstop)
-[`tmr.unregister()`](#tmrunregister)
-[`tmr.unregister()`](#tmrunregister)
## tmr.suspend()
Suspend an armed timer.
!!! attention
This is disabled by default. Modify `ENABLE_TIMER_SUSPEND` in `app/include/user_config.h` to enable it.
* Timers can be suspended at any time after they are armed.
* If a timer is rearmed with `tmr.start` or `tmr.alarm` any matching suspended timers will be discarded.
#### Syntax
`tmr.suspend(id/ref)`
#### Parameters
`id/ref` timer id (0-6) or object, obsolete for OO API (→ [`tmr.create()`](#tmrcreate))
#### Returns
`true` if timer was resumed successfully
#### Example
```lua
--suspend timer mytimer
mytimer:suspend()
--alternate metod
tmr.suspend(mytimer)
```
#### See also
-[`tmr.suspend_all()`](#tmrsuspendall)
-[`tmr.resume()`](#tmrresume)
-[`tmr.resume_all()`](#tmrresumeall)
## tmr.suspend_all()
Suspend all currently armed timers.
!!! attention
This is disabled by default. Modify `ENABLE_TIMER_SUSPEND` in `app/include/user_config.h` to enable it.
!!! Warning
This function suspends ALL active timers, including any active timers started by the NodeMCU subsystem or other modules. this may cause parts of your program to stop functioning properly.
USE THIS FUNCTION AT YOUR OWN RISK!
#### Syntax
`tmr.suspend_all()`
#### Parameters
none
#### Returns
`true` if timers were suspended successfully
#### Example
```lua
--suspend timer mytimer
tmr.suspend_all()
```
#### See also
-[`tmr.suspendl()`](#tmrsuspend)
-[`tmr.resume()`](#tmrresume)
-[`tmr.resume_all()`](#tmrresumeall)
## tmr.time()
## tmr.time()
Returns the system uptime, in seconds. Limited to 31 bits, after that it wraps around back to zero.
Returns the system uptime, in seconds. Limited to 31 bits, after that it wraps around back to zero.