Commit 07027385 authored by funshine's avatar funshine
Browse files

update readme

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