Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
07027385
Commit
07027385
authored
Nov 07, 2014
by
funshine
Browse files
update readme
parent
51267c76
Changes
1
Show whitespace changes
Inline
Side-by-side
README.md
View file @
07027385
# **nodeMcu API Instruction** #
version 0.1 2014-10-11
change log:
2014-11-5
delete log operation api from node module
add log module
modify wifi module api
modify node.key long_press and short_press default function
key is triged only when key is released
###version 0.1 2014-10-11
###change log:
2014-11-5
<br
/>
delete log operation api from node module
<br
/>
add log module
<br
/>
modify wifi module api
<br
/>
modify node.key long_press and short_press default function
<br
/>
key is triged only when key is released
<br
/>
# Summary
-
Easy to access wireless router
...
...
@@ -49,175 +51,178 @@
#Firmware Program
Address
: eagle.app.v6.flash.bin: 0x00000
: eagle.app.v6.irom0text.bin: 0x10000
: esp_init_data_default.bin: 0x7c000
: blank.bin: 0x7e000
###Address
eagle.app.v6.flash.bin: 0x00000
<br
/>
eagle.app.v6.irom0text.bin: 0x10000
<br
/>
esp_init_data_default.bin: 0x7c000
<br
/>
blank.bin: 0x7e000
#node module
<a
id=
"nm_restart"
></a>
## node.restart()
Description
: module restart.
####Description
module restart.
####Syntax
node.restart()
Syntax
: node.restart()
####Parameters
null
Parameter
s
:
null
####Return
s
null
Returns
: null
####Example
Example
:
****
```
node.restart();
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
<a
id=
"nm_dsleep"
></a>
## node.dsleep()
Description
: enter deep sleep mode for us micro seconds,restart when timed out
us: sleep time in micro second
####Description
Syntax
: node.dsleep(us)
Note: This function can only be used in the condition of connecting esp8266 PIN32(rst) and PIN8(XPD_DCDC) together.
enter deep sleep mode for us micro seconds,restart when timed out
<br
/>
us: sleep time in micro second
Parameters
: us:sleep time in micro second
####Syntax
Returns
: null
node.dsleep(us)
<br
/>
**-Note:**
This function can only be used in the condition of connecting esp8266 PIN32(rst) and PIN8(XPD_DCDC) together.
####Parameters
us:sleep time in micro second
####Returns
null
####Example
Example
:
****
```
node.dsleep(us);
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
<a
id=
"nm_chipid"
></a>
## node.chipid()
Description
: return chip identifier
####Description
return chip identifier
####Syntax
node.chipid()
Syntax
: node.chipid()
####Parameters
null
Parameter
s
: null
####Return
s
number:chip identifier
Returns
: number:chip identifier
####Example
Example
:
****
```
uint32 id = node.chipid();
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
<a
id=
"nm_heap"
></a>
## node.heap()
Description
:
return the available RAM size in bytes
####
Description
return the available RAM size in bytes
Syntax
:
node.heap()
####
Syntax
node.heap()
Parameters
:
null
####
Parameters
null
Returns
: number:system heap size left in bytes
####Returns
number:system heap size left in bytes
####Example
Example
:
****
```
uint32 heap_size = node.heap();
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
<a
id=
"nm_key"
></a>
## node.key()
Description
:
define button function.
####
Description
define button function.
Syntax
:
node.key(type, function())
####
Syntax
node.key(type, function())
Parameters
:
type: type is either string ”long” or ”short”. long: press the button for 3 seconds, short: press shortly(less than 3 seconds)
function(): user defined function for button. If null, cancling the user defined function, function are initialized to default.
Default function: long:change LED blinking rate, short:reset chip
####
Parameters
type: type is either string ”long” or ”short”. long: press the button for 3 seconds, short: press shortly(less than 3 seconds)
<br
/>
function(): user defined function for button. If null, cancling the user defined function, function are initialized to default.
<br
/>
Default function: long:change LED blinking rate, short:reset chip
Returns
:
null
####
Returns
null
Example
:
####Example
```
node.key(long, function(){print('hello world')})
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
<a
id=
"nm_led"
></a>
## node.led()
Description
: setup the on/off time for led
####Description
setup the on/off time for led
####Syntax
node.key(type, function())
Syntax
: node.key(type, function())
####Parameters
Low: LED off time, 0 for LED keeps on. Unit: milliseconds, time resolution: 80~100ms
<br
/>
High: LED off time. Unit: milliseconds, time resolution: 80~100ms
Parameters
: Low: LED off time, 0 for LED keeps on. Unit: milliseconds, time resolution: 80~100ms
High: LED off time. Unit: milliseconds, time resolution: 80~100ms
####Returns
null
Returns
: null
####Example
Example
:
****
```
//turn led on forever.
node.led(0,null);
```
See also
:
**-**
[](
)
####
See also
**-**
[](
)
#log module
<a
id=
"lg_format"
></a>
## log.format()
Description
:
format flash for users.
####
Description
format flash for users.
Syntax
:
log.format()
####
Syntax
log.format()
Parameters
:
null
####
Parameters
null
Returns
: null
####Returns
null
####Example
Example
:
****
```
//record log to init.lua. Call the file after system restart.
log.format()
...
...
@@ -226,27 +231,28 @@ Example
log.stoplog()
```
See also
:
**-**
[
log.startlog()
](
#lg_startlog
)
:
**-**
[
log.stoplog()
](
#lg_stoplog
)
####
See also
**-**
[
log.startlog()
](
#lg_startlog
)
<br
/>
**-**
[
log.stoplog()
](
#lg_stoplog
)
<a
id=
"lg_startlog"
></a>
## log.startlog()
Description
: start to log input
####Description
start to log input
####Syntax
log.startlog(filename, noparse)
Syntax
: log.startlog(filename, noparse)
####Parameters
Parameters
: filename: log file, directories are not supported
noparse: 1 for lua VM doesn’t parse input, 0 for lua VM parse input
filename: log file, directories are not supported
<br
/>
noparse: 1 for lua VM doesn’t parse input, 0 for lua VM parse input
Returns
: null
####Returns
null
####Example
Example
:
****
```
//record log to init.lua. Call the file after system restart.
log.format()
...
...
@@ -256,26 +262,26 @@ Example
//At this point, the content of init.lua is “print(“hello world”)”. When system restart, print(“hello world”) are excuted.
```
See also
:
**-**
[
log.format()
](
#lg_format
)
:
**-**
[
log.stoplog()
](
#lg_stoplog
)
####
See also
**-**
[
log.format()
](
#lg_format
)
<br
/>
**-**
[
log.stoplog()
](
#lg_stoplog
)
<a
id=
"lg_stoplog"
></a>
## log.stoplog()
Description
: stop log.
####Description
stop log.
####Syntax
log.stoplog()
Syntax
: log.stoplog()
####Parameters
null
Parameter
s
:
null
####Return
s
null
Returns
: null
####Example
Example
:
****
```
//record log to init.lua. Call the file after system restart.
log.format()
...
...
@@ -285,26 +291,26 @@ Example
//At this point, the content of init.lua is “print(“hello world”)”. When system restart, print(“hello world”) are excuted.
```
See also
:
**-**
[
log.format()
](
#lg_format
)
:
**-**
[
log.startlog()
](
#lg_startlog
)
####
See also
**-**
[
log.format()
](
#lg_format
)
<br
/>
**-**
[
log.startlog()
](
#lg_startlog
)
<a
id=
"lg_open"
></a>
## log.open()
Description
:
open the log file
####
Description
open the log file
Syntax
:
log.open(filename)
####
Syntax
log.open(filename)
Parameters
:
filename: log file, directories are not supported
####
Parameters
filename: log file, directories are not supported
Returns
: null
####Returns
null
####Example
Example
:
****
```
//print the first line of 'init.lua'
log.open(“init.lua”)
...
...
@@ -312,26 +318,26 @@ Example
log.close()
```
See also
:
**-**
[
log.close()
](
#lg_close
)
:
**-**
[
log.readline()
](
#lg_readline
)
####
See also
**-**
[
log.close()
](
#lg_close
)
<br
/>
**-**
[
log.readline()
](
#lg_readline
)
<a
id=
"lg_close"
></a>
## log.close()
Description
: close the log file which opened before
####Description
close the log file which opened before
####Syntax
log.close()
Syntax
: log.close()
####Parameters
null
Parameter
s
:
null
####Return
s
null
Returns
: null
####Example
Example
:
****
```
//print the first line of 'init.lua'
log.open(“init.lua”)
...
...
@@ -339,26 +345,26 @@ Example
log.close()
```
See also
:
**-**
[
log.open()
](
#lg_open
)
:
**-**
[
log.readline()
](
#lg_readline
)
####
See also
**-**
[
log.open()
](
#lg_open
)
<br
/>
**-**
[
log.readline()
](
#lg_readline
)
<a
id=
"lg_readline"
></a>
## log.readline()
Description
:
read log file which is opened before line by line.
####
Description
read log file which is opened before line by line.
Syntax
:
log.readline()
####
Syntax
log.readline()
Parameters
:
null
####
Parameters
null
Returns
: log file content in string
####Returns
log file content in string
####Example
Example
:
****
```
//print the first line of 'init.lua'
log.open(“init.lua”)
...
...
@@ -366,312 +372,310 @@ Example
log.close()
```
See also
:
**-**
[
log.open()
](
#lg_open
)
:
**-**
[
log.close()
](
#lg_close
)
####
See also
**-**
[
log.open()
](
#lg_open
)
**-**
[
log.close()
](
#lg_close
)
<a
id=
"lg_list"
></a>
## log.list()
Description
: list all files.
####Description
list all files.
####Syntax
log.list()
Syntax
: log.list()
####Parameters
null
Parameter
s
:
null
####Return
s
null
Returns
: null
####Example
Example
:
****
```
log.list();
```
See also
:
**-**
[
log.format()
](
#lg_format
)
####
See also
**-**
[
log.format()
](
#lg_format
)
#wifi module
##CONSTANT
:
wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
<a
id=
"wf_setmode"
></a>
## wifi.setmode(mode)
Description
: set wifi working mode.
####Description
set wifi working mode.
####Syntax
wifi.setmode(mode)
Syntax
: wifi.setmode(mode)
####Parameters
mode: value should be: wifi. STATION, wifi.SOFTAP or wifi.STATIONAP
Parameter
s
: mode: value should be: wifi. STATION, wifi.SOFTAP or wifi.STATIONAP
####Return
s
current mode after setup
Returns
: current mode after setup
####Example
Example
:
****
```
wifi.setmode(wifi.STATION)
```
See also
:
**-**
[
wifi.getmode()
](
#wf_getmode
)
####
See also
**-**
[
wifi.getmode()
](
#wf_getmode
)
<a
id=
"wf_getmode"
></a>
## wifi.getmode(mode)
Description
:
get wifi working mode.
####
Description
get wifi working mode.
Syntax
:
wifi.getmode()
####
Syntax
wifi.getmode()
Parameters
:
null
####
Parameters
null
Returns
: wifi working mode
####Returns
wifi working mode
####Example
Example
:
****
```
print(wifi.getmode())
```
See also
:
**-**
[
wifi.setmode()
](
#wf_setmode
)
####
See also
**-**
[
wifi.setmode()
](
#wf_setmode
)
<a
id=
"wf_startsmart"
></a>
## wifi.startsmart()
Description
: starts to auto configuration,if success set up ssid and pwd automatically .
####Description
starts to auto configuration,if success set up ssid and pwd automatically .
####Syntax
wifi.startsmart(channel, function succeed_callback())
Syntax
: wifi.startsmart(channel, function succeed_callback())
####Parameters
Parameters
: channel: 1~13,startup channel for searching, if null, default to 6. 20 seconds for each channel.
succeed_callback: callback function for success configuration, which is called after getting the password and the connection to AP.
channel: 1~13,startup channel for searching, if null, default to 6. 20 seconds for each channel.
<br
/>
succeed_callback: callback function for success configuration, which is called after getting the password and the connection to AP.
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.startsmart(6, cb())
```
See also
:
**-**
[
wifi.stopsmart()
](
#wf_stopsmart
)
####
See also
**-**
[
wifi.stopsmart()
](
#wf_stopsmart
)
<a
id=
"wf_stopsmart"
></a>
## wifi.stopsmart()
Description
: stop the configuring process.
####Description
stop the configuring process.
####Syntax
wifi.stopsmart()
Syntax
: wifi.stopsmart()
####Parameters
null
Parameter
s
:
null
####Return
s
null
Returns
: null
####Example
Example
:
****
```
wifi.stopsmart()
```
See also
:
**-**
[
wifi.startsmart()
](
#wf_startsmart
)
####
See also
**-**
[
wifi.startsmart()
](
#wf_startsmart
)
#wifi.sta module
<a
id=
"ws_config"
></a>
## wifi.sta.config()
Description
:
set ssid and password in station mode.
####
Description
set ssid and password in station mode.
Syntax
:
wifi.sta.config(ssid, password)
####
Syntax
wifi.sta.config(ssid, password)
Parameters
: ssid: string which is less than 32 bytes.
password: string which is less than 64 bytes.
####Parameters
ssid: string which is less than 32 bytes.
<br
/>
password: string which is less than 64 bytes.
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.sta.config("myssid","mypassword")
```
See also
:
**-**
[
wifi.sta.connect()
](
#ws_connect
)
:
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
####See also
**-**
[
wifi.sta.connect()
](
#ws_connect
)
<br
/>
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
<a
id=
"ws_connect"
></a>
## wifi.sta.connect()
Description
:
connect to AP in station mode.
####
Description
connect to AP in station mode.
Syntax
:
wifi.sta.connect()
####
Syntax
wifi.sta.connect()
Parameters
:
null
####
Parameters
null
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.sta.connect()
```
See also
:
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
:
**-**
[
wifi.sta.config()
](
#ws_config
)
####See also
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
<br
/>
**-**
[
wifi.sta.config()
](
#ws_config
)
<a
id=
"ws_disconnect"
></a>
## wifi.sta.disconnect()
Description
:
disconnect from AP in station mode.
####
Description
disconnect from AP in station mode.
Syntax
:
wifi.sta.disconnect()
####
Syntax
wifi.sta.disconnect()
Parameters
:
null
####
Parameters
null
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.sta.disconnect()
```
See also
:
**-**
[
wifi.sta..config()
](
#ws_config
)
:
**-**
[
wifi.sta.connect()
](
#ws_connect
)
####See also
**-**
[
wifi.sta..config()
](
#ws_config
)
<br
/>
**-**
[
wifi.sta.connect()
](
#ws_connect
)
<a
id=
"ws_autoconnect"
></a>
## wifi.sta.autoconnect()
Description
:
auto connect to AP in station mode.
####
Description
auto connect to AP in station mode.
Syntax
:
wifi.sta.autoconnect(auto)
####
Syntax
wifi.sta.autoconnect(auto)
Parameters
:
auto: 0 for disable auto connecting. 1 for enable auto connecting
####
Parameters
auto: 0 for disable auto connecting. 1 for enable auto connecting
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.sta.autoconnect()
```
See also
:
**-**
[
wifi.sta..config()
](
#ws_config
)
:
**-**
[
wifi.sta.connect()
](
#ws_connect
)
:
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
####See also
**-**
[
wifi.sta..config()
](
#ws_config
)
<br
/>
**-**
[
wifi.sta.connect()
](
#ws_connect
)
<br
/>
**-**
[
wifi.sta.disconnect()
](
#ws_disconnect
)
<a
id=
"ws_getip"
></a>
## wifi.sta.getip()
Description
: get ip address in station mode.
####Description
get ip address in station mode.
####Syntax
wifi.sta.getip()
Syntax
: wifi.sta.getip()
####Parameters
null
Parameters
: null
####Returns
ip address in string, for example:"192.168.0.111"
Returns
: ip address in string, for example:"192.168.0.111"
####Example
Example
:
****
```
//print current ip
print(wifi.sta.getip())
```
See also
:
**-**
[
wifi.sta..getmac()
](
#ws_getmac
)
####
See also
**-**
[
wifi.sta..getmac()
](
#ws_getmac
)
<a
id=
"ws_getmac"
></a>
## wifi.sta.getmac()
Description
:
get mac address in station mode.
####
Description
get mac address in station mode.
Syntax
:
wifi.sta.getmac()
####
Syntax
wifi.sta.getmac()
Parameters
:
null
####
Parameters
null
Returns
: mac address in string, for example:"18-33-44-FE-55-BB"
####Returns
mac address in string, for example:"18-33-44-FE-55-BB"
####Example
Example
:
****
```
//print current mac address
print(wifi.sta.getmac())
```
See also
:
**-**
[
wifi.sta..getip()
](
#ws_getip
)
####
See also
**-**
[
wifi.sta..getip()
](
#ws_getip
)
#wifi.ap module
<a
id=
"wa_config"
></a>
## wifi.ap.config()
Description
: set ssid and password in ap mode.
####Description
set ssid and password in ap mode.
####Syntax
wifi.ap.config(cfg)
####Parameters
cfg: lua table for setup ap.
Syntax
: wifi.ap.config(cfg)
####Example:
Parameters
: cfg: lua table for setup ap.
: Example:
```
cfg={}
cfg.ssid="myssid"
...
...
@@ -679,161 +683,162 @@ Parameters
wifi.ap.setconfig(cfg)
```
Returns
: null
####Returns
null
####Example
Example
:
****
```
wifi.ap.config(ssid, 'password')
```
See also
:
<>
####
See also
**-**
[]
<>
<a
id=
"wa_getip"
></a>
## wifi.ap.getip()
Description
: get ip in ap mode.
####Description
get ip in ap mode.
####Syntax
wifi.ap.getip()
Syntax
: wifi.ap.getip()
####Parameters
null
Parameter
s
: null
####Return
s
ip address in string, for example:"192.168.0.111"
Returns
: ip address in string, for example:"192.168.0.111"
####Example
Example
:
****
```
wifi.ap.getip()
```
See also
:
**-**
[
wifi.ap..getmac()
](
#wa_getmac
)
####
See also
**-**
[
wifi.ap..getmac()
](
#wa_getmac
)
<a
id=
"wa_getmac"
></a>
## wifi.ap.getmac()
Description
:
get mac address in ap mode.
####
Description
get mac address in ap mode.
Syntax
:
wifi.ap.getmac()
####
Syntax
wifi.ap.getmac()
Parameters
:
null
####
Parameters
null
Returns
: mac address in string, for example:"1A-33-44-FE-55-BB"
####Returns
mac address in string, for example:"1A-33-44-FE-55-BB"
####Example
Example
:
****
```
wifi.ap.getmac()
```
See also
:
**-**
[
wifi.ap.getip()
](
#wa_getip
)
####
See also
**-**
[
wifi.ap.getip()
](
#wa_getip
)
#timer module
<a
id=
"tm_delay"
></a>
## tmr.delay()
Description
: delay us micro seconds.
####Description
delay us micro seconds.
####Syntax
tmr.dealy(us)
Syntax
: tmr.dealy(us)
####Parameters
us: delay time in micro second
Parameter
s
: us: delay time in micro second
####Return
s
null
Returns
: null
####Example
Example
:
****
```
//delay 100us
tmr.delay(100)
```
See also
:
**-**
[
tmr.now()
](
#tm_now
)
####
See also
**-**
[
tmr.now()
](
#tm_now
)
<a
id=
"tm_now"
></a>
## tmr.now()
Description
:
return the current value of system counter: uint32, loopback, us.
####
Description
return the current value of system counter: uint32, loopback, us.
Syntax
:
tmr.now()
####
Syntax
tmr.now()
Parameters
:
null
####
Parameters
null
Returns
: uint32: value of counter
####Returns
uint32: value of counter
####Example
Example
:
****
```
//print current value of counter
print(tmr.now())
```
See also
:
**-**
[
tmr.delay()
](
#tm_delay
)
####
See also
**-**
[
tmr.delay()
](
#tm_delay
)
<a
id=
"tm_alarm"
></a>
## tmr.alarm()
Description
: alarm time.
####Description
alarm time.
####Syntax
tmr.alarm(interval, repeat, function do())
Syntax
: tmr.alarm(interval, repeat, function do())
####Parameters
Interval: alarm time, unit: millisecond
<br
/>
repeat: 0 for one time alarm, 1 for repeat
<br
/>
function do(): callback function for alarm timed out
Parameters
: Interval: alarm time, unit: millisecond;
repeat: 0 for one time alarm, 1 for repeat;
function do(): callback function for alarm timed out.
####Returns
null
Returns
: null
####Example
Example
:
****
```
//print "hello world" every 1000ms
tmr.alarm(1000, 1, function() print(“hello world”) end )
```
See also
:
**-**
[
tmr.now()
](
#tm_now
)
####
See also
**-**
[
tmr.now()
](
#tm_now
)
<a
id=
"tm_stop"
></a>
## tmr.stop()
Description
: stop alarm.
: Note: only one alarm is allowed, the previous one would be replaced if tmr.alarm() again before tmr.stop().
####Description
Syntax
:
tmr.stop()
stop alarm.
<br
/>
**-Note:**
only one alarm is allowed, the previous one would be replaced if tmr.alarm() again before
tmr.stop()
.
Parameters
: null.
####Syntax
tmr.stop()
Returns
: null
####Parameters
null.
####Returns
null
####Example
Example
:
****
```
//print "hello world" every 1000ms
tmr.alarm(1000, 1, function() print(“hello world”) end )
...
...
@@ -844,84 +849,84 @@ Example
tmr.stop()
```
See also
:
**-**
[
tmr.now()
](
#tm_now
)
####
See also
**-**
[
tmr.now()
](
#tm_now
)
#GPIO module
##CONSTANT
:
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
<a
id=
"io_mode"
></a>
## gpio.mode()
Description
:
initialize pin to GPIO mode, set the pin in/out mode.
####
Description
initialize pin to GPIO mode, set the pin in/out mode.
Syntax
:
gpio.mode(pin, mode)
####
Syntax
gpio.mode(pin, mode)
Parameters
:
pin: 0~11,IO index
mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)
####
Parameters
pin: 0~11,IO index
<br
/>
mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)
Returns
: null
####Returns
null
####Example
Example
:
****
```
//set gpio 0 as output.
gpio.mode(0, gpio.OUTPUT)
```
See also
:
**-**
[
gpio.read()
](
#io_read
)
####
See also
**-**
[
gpio.read()
](
#io_read
)
<a
id=
"io_read"
></a>
## gpio.read()
Description
: read pin value.
####Description
read pin value.
####Syntax
gpio.read(pin)
Syntax
: gpio.read(pin)
####Parameters
pin: 0~11,IO index
Parameter
s
: pin: 0~11,IO index
####Return
s
number:0 for low, 1 for high
Returns
: number:0 for low, 1 for high
####Example
Example
:
****
```
//read value of gpio 0.
gpio.read(0)
```
See also
:
**-**
[
gpio.mode()
](
#io_mode
)
####
See also
**-**
[
gpio.mode()
](
#io_mode
)
<a
id=
"io_write"
></a>
## gpio.write()
Description
:
set pin value.
####
Description
set pin value.
Syntax
:
gpio.write(pin)
####
Syntax
gpio.write(pin)
Parameters
:
pin: 0~11,IO index
:
level: gpio.HIGH or gpio.LOW
####
Parameters
pin: 0~11,IO index
<br
/>
level: gpio.HIGH or gpio.LOW
Returns
: null
####Returns
null
####Example
Example
:
****
```
//set pin index 1 to GPIO mode, and set the pin to high.
pin=1
...
...
@@ -929,31 +934,29 @@ Example
gpio.write(pin, gpio.HIGH)
```
See also
:
**-**
[
gpio.mode()
](
#io_mode
)
:
**-**
[
gpio.read()
](
#io_read
)
####See also
**-**
[
gpio.mode()
](
#io_mode
)
<br
/>
**-**
[
gpio.read()
](
#io_read
)
<a
id=
"io_trig"
></a>
## gpio.trig()
Description
:
set the interrupt callback function for pin.
####
Description
set the interrupt callback function for pin.
Syntax
:
gpio.trig(pin, type, function(level))
####
Syntax
gpio.trig(pin, type, function(level))
Parameters
: pin: 0~11,IO index
type: ”up”, “down”, “both”, “low”, “high”, which represent rising edge, falling edge, both edge, low level, high level trig mode separately.
function(level): callback function when triggered. The gpio level is the param.
Use previous callback function if undefined here.
####Parameters
pin: 0~11,IO index
<br
/>
type: ”up”, “down”, “both”, “low”, “high”, which represent rising edge, falling edge, both edge, low level, high level trig mode separately.
<br
/>
function(level): callback function when triggered. The gpio level is the param. Use previous callback function if undefined here.
Returns
: null
####Returns
null
####Example
Example
:
****
```
//use pin 0 as the input pulse width counter
pulse0 = 0
...
...
@@ -969,203 +972,203 @@ Example
```
See also
:
**-**
[
gpio.mode()
](
#io_mode
)
:
**-**
[
gpio.write()
](
#io_write
)
####See also
**-**
[
gpio.mode()
](
#io_mode
)
<br
/>
**-**
[
gpio.write()
](
#io_write
)
#PWM module
<a
id=
"pw_setup"
></a>
## pwm.setup()
Description
:
set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.
####
Description
set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.
Syntax
:
pwm.setup(pin, clock, duty)
####
Syntax
pwm.setup(pin, clock, duty)
Parameters
:
pin: 0~11,IO index
clock: 1~500,pwm frequency
duty: 0~100,pwm duty cycle in percentage
####
Parameters
pin: 0~11,IO index
<br
/>
clock: 1~500,pwm frequency
<br
/>
duty: 0~100,pwm duty cycle in percentage
Returns
: null
####Returns
null
####Example
Example
:
****
```
//set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50..
pwm.setup(0, 100, 50)
```
See also
:
**-**
[
pwm.start()
](
#pw_start
)
####
See also
**-**
[
pwm.start()
](
#pw_start
)
<a
id=
"pw_close"
></a>
## pwm.close()
Description
: quit PWM mode for specified pin.
####Description
quit PWM mode for specified pin.
####Syntax
pwm.close(pin)
Syntax
: pwm.close(pin)
####Parameters
pin: 0~11,IO index
Parameter
s
: pin: 0~11,IO index
####Return
s
null
Returns
: null
####Example
Example
:
****
```
pwm.close(0)
```
See also
:
**-**
[
pwm.start()
](
#pw_start
)
####
See also
**-**
[
pwm.start()
](
#pw_start
)
<a
id=
"pw_start"
></a>
## pwm.start()
Description
:
pwm starts, you can detect the waveform on the gpio.
####
Description
pwm starts, you can detect the waveform on the gpio.
Syntax
:
pwm.start(pin)
####
Syntax
pwm.start(pin)
Parameters
:
pin: 0~11,IO index
####
Parameters
pin: 0~11,IO index
Returns
: null
####Returns
null
####Example
Example
:
****
```
pwm.start(0)
```
See also
:
**-**
[
pwm.stop()
](
#pw_stop
)
####
See also
**-**
[
pwm.stop()
](
#pw_stop
)
<a
id=
"pw_stop"
></a>
## pwm.stop()
Description
: pause the output of PWM waveform.
####Description
pause the output of PWM waveform.
####Syntax
pwm.stop(pin)
Syntax
: pwm.stop(pin)
####Parameters
pin: 0~11,IO index
Parameter
s
: pin: 0~11,IO index
####Return
s
null
Returns
: null
####Example
Example
:
****
```
pwm.stop(0)
```
See also
:
**-**
[
pwm.start()
](
#pw_start
)
####
See also
**-**
[
pwm.start()
](
#pw_start
)
<a
id=
"pw_setclock"
></a>
## pwm.setclock()
Description
: set pwm frequency for pin.
: Note: setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.
####Description
Syntax
: pwm.setclock(pin, clock)
set pwm frequency for pin.
<br
/>
**-Note:**
setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.
Parameters
: pin: 0~11,IO index.
clock: 1~500, pwm frequency.
####Syntax
pwm.setclock(pin, clock)
Returns
: null
####Parameters
pin: 0~11,IO index.
<br
/>
clock: 1~500, pwm frequency.
####Returns
null
####Example
Example
:
****
```
pwm.setclock(0, 100)
```
See also
:
**-**
[
pwm.getclock()
](
#pw_getclock
)
####
See also
**-**
[
pwm.getclock()
](
#pw_getclock
)
<a
id=
"pw_getclock"
></a>
## pwm.getclock()
Description
:
get pwm frequency of pin.
####
Description
get pwm frequency of pin.
Syntax
:
pwm.getclock(pin)
####
Syntax
pwm.getclock(pin)
Parameters
:
pin: 0~11,IO index.
####
Parameters
pin: 0~11,IO index.
Returns
: number:pwm frequency of pin
####Returns
number:pwm frequency of pin
####Example
Example
:
****
```
print(pwm.getclock(0))
```
See also
:
**-**
[
pwm.setclock()
](
#pw_setclock
)
####
See also
**-**
[
pwm.setclock()
](
#pw_setclock
)
<a
id=
"pw_setduty"
></a>
## pwm.setduty()
Description
: set duty clycle for pin.
####Description
set duty clycle for pin.
####Syntax
pwm.setduty(pin, duty)
Syntax
: pwm.setduty(pin, duty)
####Parameters
pin: 0~11,IO index
<br
/>
duty: 0~100,pwm duty cycle in percentage
Parameters
: pin: 0~11,IO index
: duty: 0~100,pwm duty cycle in percentage
####Returns
null
Returns
: null
####Example
Example
:
****
```
pwm.setduty(0, 50)
```
See also
:
**-**
[
pwm.getduty()
](
#pw_getduty
)
####
See also
**-**
[
pwm.getduty()
](
#pw_getduty
)
<a
id=
"pw_getduty"
></a>
## pwm.getduty()
Description
:
get duty clycle for pin.
####
Description
get duty clycle for pin.
Syntax
:
pwm.getduty(pin)
####
Syntax
pwm.getduty(pin)
Parameters
:
pin: 0~11,IO index
####
Parameters
pin: 0~11,IO index
Returns
: null
####Returns
null
####Example
Example
:
****
```
//D0 is connected to green led
//D1 is connected to blue led
...
...
@@ -1186,83 +1189,83 @@ Example
```
See also
:
**-**
[
pwm.setduty()
](
#pw_setduty
)
####
See also
**-**
[
pwm.setduty()
](
#pw_setduty
)
#net module
##CONSTANT
:
net.TCP, net.UDP
net.TCP, net.UDP
<a
id=
"nt_createServer"
></a>
## net.createServer()
Description
: create a server.
####Description
create a server.
####Syntax
net.createServer(type, secure)
Syntax
: net.createServer(type, secure)
####Parameters
type: net.TCP or net.UDP
<br
/>
secure: true or false, true for safe link, false for ordinary link
Parameters
: type: net.TCP or net.UDP
secure: true or false, true for safe link, false for ordinary link
####Returns
net.server sub module
Returns
: net.server sub module
####Example
Example
:
****
```
net.createServer(net.TCP, true)
```
See also
:
**-**
[
net.createConnection()
](
#nt_createConnection
)
####
See also
**-**
[
net.createConnection()
](
#nt_createConnection
)
<a
id=
"nt_createConnection"
></a>
## net.createConnection()
Description
:
create a client.
####
Description
create a client.
Syntax
:
net.createConnection(type, secure)
####
Syntax
net.createConnection(type, secure)
Parameters
:
type: net.TCP or net.UDP
secure: true or false, true for safe link, false for ordinary link
####
Parameters
type: net.TCP or net.UDP
<br
/>
secure: true or false, true for safe link, false for ordinary link
Returns
: net.server sub module
####Returns
net.server sub module
####Example
Example
:
****
```
net.createConnection(net.UDP, false)
```
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
#net.server module
<a
id=
"ns_listen"
></a>
## listen()
Description
: listen on port from [ip] address.
####Description
listen on port from [ip] address.
####Syntax
net.server.listen(port,[ip],function(net.socket))
Syntax
: net.server.listen(port,[ip],function(net.socket))
####Parameters
port: port number
<br
/>
ip:ip address string, can be omitted
<br
/>
function(net.socket): callback function, pass to Caller function as param if a connection is created successfully
Parameters
: port: port number
ip:ip address string, can be omitted
function(net.socket): callback function, pass to Caller function as param if a connection is created successfully
####Returns
null
Returns
: null
####Example
Example
:
****
```
//create a server
sv=net.createServer(net.TCP, false)
...
...
@@ -1273,26 +1276,26 @@ Example
end)
```
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
<a
id=
"ns_close"
></a>
## close()
Description
:
close server.
####
Description
close server.
Syntax
:
net.server.close()
####
Syntax
net.server.close()
Parameters
:
null
####
Parameters
null
Returns
: null
####Returns
null
####Example
Example
:
****
```
//create a server
sv=net.createServer(net.TCP, false)
...
...
@@ -1300,67 +1303,67 @@ Example
sv:close()
```
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
#net.socket module
<a
id=
"nk_connect"
></a>
## connect()
Description
:
connect to remote.
####
Description
connect to remote.
Syntax
:
connect(port, ip)
####
Syntax
connect(port, ip)
Parameters
:
port: port number
ip: ip address in string
####
Parameters
port: port number
<br
/>
ip: ip address in string
Returns
:
null
####
Returns
null
See also
:
**-**
[
net.socket:on()
](
#nk_on
)
####
See also
**-**
[
net.socket:on()
](
#nk_on
)
<a
id=
"nk_send"
></a>
## send()
Description
:
send data to remote via connection.
####
Description
send data to remote via connection.
Syntax
:
send(string, function(sent))
####
Syntax
send(string, function(sent))
Parameters
:
string: data in string which will be sent to remote
function(sent): callback function for sending string
####
Parameters
string: data in string which will be sent to remote
<br
/>
function(sent): callback function for sending string
Returns
:
null
####
Returns
null
See also
:
**-**
[
net.socket:on()
](
#nk_on
)
####
See also
**-**
[
net.socket:on()
](
#nk_on
)
<a
id=
"nk_on"
></a>
## on()
Description
: register callback function for event.
####Description
register callback function for event.
####Syntax
on(event, function cb())
Syntax
: on(event, function cb())
####Parameters
event: string, which can be: "connection","reconnection","disconnection","receive","sent"
<br
/>
function cb(net.socket, [string]): callback function. The first param is the socket.
<br
/>
If event is”receive”, the second param is received data in string.
Parameters
: event: string, which can be: "connection","reconnection","disconnection","receive","sent"
function cb(net.socket, [string]): callback function. The first param is the socket.
If event is”receive”, the second param is received data in string.
####Returns
null
Returns
: null
####Example
Example
:
****
```
sk=net.createConnection(net.TCP, false)
sk:on("receive", function(sck, c) print(c) end )
...
...
@@ -1368,169 +1371,169 @@ Example
sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
```
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
<a
id=
"nk_close"
></a>
## close()
Description
:
close socket.
####
Description
close socket.
Syntax
:
close()
####
Syntax
close()
Parameters
:
null
####
Parameters
null
Returns
:
null
####
Returns
null
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
<a
id=
"nk_dns"
></a>
## dns()
Description
:
get domain ip
####
Description
get domain ip
Syntax
:
dns(domain, function(net.socket, ip))
####
Syntax
dns(domain, function(net.socket, ip))
Parameters
:
domain: domain name.
function (net.socket, ip): callback function. The first param is the socket, the second param is the ip address in string.
####
Parameters
domain: domain name.
<br
/>
function (net.socket, ip): callback function. The first param is the socket, the second param is the ip address in string.
Returns
:
null
####
Returns
null
See also
:
**-**
[
net.createServer()
](
#nt_createServer
)
####
See also
**-**
[
net.createServer()
](
#nt_createServer
)
#i2c module
##CONSTANT
:
i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.
i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.
<a
id=
"ic_setup"
></a>
## i2c.setup()
Description
:
initialize i2c.
####
Description
initialize i2c.
Syntax
:
i2c.setup(id, pinSDA, pinSCL, speed)
####
Syntax
i2c.setup(id, pinSDA, pinSCL, speed)
Parameters
:
id = 0
pinSDA: 0~11,IO index
pinSCL: 0~11,IO index
speed: i2c.SLOW
####
Parameters
id = 0
<br
/>
pinSDA: 0~11,IO index
<br
/>
pinSCL: 0~11,IO index
<br
/>
speed: i2c.SLOW
Returns
:
null
####
Returns
null
See also
:
**-**
[
i2c.read()
](
#ic_read
)
####
See also
**-**
[
i2c.read()
](
#ic_read
)
<a
id=
"ic_start"
></a>
## i2c.start()
Description
:
start i2c transporting.
####
Description
start i2c transporting.
Syntax
:
i2c.start(id)
####
Syntax
i2c.start(id)
Parameters
:
id = 0
####
Parameters
id = 0
Returns
:
null
####
Returns
null
See also
:
**-**
[
i2c.read()
](
#ic_read
)
####
See also
**-**
[
i2c.read()
](
#ic_read
)
<a
id=
"ic_stop"
></a>
## i2c.stop()
Description
:
stop i2c transporting.
####
Description
stop i2c transporting.
Syntax
:
i2c.stop(id)
####
Syntax
i2c.stop(id)
Parameters
:
id = 0
####
Parameters
id = 0
Returns
:
null
####
Returns
null
See also
:
**-**
[
i2c.read()
](
#ic_read
)
####
See also
**-**
[
i2c.read()
](
#ic_read
)
<a
id=
"ic_address"
></a>
## i2c.address()
Description
:
setup i2c address and read/write mode.
####
Description
setup i2c address and read/write mode.
Syntax
:
i2c.address(id, device_addr, direction)
####
Syntax
i2c.address(id, device_addr, direction)
Parameters
: id=0
device_addr: device address.
direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode
####
Parameters
id=0
<br
/>
device_addr: device address.
<br
/>
direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode
Returns
:
null
####
Returns
null
See also
:
**-**
[
i2c.read()
](
#ic_read
)
####
See also
**-**
[
i2c.read()
](
#ic_read
)
<a
id=
"ic_write"
></a>
## i2c.write()
Description
:
write data to i2c, data can be multi numbers, string or lua table.
####
Description
write data to i2c, data can be multi numbers, string or lua table.
Syntax
:
i2c.write(id, data1, data2,...)
####
Syntax
i2c.write(id, data1, data2,...)
Parameters
: id=0
data: data can be numbers, string or lua table.
####
Parameters
id=0
<br
/>
data: data can be numbers, string or lua table.
Returns
: null
####Returns
null
####Example
Example
:
****
```
i2c.write(0, "hello", "world")
```
See also
:
**-**
[
i2c.read()
](
#ic_read
)
####
See also
**-**
[
i2c.read()
](
#ic_read
)
<a
id=
"ic_read"
></a>
</a>
<a
id=
"ic_read"
></a>
## i2c.read()
Description
: read data for len bytes.
####Description
read data for len bytes.
####Syntax
i2c.read(id, len)
Syntax
: i2c.read(id, len)
####Parameters
id=0
<br
/>
len: data length
Parameters
: id=0
len: data length
####Returns
string:data received.
Returns
: string:data received.
####Example
Example
:
****
```
id=0
sda=1
...
...
@@ -1558,6 +1561,6 @@ Example
```
See also
:
**-**
[
i2c.write()
](
#ic_write
)
####
See also
**-**
[
i2c.write()
](
#ic_write
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment