Commit 35ad738f authored by Hong's avatar Hong
Browse files

add readme

parent 994c550b
...@@ -12,7 +12,7 @@ version 0.1 2014-10-11 ...@@ -12,7 +12,7 @@ version 0.1 2014-10-11
nodeMcu对模块的引脚进行编号,gpio,i2c,pwm等模块需要使用引脚编号进行索引。 nodeMcu对模块的引脚进行编号,gpio,i2c,pwm等模块需要使用引脚编号进行索引。
目前的编号对应表格: ###目前的编号对应表格:
IO索引编号 ESP8266实际IO IO索引编号 ESP8266实际IO IO索引编号 ESP8266实际IO IO索引编号 ESP8266实际IO
0 GPIO12 8 GPIO0 0 GPIO12 8 GPIO0
...@@ -24,7 +24,8 @@ version 0.1 2014-10-11 ...@@ -24,7 +24,8 @@ version 0.1 2014-10-11
6 GPIO9 6 GPIO9
7 GPIO10 7 GPIO10
串口波特率74880 ###串口波特率
74880
###固件烧写地址: ###固件烧写地址:
...@@ -37,30 +38,30 @@ version 0.1 2014-10-11 ...@@ -37,30 +38,30 @@ version 0.1 2014-10-11
node module node module
------ ------
node.restart() node.restart()
描述:重新启动 描述:重新启动
node.dsleep( us ) node.dsleep( us )
描述:深度睡眠 us 微秒,时间到之后将重新启动 描述:深度睡眠 us 微秒,时间到之后将重新启动
us:时间,单位微秒 us:时间,单位微秒
node.chipid() node.chipid()
描述:返回芯片id 描述:返回芯片id
返回:number 返回:number
node.heap() node.heap()
描述:返回可用内存 in bytes 描述:返回可用内存 in bytes
返回:系统heap剩余 返回:系统heap剩余
node.format() node.format()
描述:格式化用户flash区 描述:格式化用户flash区
node.startlog( filename, noparse) node.startlog( filename, noparse)
描述:开始记录输入 描述:开始记录输入
filename:log所保存的文件名,不支持目录 filename:log所保存的文件名,不支持目录
noparse:1表示lua虚拟机不对输入进行解析,0表示lua虚拟机对输入进行解析 noparse:1表示lua虚拟机不对输入进行解析,0表示lua虚拟机对输入进行解析
node.stoplog() node.stoplog()
描述:结束log 描述:结束log
例子:录制log到init.lua文件,可以在系统启动之后自动调用该文件。 例子:录制log到init.lua文件,可以在系统启动之后自动调用该文件。
node.format() node.format()
...@@ -71,13 +72,13 @@ node.stoplog() ...@@ -71,13 +72,13 @@ node.stoplog()
此时,文件init.lua内部将含有内容,重启之后,系统执行print(“hello world”) 此时,文件init.lua内部将含有内容,重启之后,系统执行print(“hello world”)
node.readlog( filename) node.readlog( filename)
描述:读取文件 描述:读取文件
filename:log文件名,不支持目录 filename:log文件名,不支持目录
返回:读取的内容,字符串形式 返回:读取的内容,字符串形式
node.list() node.list()
描述:返回所有文件 描述:返回所有文件
返回:一个包含 <文件名文件大小> pair 的map 返回:一个包含 <文件名文件大小> pair 的map
wifi module wifi module
----------- -----------
...@@ -85,52 +86,52 @@ wifi module ...@@ -85,52 +86,52 @@ wifi module
常量:wifi. STATION, wifi.SOFTAP, wifi.STATIONAP 常量:wifi. STATION, wifi.SOFTAP, wifi.STATIONAP
wifi.setmode(mode) wifi.setmode(mode)
描述:设置wifi的工作模式 描述:设置wifi的工作模式
mode:取值:wifi. STATION, wifi.SOFTAP或wifi.STATIONAP mode:取值:wifi. STATION, wifi.SOFTAP或wifi.STATIONAP
返回设置之后的当前mode 返回设置之后的当前mode
wifi.getmode() wifi.getmode()
描述:获取wifi的工作模式 描述:获取wifi的工作模式
返回:wifi. STATION, wifi.SOFTAP或wifi.STATIONAP 返回:wifi. STATION, wifi.SOFTAP或wifi.STATIONAP
wifi.startconfig( channel, function succeed_callback ) wifi.startconfig( channel, function succeed_callback )
描述:开始智能配置,若成功自动设置ssid和pwd并退出 描述:开始智能配置,若成功自动设置ssid和pwd并退出
channel:1~13,起始搜索信道。若不指定,默认为6,每个信道搜索20秒 channel:1~13,起始搜索信道。若不指定,默认为6,每个信道搜索20秒
succeed_callback:配置成功后的回调函数,将在获取密码正确并连接上ap之后调用 succeed_callback:配置成功后的回调函数,将在获取密码正确并连接上ap之后调用
wifi.stopconfig() wifi.stopconfig()
描述:中断智能配置 描述:中断智能配置
wifi.station module wifi.station module
----------------- -----------------
wifi.station.setconfig(ssid, password) wifi.station.setconfig(ssid, password)
描述:设置station模式下的ssid和password 描述:设置station模式下的ssid和password
ssid:字符串形式,长度小于32 ssid:字符串形式,长度小于32
password:字符串形式,长度小于64 password:字符串形式,长度小于64
wifi.station.connect() wifi.station.connect()
描述:station模式下连接至ap 描述:station模式下连接至ap
wifi.station.disconnect() wifi.station.disconnect()
描述:station模式下断开与ap的连接 描述:station模式下断开与ap的连接
wifi.station.autoconnect(auto) wifi.station.autoconnect(auto)
描述:station模式下设置自动连接至ap 描述:station模式下设置自动连接至ap
auto:0表示设置为不自动连,1表示设置为自动连接 auto:0表示设置为不自动连,1表示设置为自动连接
wifi.station.getip() wifi.station.getip()
描述:station模式下获取ip 描述:station模式下获取ip
返回:字符串形式的ip,如“192.168.0.2” 返回:字符串形式的ip,如“192.168.0.2”
wifi.station.getmac() wifi.station.getmac()
描述:station模式下获取mac 描述:station模式下获取mac
返回:字符串形式的mac,如“18-33-44-FE-55-BB” 返回:字符串形式的mac,如“18-33-44-FE-55-BB”
wifi.ap module wifi.ap module
--------------- ---------------
wifi.ap.setconfig(cfg) wifi.ap.setconfig(cfg)
描述:设置station模式下的ssid和password 描述:设置station模式下的ssid和password
cfg:设置需要的map cfg:设置需要的map
例子: 例子:
cfg={} cfg={}
...@@ -139,33 +140,31 @@ cfg:设置需要的map ...@@ -139,33 +140,31 @@ cfg:设置需要的map
wifi.ap.setconfig(cfg) wifi.ap.setconfig(cfg)
wifi.ap.getip() wifi.ap.getip()
描述:ap模式下获取ip 描述:ap模式下获取ip
返回:字符串形式的ip,如“192.168.0.2” 返回:字符串形式的ip,如“192.168.0.2”
wifi. ap.getmac() wifi. ap.getmac()
描述:ap模式下获取mac 描述:ap模式下获取mac
返回:字符串形式的mac,如“1A-33-44-FE-55-BB” 返回:字符串形式的mac,如“1A-33-44-FE-55-BB”
gpio module gpio module
----------- -----------
模块名:gpio
常量:gpio.OUTPUT, gpio.INPUT, gpio.HIGH, gpio.LOW 常量:gpio.OUTPUT, gpio.INPUT, gpio.HIGH, gpio.LOW
gpio.mode( pin, mode) gpio.mode( pin, mode)
描述:设置对应pin的输入输出模式,将该pin初始化为gpio模式。 描述:设置对应pin的输入输出模式,将该pin初始化为gpio模式。
pin:0~11,IO索引编号 pin:0~11,IO索引编号
mode:gpio.OUTPUT或者gpio.INPUT mode:gpio.OUTPUT或者gpio.INPUT
gpio.read(pin) gpio.read(pin)
描述:读取对应pin的值 描述:读取对应pin的值
pin:0~11,IO索引编号 pin:0~11,IO索引编号
返回:0表示低,1表示高 返回:0表示低,1表示高
gpio.write(pin, level) gpio.write(pin, level)
描述:设置对应pin的值 描述:设置对应pin的值
pin:0~11,IO索引编号 pin:0~11,IO索引编号
level:gpio.HIGH或者gpio.LOW level:gpio.HIGH或者gpio.LOW
例子: 例子:
pin=1 pin=1
...@@ -179,36 +178,36 @@ net module ...@@ -179,36 +178,36 @@ net module
常量:net.TCP, net.UDP 常量:net.TCP, net.UDP
net.createServer(type, secure) net.createServer(type, secure)
描述:建立一个服务器 描述:建立一个服务器
type:net.TCP或 net.UDP type:net.TCP或 net.UDP
secure:true 或者 false,表示是否为安全连接 secure:true 或者 false,表示是否为安全连接
返回:net.server子模块 返回:net.server子模块
net.createConnection(type, secure) net.createConnection(type, secure)
描述:建立一个客户端 描述:建立一个客户端
type:net.TCP或 net.UDP type:net.TCP或 net.UDP
secure:true 或者 false,表示是否为安全连接 secure:true 或者 false,表示是否为安全连接
返回:net. socket子模块 返回:net. socket子模块
net.server module net.server module
listen(port,[ip]) listen(port,[ip])
描述:监听某端口 描述:监听某端口
port:端口号 port:端口号
ip:可忽略,ip字符串 ip:可忽略,ip字符串
例子: 例子:
sv=net.createServer(net.TCP, false) sv=net.createServer(net.TCP, false)
sv:listen(80) sv:listen(80)
send( string, function(sent) ) send( string, function(sent) )
描述:向连接的客户端发送数据 描述:向连接的客户端发送数据
string:需要发送的数据字符串 string:需要发送的数据字符串
on(event, function cb()) on(event, function cb())
描述:注册事件的回调函数 描述:注册事件的回调函数
event:字符串,可为:"connection","reconnection","disconnection","receive","sent" event:字符串,可为:"connection","reconnection","disconnection","receive","sent"
function cb(net.server sv, [string]):回调函数。第一个参数为服务器本身。 function cb(net.server sv, [string]):回调函数。第一个参数为服务器本身。
若event为”receive”, 第二个参数为接收到数据,字符串形式。 若event为”receive”, 第二个参数为接收到数据,字符串形式。
例子: 例子:
sv=net.createServer(net.TCP, false) sv=net.createServer(net.TCP, false)
...@@ -216,23 +215,24 @@ function cb(net.server sv, [string]):回调函数。第一个参数为服务 ...@@ -216,23 +215,24 @@ function cb(net.server sv, [string]):回调函数。第一个参数为服务
sv:on("receive", function(s,c) s:send("Hello, world.") print(c) end ) sv:on("receive", function(s,c) s:send("Hello, world.") print(c) end )
close() close()
描述:关闭服务器 描述:关闭服务器
net.socket module net.socket module
-------
connect(port, ip) connect(port, ip)
描述:连接到某ip和端口 描述:连接到某ip和端口
port:端口号 port:端口号
ip:ip字符串 ip:ip字符串
send( string, function(sent) ) send( string, function(sent) )
描述:向连接发送数据 描述:向连接发送数据
string:需要发送的数据字符串 string:需要发送的数据字符串
on(event, function cb()) on(event, function cb())
描述:注册事件的回调函数 描述:注册事件的回调函数
event:字符串,可为:"connection","reconnection","disconnection","receive","sent" event:字符串,可为:"connection","reconnection","disconnection","receive","sent"
function cb(net.socket, [string]):回调函数。第一个参数为socket连接本身。 function cb(net.socket, [string]):回调函数。第一个参数为socket连接本身。
若event为”receive”, 第二个参数为接收到数据,字符串形式。 若event为”receive”, 第二个参数为接收到数据,字符串形式。
例子: 例子:
sk=net.createConnection(net.TCP, false) sk=net.createConnection(net.TCP, false)
...@@ -241,5 +241,5 @@ function cb(net.socket, [string]):回调函数。第一个参数为socket连 ...@@ -241,5 +241,5 @@ function cb(net.socket, [string]):回调函数。第一个参数为socket连
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")
close() close()
描述:关闭socket 描述:关闭socket
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