Unverified Commit 8b84445a authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2391 from nodemcu/dev

Next master snap
parents 67027c0d 2cc195d5
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include "../crypto/digests.h" #include "../crypto/digests.h"
#include "../crypto/mech.h" #include "../crypto/mech.h"
#include "pm/swtimer.h"
#define PROTOCOL_SECURE "wss://" #define PROTOCOL_SECURE "wss://"
#define PROTOCOL_INSECURE "ws://" #define PROTOCOL_INSECURE "ws://"
...@@ -560,6 +562,7 @@ static void ws_initReceiveCallback(void *arg, char *buf, unsigned short len) { ...@@ -560,6 +562,7 @@ static void ws_initReceiveCallback(void *arg, char *buf, unsigned short len) {
os_timer_disarm(&ws->timeoutTimer); os_timer_disarm(&ws->timeoutTimer);
os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_sendPingTimeout, conn); os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_sendPingTimeout, conn);
SWTIMER_REG_CB(ws_sendPingTimeout, SWTIMER_RESUME)
os_timer_arm(&ws->timeoutTimer, WS_PING_INTERVAL_MS, true); os_timer_arm(&ws->timeoutTimer, WS_PING_INTERVAL_MS, true);
espconn_regist_recvcb(conn, ws_receiveCallback); espconn_regist_recvcb(conn, ws_receiveCallback);
...@@ -706,6 +709,7 @@ static void dns_callback(const char *hostname, ip_addr_t *addr, void *arg) { ...@@ -706,6 +709,7 @@ static void dns_callback(const char *hostname, ip_addr_t *addr, void *arg) {
// Set connection timeout timer // Set connection timeout timer
os_timer_disarm(&ws->timeoutTimer); os_timer_disarm(&ws->timeoutTimer);
os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_connectTimeout, conn); os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_connectTimeout, conn);
SWTIMER_REG_CB(ws_connectTimeout, SWTIMER_RESUME)
os_timer_arm(&ws->timeoutTimer, WS_CONNECT_TIMEOUT_MS, false); os_timer_arm(&ws->timeoutTimer, WS_CONNECT_TIMEOUT_MS, false);
if (ws->isSecure) { if (ws->isSecure) {
...@@ -867,6 +871,7 @@ void ws_close(ws_info *ws) { ...@@ -867,6 +871,7 @@ void ws_close(ws_info *ws) {
os_timer_disarm(&ws->timeoutTimer); os_timer_disarm(&ws->timeoutTimer);
os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_forceCloseTimeout, ws->conn); os_timer_setfn(&ws->timeoutTimer, (os_timer_func_t *) ws_forceCloseTimeout, ws->conn);
SWTIMER_REG_CB(ws_forceCloseTimeout, SWTIMER_RESUME);
os_timer_arm(&ws->timeoutTimer, WS_FORCE_CLOSE_TIMEOUT_MS, false); os_timer_arm(&ws->timeoutTimer, WS_FORCE_CLOSE_TIMEOUT_MS, false);
} }
} }
...@@ -87,8 +87,7 @@ dofile("hello.lc") ...@@ -87,8 +87,7 @@ dofile("hello.lc")
Enters deep sleep mode, wakes up when timed out. Enters deep sleep mode, wakes up when timed out.
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
local cpuFreq = 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.
#### Syntax #### Syntax
`node.sleep({wake_gpio[, duration, int_type, resume_cb, preserve_mode]})` <!---`node.sleep({wake_pin[, duration, int_type, resume_cb, preserve_mode]})`--->
`node.sleep({wake_pin[, int_type, resume_cb, preserve_mode]})`
#### Parameters #### Parameters
- `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.
####Syntax
`total_allocated, estimated_used = node.egc.meminfo()`
#### Parameters
None.
#### Returns
- `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.
# node.task module # node.task module
......
...@@ -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.
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
This module provides a simple interface to [TCS34725 colour/light sensors](https://www.adafruit.com/product/1334) (Adafruit). This module provides a simple interface to [TCS34725 colour/light sensors](https://www.adafruit.com/product/1334) (Adafruit).
Note that you must call [`setup()`](#tcs34725setup) before you can start reading values! !!! Warning
You must call [`setup()`](#tcs34725setup) before you can start reading values!
## tcs34725.setup() ## tcs34725.setup()
setupializes module. setupialization is mandatory before values can be read. Initialization via this call is mandatory before values can be read.
#### Syntax #### Syntax
......
...@@ -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.
......
...@@ -121,7 +121,7 @@ SECTIONS ...@@ -121,7 +121,7 @@ SECTIONS
/* *libwpa.a:*(.literal .text) - tested that safe to keep in iROM */ /* *libwpa.a:*(.literal .text) - tested that safe to keep in iROM */
/* *libwps.a:*(.literal .text) - tested that safe to keep in iROM */ /* *libwps.a:*(.literal .text) - tested that safe to keep in iROM */
*(.iram.text .iram0.text) *(.iram.text .iram0.text .iram0.text.*)
*(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) *(.stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
......
wifi.setmode(wifi.SOFTAP) wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid="test",pwd="12345678"}) wifi.ap.config({ ssid = "test", pwd = "12345678" })
gpio.mode(1, gpio.OUTPUT) gpio.mode(1, gpio.OUTPUT)
srv=net.createServer(net.TCP) srv = net.createServer(net.TCP)
srv:listen(80,function(conn) srv:listen(80, function(conn)
conn:on("receive", function(client,request) conn:on("receive", function(client, request)
local buf = "" local buf = ""
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP") local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
if(method == nil)then if (method == nil) then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP") _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
end end
local _GET = {} local _GET = {}
if (vars ~= nil)then if (vars ~= nil) then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v _GET[k] = v
end end
end end
buf = buf.."<h1> Hello, NodeMcu.</h1><form src=\"/\">Turn PIN1 <select name=\"pin\" onchange=\"form.submit()\">" buf = buf .. "<!DOCTYPE html><html><body><h1>Hello, this is NodeMCU.</h1><form src=\"/\">Turn PIN1 <select name=\"pin\" onchange=\"form.submit()\">"
local _on,_off = "","" local _on, _off = "", ""
if(_GET.pin == "ON")then if (_GET.pin == "ON") then
_on = " selected=true" _on = " selected=true"
gpio.write(1, gpio.HIGH) gpio.write(1, gpio.HIGH)
elseif(_GET.pin == "OFF")then elseif (_GET.pin == "OFF") then
_off = " selected=\"true\"" _off = " selected=\"true\""
gpio.write(1, gpio.LOW) gpio.write(1, gpio.LOW)
end end
buf = buf.."<option".._on..">ON</opton><option".._off..">OFF</option></select></form>" buf = buf .. "<option" .. _on .. ">ON</option><option" .. _off .. ">OFF</option></select></form></body></html>"
client:send(buf) client:send(buf)
end) end)
conn:on("sent", function (c) c:close() end) conn:on("sent", function(c) c:close() end)
end) end)
...@@ -6,7 +6,7 @@ Works: ...@@ -6,7 +6,7 @@ Works:
- entering the chip's to shutdown mode (350uA -> 5uA power consumption) - entering the chip's to shutdown mode (350uA -> 5uA power consumption)
- waking up the chip from shutdown - waking up the chip from shutdown
##Require ## Require
```lua ```lua
LM92 = require("lm92") LM92 = require("lm92")
``` ```
...@@ -16,19 +16,19 @@ LM92 = nil ...@@ -16,19 +16,19 @@ LM92 = nil
package.loaded["lm92"]=nil package.loaded["lm92"]=nil
``` ```
##setup() ## setup()
####Description #### Description
Setting the address for lm92. Setting the address for lm92.
####Syntax #### Syntax
setup(sda, scl, address) setup(sda, scl, address)
####Parameters #### Parameters
address: 0x48~0x4b, i2c address (depends on tha A0~A1 pins) address: 0x48~0x4b, i2c address (depends on tha A0~A1 pins)
####Returns #### Returns
nil nil
####Example #### Example
```lua ```lua
LM92 = require("lm92") LM92 = require("lm92")
gpio0 = 3 gpio0 = 3
...@@ -39,126 +39,126 @@ addr = 0x48 ...@@ -39,126 +39,126 @@ addr = 0x48
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
LM92.setup(addr) LM92.setup(addr)
``` ```
##getTemperature() ## getTemperature()
####Description #### Description
Returns the temperature register's content. Returns the temperature register's content.
####Syntax #### Syntax
getTemperature() getTemperature()
####Parameters #### Parameters
- -
####Returns #### Returns
Temperature in degree Celsius. Temperature in degree Celsius.
####Example #### Example
```lua ```lua
t = LM92.getTemperature() t = LM92.getTemperature()
print("Got temperature: "..t.." C") print("Got temperature: "..t.." C")
``` ```
##wakeup() ## wakeup()
####Description #### Description
Makes the chip exit the low power shutdown mode. Makes the chip exit the low power shutdown mode.
####Syntax #### Syntax
wakeup() wakeup()
####Parameters #### Parameters
- -
####Returns #### Returns
- -
####Example #### Example
```lua ```lua
LM92.wakeup() LM92.wakeup()
tmr.delay( 1 * 1000 * 1000 ) tmr.delay( 1 * 1000 * 1000 )
``` ```
##shutdown() ## shutdown()
####Description #### Description
Makes the chip enter the low power shutdown mode. Makes the chip enter the low power shutdown mode.
####Syntax #### Syntax
shutdown() shutdown()
####Parameters #### Parameters
- -
####Returns #### Returns
- -
####Example #### Example
```lua ```lua
LM92.shutdown() LM92.shutdown()
``` ```
##setThyst() ## setThyst()
####Description #### Description
Set hysteresis Temperature. Set hysteresis Temperature.
####Syntax #### Syntax
setThyst(data_wr) setThyst(data_wr)
####Parameters #### Parameters
data_wr: 130~-55 ºC, hysteresis Temperature data_wr: 130~-55 ºC, hysteresis Temperature
####Returns #### Returns
nil nil
####Example #### Example
```lua ```lua
LM92.setThyst(3) LM92.setThyst(3)
``` ```
##setTcrit() ## setTcrit()
####Description #### Description
Set Critical Temperature. Set Critical Temperature.
####Syntax #### Syntax
setTcrit(data_wr) setTcrit(data_wr)
####Parameters #### Parameters
data_wr: 130~-55 ºC, Critical Temperature data_wr: 130~-55 ºC, Critical Temperature
####Returns #### Returns
nil nil
####Example #### Example
```lua ```lua
LM92.setTcrit(100.625) LM92.setTcrit(100.625)
``` ```
##setTlow() ## setTlow()
####Description #### Description
Set Low Window Temperature. Set Low Window Temperature.
####Syntax #### Syntax
setTlow(data_wr) setTlow(data_wr)
####Parameters ####Parameters
data_wr: 130~-55 ºC, Low Window Temperature data_wr: 130~-55 ºC, Low Window Temperature
####Returns #### Returns
nil nil
####Example #### Example
```lua ```lua
LM92.setTlow(32.25) LM92.setTlow(32.25)
``` ```
##setThigh() ## setThigh()
####Description ####Description
Set High Window Temperature. Set High Window Temperature.
####Syntax #### Syntax
setThigh(data_wr) setThigh(data_wr)
####Parameters #### Parameters
data_wr: 130~-55 ºC, High Window Temperature data_wr: 130~-55 ºC, High Window Temperature
####Returns #### Returns
nil nil
####Example ####Example
...@@ -166,83 +166,84 @@ nil ...@@ -166,83 +166,84 @@ nil
LM92.setThigh(27.5) LM92.setThigh(27.5)
``` ```
##getThyst() ## getThyst()
####Description #### Description
Get hysteresis Temperature. Get hysteresis Temperature.
####Syntax #### Syntax
getThyst() getThyst()
####Parameters #### Parameters
-- --
####Returns #### Returns
Hysteresis Temperature in degree Celsius. Hysteresis Temperature in degree Celsius.
####Example #### Example
```lua ```lua
t = LM92.getThyst() t = LM92.getThyst()
print("Got hysteresis temperature: "..t.." C") print("Got hysteresis temperature: "..t.." C")
``` ```
##getTcrit() ## getTcrit()
####Description #### Description
Get Critical Temperature. Get Critical Temperature.
####Syntax #### Syntax
getTcrit() getTcrit()
####Parameters #### Parameters
-- --
####Returns #### Returns
Critical Temperature in degree Celsius. Critical Temperature in degree Celsius.
####Example #### Example
```lua ```lua
t = LM92.getTcrit() t = LM92.getTcrit()
print("Got Critical temperature: "..t.." C") print("Got Critical temperature: "..t.." C")
``` ```
##getTlow() ## getTlow()
####Description #### Description
Get Low Window Temperature. Get Low Window Temperature.
####Syntax #### Syntax
getTlow() getTlow()
####Parameters #### Parameters
-- --
####Returns #### Returns
Low Window Temperature in degree Celsius. Low Window Temperature in degree Celsius.
####Example #### Example
```lua ```lua
t = LM92.getTlow() t = LM92.getTlow()
print("Got Low Window temperature: "..t.." C") print("Got Low Window temperature: "..t.." C")
``` ```
##getThigh() ## getThigh()
####Description #### Description
Get High Window Temperature. Get High Window Temperature.
####Syntax #### Syntax
getThigh() getThigh()
####Parameters #### Parameters
-- --
####Returns #### Returns
High Window Temperature in degree Celsius. High Window Temperature in degree Celsius.
####Example #### Example
```lua ```lua
t = LM92.getThigh() t = LM92.getThigh()
print("Got High Window temperature: "..t.." C") print("Got High Window temperature: "..t.." C")
``` ```
##Full example ## Full example
```lua
--node.compile("lm92.lua") --node.compile("lm92.lua")
LM92 = require("lm92") LM92 = require("lm92")
gpio0 = 3 gpio0 = 3
...@@ -270,6 +271,7 @@ t = LM92.getTlow() ...@@ -270,6 +271,7 @@ t = LM92.getTlow()
print("Got Low: "..t.." C") print("Got Low: "..t.." C")
t = LM92.getThigh() t = LM92.getThigh()
print("Got High: "..t.." C") print("Got High: "..t.." C")
```
#### TODO: #### TODO:
- add full support of the features, including interrupt and critical alert support - add full support of the features, including interrupt and critical alert support
...@@ -15,15 +15,4 @@ void call_user_start(void); ...@@ -15,15 +15,4 @@ void call_user_start(void);
#include_next "osapi.h" #include_next "osapi.h"
#ifdef ENABLE_TIMER_SUSPEND
extern void swtmr_register(void* timer_ptr);
#undef os_timer_arm
#define os_timer_arm(timer_ptr, duration, mode) do{swtmr_register(timer_ptr); \
ets_timer_arm_new(timer_ptr, duration, mode, 1);}while(0);
extern void swtmr_unregister(void* timer_ptr);
#undef os_timer_disarm
#define os_timer_disarm(timer_ptr) do{swtmr_unregister(timer_ptr); ets_timer_disarm(timer_ptr);}while(0);
#endif
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment