Commit f1461c2e authored by Marcel Stör's avatar Marcel Stör
Browse files

Tweak theme and update a few modules for consistency

parent f2babb9c
......@@ -11,4 +11,26 @@ blockquote {
/*shifts the nested subnav label to the left to align it with the regular nav item labels*/
ul.subnav ul.subnav span {
padding-left: 1.3em;
}
p {
line-height: 20px;
margin-bottom: 16px;
}
h1, h2 {
border-bottom: 1px solid #eee;
line-height: 1.2;
margin-top: 1.2em;
margin-bottom: 16px;
}
h3, h4, h5, h6 {
margin: 1em 0 0.7em 0;
}
code {
font-size: 85%;
margin-right: 3px;
}
.wy-plain-list-disc, .rst-content .section ul, .rst-content .toctree-wrapper ul, article ul {
line-height: 20px;
margin-bottom: 16px;
}
\ No newline at end of file
# ADC Module
The ADC module provides access to the in-built ADC.
On the ESP8266 there is only a single-channel, which is multiplexed with the
battery voltage. Depending on the setting in the "esp init data" (byte 107)
one can either use the ADC to read an external voltage, or to read the
system voltage, but not both.
On the ESP8266 there is only a single-channel, which is multiplexed with the battery voltage. Depending on the setting in the "esp init data" (byte 107) one can either use the ADC to read an external voltage, or to read the system voltage, but not both.
The default setting in the NodeMCU firmware can be controlled via user_config.h at compile time, by defining one of ESP_INIT_DATA_ENABLE_READVDD33, ESP_INIT_DATA_ENABLE_READADC or ESP_INIT_DATA_FIXED_VDD33_VALUE. To change the setting
at a later date, use Espressif's flash download tool to create a new init data block.
The default setting in the NodeMCU firmware can be controlled via user_config.h at compile time, by defining one of ESP_INIT_DATA_ENABLE_READVDD33, ESP_INIT_DATA_ENABLE_READADC or ESP_INIT_DATA_FIXED_VDD33_VALUE. To change the setting at a later date, use Espressif's flash download tool to create a new init data block.
## adc.read()
Samples the ADC.
####Syntax
`adc.read(channel)`
####Parameters
- `channel`: Always zero on the ESP8266
`channel` always zero on the ESP8266
####Returns
number:the sampled value
the sampled value (number)
####Example
```lua
val = adc.read(0)
```
___
## adc.readvdd33()
Reads the system voltage.
####Syntax
`adc.readvdd33()`
####Parameters
`nil`
none
####Returns
The system voltage, in millivolts.
system voltage in millivolts (number)
If the ESP8266 has been configured to use the ADC for sampling the external pin, this function will always return 65535. This is a hardware and/or SDK limitation.
......@@ -46,4 +36,3 @@ If the ESP8266 has been configured to use the ADC for sampling the external pin,
```lua
mv = adc.readvdd33()
```
___
......@@ -2,170 +2,169 @@
Bit manipulation support, on 32bit integers.
## bit.bnot()
Bitwise negation, equivalent to ~value in C.
## bit.arshift()
Arithmetic right shift a number equivalent to `value >> shift` in C.
####Syntax
`bit.bnot(value)`
`bit.arshift(value, shift)`
####Parameters
value: the number to negate.
- `value` the value to shift
- `shift` positions to shift
####Returns
number: the bitwise negated value of the number.
___
the number shifted right (arithmetically)
## bit.band()
Bitwise AND, equivalent to val1 & val2 & ... & valn in C.
Bitwise AND, equivalent to `val1 & val2 & ... & valn` in C.
####Syntax
`bit.band(val1, val2 [, ... valn])`
####Parameters
- `val1`: first AND argument.
- `val2`: second AND argument.
- `...valn`: ...nth AND argument.
- `val1` first AND argument
- `val2` second AND argument
- `...valn` ...nth AND argument
####Returns
number: the bitwise AND of all the arguments.
___
## bit.bor()
Bitwise OR, equivalent to val1 | val2 | ... | valn in C.
the bitwise AND of all the arguments (number)
## bit.bit()
Generate a number with a 1 bit (used for mask generation). Equivalent to `1 << position` in C.
####Syntax
`bit.bor(val1, val2 [, ... valn])`
`bit.bit(position)`
####Parameters
- `val1`: first OR argument.
- `val2`: second OR argument.
- `...valn`: ...nth OR argument.
`position` position of the bit that will be set to 1
####Returns
number: the bitwise OR of all the arguments.
___
## bit.bxor()
a number with only one 1 bit at position (the rest are set to 0)
Bitwise XOR, equivalent to val1 ^ val2 ^ ... ^ valn in C.
## bit.bnot()
Bitwise negation, equivalent to `~value in C.
####Syntax
`bit.bxor(val1, val2 [, ... valn])`
`bit.bnot(value)`
####Parameters
- `val1`: first XOR argument.
- `val2`: second XOR argument.
- `...valn`: ...nth XOR argument.
`value` the number to negate
####Returns
number: the bitwise XOR of all the arguments.
___
## bit.lshift()
Left-shift a number, equivalent to value << shift in C.
the bitwise negated value of the number
## bit.bor()
Bitwise OR, equivalent to `val1 | val2 | ... | valn` in C.
####Syntax
`bit.lshift(value, shift)`
`bit.bor(val1, val2 [, ... valn])`
####Parameters
- `value`: the value to shift.
- `shift`: positions to shift.
- `val1` first OR argument.
- `val2` second OR argument.
- `...valn` ...nth OR argument
####Returns
number: the number shifted left
___
## bit.rshift()
the bitwise OR of all the arguments (number)
## bit.bxor()
Logical right shift a number, equivalent to ( unsigned )value >> shift in C.
Bitwise XOR, equivalent to `val1 ^ val2 ^ ... ^ valn` in C.
####Syntax
`bit.rshift(value, shift)`
`bit.bxor(val1, val2 [, ... valn])`
####Parameters
- `value`: the value to shift.
- `shift`: positions to shift.
- `val1` first XOR argument
- `val2` second XOR argument
- `...valn` ...nth XOR argument
####Returns
number: the number shifted right (logically).
___
## bit.arshift()
Arithmetic right shift a number equivalent to value >> shift in C.
the bitwise XOR of all the arguments (number)
## bit.clear()
Clear bits in a number.
####Syntax
`bit.arshift(value, shift)`
`bit.clear(value, pos1 [, ... posn])`
####Parameters
- `value`: the value to shift.
- `shift`: positions to shift.
- `value` the base number
- `pos1` position of the first bit to clear
- `...posn` position of thet nth bit to clear
####Returns
number: the number shifted right (arithmetically).
___
## bit.bit()
the number with the bit(s) cleared in the given position(s)
## bit.isclear()
Generate a number with a 1 bit (used for mask generation). Equivalent to 1 << position in C.
Test if a given bit is cleared.
####Syntax
`bit.bit(position)`
`bit.isclear(value, position)`
####Parameters
- `position`: position of the bit that will be set to 1.
- `value` the value to test
- `position` bit position to test
####Returns
number: a number with only one 1 bit at position (the rest are set to 0).
___
## bit.set()
true if the bit at the given position is 0, false othewise
Set bits in a number.
## bit.isset()
Test if a given bit is set.
####Syntax
`bit.set(value, pos1 [, ... posn ])`
`bit.isset(value, position)`
####Parameters
- `value`: the base number.
- `pos1`: position of the first bit to set.
- `...posn`: position of the nth bit to set.
- `value` the value to test
- `position` bit position to test
####Returns
number: the number with the bit(s) set in the given position(s).
___
## bit.clear()
Clear bits in a number.
true if the bit at the given position is 1, false otherwise
## bit.lshift()
Left-shift a number, equivalent to `value << shift` in C.
####Syntax
`bit.clear(value, pos1 [, ... posn])`
`bit.lshift(value, shift)`
####Parameters
- `value`: the base number.
- `pos1`: position of the first bit to clear.
- `...posn`: position of thet nth bit to clear.
- `value` the value to shift
- `shift` positions to shift
####Returns
number: the number with the bit(s) cleared in the given position(s).
___
## bit.isset()
the number shifted left
Test if a given bit is set.
## bit.rshift()
Logical right shift a number, equivalent to `( unsigned )value >> shift` in C.
####Syntax
`bit.isset(value, position)`
`bit.rshift(value, shift)`
####Parameters
- `value`: the value to test.
- `position`: bit position to test.
- `value` the value to shift.
- `shift` positions to shift.
####Returns
boolean: true if the bit at the given position is 1, false otherwise.
___
## bit.isclear()
the number shifted right (logically)
Test if a given bit is cleared.
## bit.set()
Set bits in a number.
####Syntax
`bit.isclear(value, position)`
`bit.set(value, pos1 [, ... posn ])`
####Parameters
- `value`: the value to test.
- `position`: bit position to test.
- `value` the base number.
- `pos1` position of the first bit to set.
- `...posn` position of the nth bit to set.
####Returns
boolean: true if the bit at the given position is 0, false othewise.
___
the number with the bit(s) set in the given position(s)
\ No newline at end of file
......@@ -6,73 +6,86 @@ The node module provides access to system-level features such as sleep, restart
Returns the boot reason code.
This is the raw code, not the new "reset info" code which was introduced in recent SDKs. Values are:
- 1: power-on
- 2: reset (software?)
- 3: hardware reset via reset pin
- 4: WDT reset (watchdog timeout)
####Syntax
`node.bootreason()`
####Parameters
`nil`
none
####Returns
number:the boot reason code
the boot reason code (number)
####Example
```lua
rsn = node.bootreason()
```
___
## node.restart()
Restarts the chip.
## node.chipid()
####Syntax
`node.restart()`
Returns the ESP chip ID.
####Parameters
`nil`
none
####Returns
chip ID (number)
####Example
```lua
id = node.chipid();
```
## node.compile()
Compiles a Lua text file into Lua bytecode, and saves it as .lc file.
####Parameters
`filename` name of Lua text file
####Returns
`nil`
####Example
```lua
node.restart();
file.open("hello.lua","w+")
file.writeline([[print("hello nodemcu")]])
file.writeline([[print(node.heap())]])
file.close()
node.compile("hello.lua")
dofile("hello.lua")
dofile("hello.lc")
```
___
## node.dsleep()
Enter deep sleep mode, wake 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.
Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes.
####Syntax
`node.dsleep(us, option)`
!!! note "Note:"
**Note:** This function can only be used in the condition that esp8266 PIN32(RST) and PIN8(XPD_DCDC aka GPIO16) are connected together. Using sleep(0) will set no wake up timer, connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.<br />
option=0, init data byte 108 is valuable;<br />
option>0, init data byte 108 is valueless.<br />
More details as follows:<br />
0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108.<br />
1, RF_CAL after deep-sleep wake up, there will belarge current.<br />
2, no RF_CAL after deep-sleep wake up, there will only be small current.<br />
4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
This function can only be used in the condition that esp8266 PIN32(RST) and PIN8(XPD_DCDC aka GPIO16) are connected together. Using sleep(0) will set no wake up timer, connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST.
####Parameters
- `us`: number(Integer) or nil, sleep time in micro second. If us = 0, it will sleep forever. If us = nil, will not set sleep time.
- `us` number (integer) or `nil`, sleep time in micro second. If `us == 0`, it will sleep forever. If `us == nil`, will not set sleep time.
- `option`: number(Integer) or nil. If option = nil, it will use last alive setting as default option.
- `option` number (integer) or `nil`. If `nil`, it will use last alive setting as default option.
- 0, init data byte 108 is valuable
- \> 0, init data byte 108 is valueless
- 0, RF_CAL or not after deep-sleep wake up, depends on init data byte 108
- 1, RF_CAL after deep-sleep wake up, there will belarge 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
####Returns
`nil`
####Example
```lua
--do nothing
node.dsleep()
......@@ -83,305 +96,232 @@ node.dsleep(1000000, 4)
--set sleep option only
node.dsleep(nil,4)
```
___
## node.info()
Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed.
## node.flashid()
####Syntax
`node.info()`
Returns the flash chip ID.
####Parameters
`nil`
none
####Returns
- `majorVer` (number)
- `minorVer` (number)
- `devVer` (number)
- `chipid` (number)
- `flashid` (number)
- `flashsize` (number)
- `flashmode` (number)
- `flashspeed` (number)
flash ID (number)
####Example
```lua
majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info()
print("NodeMCU "..majorVer.."."..minorVer.."."..devVer)
flashid = node.flashid();
```
___
## node.chipid()
Returns the ESP chip ID.
## node.heap()
####Syntax
`node.chipid()`
Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible.
####Parameters
`nil`
none
####Returns
number:chip ID
system heap size left in bytes (number)
####Example
```lua
id = node.chipid();
heap_size = node.heap();
```
___
## node.flashid()
Returns the flash chip ID.
####Syntax
`node.flashid()`
####Parameters
`nil`
####Returns
number:flash ID
####Example
```lua
flashid = node.flashid();
```
___
## node.heap()
Returns the current available heap size in bytes. Note that due to fragmentation, actual allocations of this size may not be possible.
## node.info()
####Syntax
`node.heap()`
Returns NodeMCU version, chipid, flashid, flash size, flash mode, flash speed.
####Parameters
`nil`
none
####Returns
number: system heap size left in bytes
- `majorVer` (number)
- `minorVer` (number)
- `devVer` (number)
- `chipid` (number)
- `flashid` (number)
- `flashsize` (number)
- `flashmode` (number)
- `flashspeed` (number)
####Example
```lua
heap_size = node.heap();
majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info()
print("NodeMCU "..majorVer.."."..minorVer.."."..devVer)
```
___
## node.key() --deprecated
Define action to take on button press (on the old devkit 0.9), button connected to GPIO 16.
## node.input()
This function is only available if the firmware was compiled with DEVKIT_VERSION_0_9 defined.
Submits a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation.
!!! note "Note:"
This function only has an effect when invoked from a callback. Using it directly on the console **does not work**.
####Syntax
`node.key(type, function)`
####Parameters
- `type`: type is either string "long" or "short". long: press the key for 3 seconds, short: press shortly(less than 3 seconds)
- `function`: user defined function which is called when key is pressed. If nil, remove the user defined function. Default function: long: change LED blinking rate, short: reset chip
`str` Lua chunk
####Returns
`nil`
####Example
```lua
node.key("long", function() print('hello world') end)
sk:on("receive", function(conn, payload) node.input(payload) end)
```
####See also
- `node.led()`
___
## node.led() --deprecated
[`node.output()`](#nodeoutput)
## node.key() --deprecated
Set the on/off time for the LED (on the old devkit 0.9), with the LED connected to GPIO16, multiplexed with `node.key()`.
Defines action to take on button press (on the old devkit 0.9), button connected to GPIO 16.
This function is only available if the firmware was compiled with DEVKIT_VERSION_0_9 defined.
####Syntax
`node.led(low, high)`
####Parameters
- `low`: LED off time, LED keeps on when low=0. Unit: milliseconds, time resolution: 80~100ms<br />
- `high`: LED on time. Unit: milliseconds, time resolution: 80~100ms
- `type`: type is either string "long" or "short". long: press the key for 3 seconds, short: press shortly(less than 3 seconds)
- `function`: user defined function which is called when key is pressed. If nil, remove the user defined function. Default function: long: change LED blinking rate, short: reset chip
####Returns
`nil`
####Example
```lua
-- turn led on forever.
node.led(0)
node.key("long", function() print('hello world') end)
```
####See also
- `node.key()`
___
## node.input()
Submit a string to the Lua interpreter. Similar to `pcall(loadstring(str))`, but without the single-line limitation.
!!! note "Note:"
## node.led() --deprecated
This function only has an effect when invoked from a callback. Using it directly on the console **does not work**.
Sets the on/off time for the LED (on the old devkit 0.9), with the LED connected to GPIO16, multiplexed with `node.key()`.
####Syntax
`node.input(str)`
This function is only available if the firmware was compiled with DEVKIT_VERSION_0_9 defined.
####Parameters
- `str`: Lua chunk
- `low` LED off time, LED keeps on when low=0. Unit: milliseconds, time resolution: 80~100ms<br />
- `high` LED on time. Unit: milliseconds, time resolution: 80~100ms
####Returns
`nil`
####Example
```lua
sk:on("receive", function(conn, payload) node.input(payload) end)
-- turn led on forever.
node.led(0)
```
####See also
- `node.output()`
___
## node.output()
Redirects the Lua interpreter output to a callback function. Optionally also prints it to the serial console.
!!! note "Note:"
Do **not** attempt to `print()` or otherwise induce the Lua interpreter to produce output from within the callback function. Doing so results in infinite recursion, and leads to a watchdog-triggered restart.
####Syntax
`node.output(output_fn, serial_debug)`
Do **not** attempt to `print()` or otherwise induce the Lua interpreter to produce output from within the callback function. Doing so results in infinite recursion, and leads to a watchdog-triggered restart.
####Parameters
- `output_fn(str)`: a function accept every output as str, and can send the output to a socket (or maybe a file).
- `serial_debug`: 1 output also show in serial. 0: no serial output.
- `output_fn(str)` a function accept every output as str, and can send the output to a socket (or maybe a file).
- `serial_debug` 1 output also show in serial. 0: no serial output.
####Returns
`nil`
####Example
```lua
function tonet(str)
sk:send(str)
end
node.output(tonet, 1) -- serial also get the lua output.
function tonet(str)
sk:send(str)
end
node.output(tonet, 1) -- serial also get the lua output.
```
```lua
-- a simple telnet server
s=net.createServer(net.TCP)
s:listen(2323,function(c)
con_std = c
function s_output(str)
if(con_std~=nil)
then con_std:send(str)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
c:on("receive",function(c,l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
c:on("disconnection",function(c)
con_std = nil
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
end)
-- a simple telnet server
s=net.createServer(net.TCP)
s:listen(2323,function(c)
con_std = c
function s_output(str)
if(con_std~=nil)
then con_std:send(str)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
c:on("receive",function(c,l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
c:on("disconnection",function(c)
con_std = nil
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
end)
```
####See also
- `node.input()`
___
## node.readvdd33() --deprecated, moved to adc.readvdd33()
####See also
- `adc.readvdd33()`
___
## node.compile()
[`node.input()`](#nodeinput)
Compile a Lua text file into Lua bytecode, and save it as .lc file.
## node.readvdd33() --deprecated
Moved to [`adc.readvdd33()`](adc/#adcreadvdd33).
####Syntax
`node.compile(filename)`
## node.restart()
Restarts the chip.
####Parameters
- `filename`: name of Lua text file
none
####Returns
`nil`
####Example
```lua
file.open("hello.lua","w+")
file.writeline([[print("hello nodemcu")]])
file.writeline([[print(node.heap())]])
file.close()
node.compile("hello.lua")
dofile("hello.lua")
dofile("hello.lc")
node.restart();
```
___
## node.setcpufreq()
Change the working CPU Frequency.
## node.restore()
Restores system configuration to defaults. Erases all stored WiFi settings, and resets the "esp init data" to the defaults. This function is intended as a last-resort without having to reflash the ESP altogether.
####Syntax
`node.setcpufreq(speed)`
This also uses the SDK function `system_restore()`, which doesn't document precisely what it erases/restores.
####Parameters
- `speed`: `node.CPU80MHZ` or `node.CPU160MHZ`
none
####Returns
number:target CPU Frequency
`nil`
####Example
```lua
node.setcpufreq(node.CPU80MHZ)
node.restore()
node.restart() -- ensure the restored settings take effect
```
___
## node.restore()
Restore system configuration to defaults. Erases all stored WiFi settings, and resets the "esp init data" to the defaults. This function is intended as a last-resort without having to reflash the ESP altogether.
This also uses the SDK function `system_restore()`, which doesn't document precisely what it erases/restores.
## node.setcpufreq()
####Syntax
`node.restore()`
Change the working CPU Frequency.
####Parameters
`nil`
`speed` constant 'node.CPU80MHZ' or 'node.CPU160MHZ'
####Returns
`nil`
target CPU frequency (number)
####Example
```lua
node.restore()
node.restart() -- ensure the restored settings take effect
node.setcpufreq(node.CPU80MHZ)
```
___
## node.stripdebug()
Controls the amount of debug information kept during `node.compile()`, and
allows removal of debug information from already compiled Lua code.
Controls the amount of debug information kept during `node.compile()`, and allows removal of debug information from already compiled Lua code.
Only recommended for advanced users, the NodeMCU defaults are fine for almost all use cases.
####Syntax
`node.stripdebug([level[, function]])``
####Parameters
- `level`:
- `level`
- 1: don't discard debug info
- 2: discard Local and Upvalue debug info
- 3: discard Local, Upvalue and line-number debug info
- function: a compiled function to be stripped per setfenv except 0 is not permitted.
- `function` a compiled function to be stripped per setfenv except 0 is not permitted.
If no arguments are given then the current default setting is returned. If function is omitted, this is the default setting for future compiles. The function argument uses the same rules as for `setfenv()`.
#### Returns
If invoked without arguments, returns the current level settings. Otherwise, `nil` is returned.
......@@ -392,5 +332,5 @@ node.compile('bigstuff.lua')
```
####See also
- `node.compile()`
___
[`node.compile()`](#nodecompile)
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