diff --git a/0.9.2/512k-flash/nodemcu_512k.bin b/0.9.2/512k-flash/nodemcu_512k.bin index 7baff22f..89bf0c28 100644 Binary files a/0.9.2/512k-flash/nodemcu_512k.bin and b/0.9.2/512k-flash/nodemcu_512k.bin differ diff --git a/README.html b/README.html index 957a28ec..a5f358eb 100644 --- a/README.html +++ b/README.html @@ -1014,74 +1014,9 @@ body .markdown-body page-break-after: avoid; } } -README

NodeMcu

+README

NodeMcu

A lua based firmware for wifi-soc esp8266

-

version 0.9.2 build 2014-11-18

+

version 0.9.2 build 2014-11-19

Change log

change log

变更日志

@@ -1131,106 +1066,98 @@ for most esp8266 modules, just pull GPIO0 down and restart.

braudrate:9600

Start play

Connect to your ap

-
    print(wifi.sta.getip())
-    --0.0.0.0
-    wifi.setmode(wifi.STATION)
-    wifi.sta.config("SSID","password")
-    print(wifi.sta.getip())
-    --192.168.18.110
-
- +
    print(wifi.sta.getip())
+    --0.0.0.0
+    wifi.setmode(wifi.STATION)
+    wifi.sta.config("SSID","password")
+    print(wifi.sta.getip())
+    --192.168.18.110
+

Manipulate hardware like a arduino

-
    pin = 1
-    gpio.mode(pin,gpio.OUTPUT)
-    gpio.write(pin,gpio.HIGH)
-    print(gpio.read(pin))
-
- +
    pin = 1
+    gpio.mode(pin,gpio.OUTPUT)
+    gpio.write(pin,gpio.HIGH)
+    print(gpio.read(pin))
+

Write network application in nodejs style

-
    -- A simple http client
-    conn=net.createConnection(net.TCP, false) 
-    conn:on("receive", function(conn, payload) print(c) end )
-    conn:connect(80,"115.239.210.27")
-    conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"
-        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
-
- +
    -- A simple http client
+    conn=net.createConnection(net.TCP, false) 
+    conn:on("receive", function(conn, payload) print(c) end )
+    conn:connect(80,"115.239.210.27")
+    conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"
+        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
+

Or a simple http server

-
    -- A simple http server
-    srv=net.createServer(net.TCP) 
-    srv:listen(80,function(conn) 
-      conn:on("receive",function(conn,payload) 
-        print(payload) 
-        conn:send("<h1> Hello, NodeMcu.</h1>")
-      end) 
-    end)
-
- +
    -- A simple http server
+    srv=net.createServer(net.TCP) 
+    srv:listen(80,function(conn) 
+      conn:on("receive",function(conn,payload) 
+        print(payload) 
+        conn:send("<h1> Hello, NodeMcu.</h1>")
+      end) 
+    end)
+

Do something shining

-
  function led(r,g,b) 
-    pwm.setduty(0,r) 
-    pwm.setduty(1,g) 
-    pwm.setduty(2,b) 
-  end
-  pwm.setup(0,500,50) 
-  pwm.setup(1,500,50) 
-  pwm.setup(2,500,50)
-  pwm.start(0) 
-  pwm.start(1) 
-  pwm.start(2)
-  led(50,0,0) -- red
-  led(0,0,50) -- blue
-
- +
  function led(r,g,b) 
+    pwm.setduty(0,r) 
+    pwm.setduty(1,g) 
+    pwm.setduty(2,b) 
+  end
+  pwm.setup(0,500,50) 
+  pwm.setup(1,500,50) 
+  pwm.setup(2,500,50)
+  pwm.start(0) 
+  pwm.start(1) 
+  pwm.start(2)
+  led(50,0,0) -- red
+  led(0,0,50) -- blue
+
-
  lighton=0
-  tmr.alarm(1000,1,function()
-    if lighton==0 then 
-      lighton=1 
-      led(50,50,50) 
-    else 
-      lighton=0 
-      led(0,0,0) 
-    end 
-  end)
-
- +
  lighton=0
+  tmr.alarm(1000,1,function()
+    if lighton==0 then 
+      lighton=1 
+      led(50,50,50) 
+    else 
+      lighton=0 
+      led(0,0,0) 
+    end 
+  end)
+

If you want to run something when system started

-
  --init.lua will be excuted
-  file.open("init.lua","w")
-  file.writeline([[print("Hello, do this at the beginning.")]])
-  file.close()
-  node.restart()  -- this will restart the module.
-
- +
  --init.lua will be excuted
+  file.open("init.lua","w")
+  file.writeline([[print("Hello, do this at the beginning.")]])
+  file.close()
+  node.restart()  -- this will restart the module.
+

With below code, you can telnet to your esp8266 now

-
    -- 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)
+

Check this out

Tencent QQ group: 309957875

diff --git a/README.md b/README.md index 0281a8d8..66b74d9e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # **NodeMcu** # ###A lua based firmware for wifi-soc esp8266 -version 0.9.2 build 2014-11-18 +version 0.9.2 build 2014-11-19 # Change log [change log](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log)
[变更日志](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log) diff --git a/nodemcu_api_cn.html b/nodemcu_api_cn.html index 8e6f4d0a..dbeeb515 100644 --- a/nodemcu_api_cn.html +++ b/nodemcu_api_cn.html @@ -1014,76 +1014,14 @@ body .markdown-body page-break-after: avoid; } } -nodemcu_api_cn

nodeMcu API说明

+nodemcu_api_cn

nodeMcu API说明

English Version

-

版本 0.9.2 build 2014-11-18

+

版本 0.9.2 build 2014-11-19

变更日志:

+

2014-11-19

+增加adc模块,adc.read(0)读取adc的值。

+wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。

2014-11-18

修正tcp服务器不能使用:close()函数关闭tcp连接的问题。

tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)

@@ -1166,9 +1104,8 @@ node模块中删除了log函数。

返回值

nil

示例

-
    node.restart();
-
- +
    node.restart();
+

参见

-

@@ -1184,9 +1121,8 @@ node模块中删除了log函数。

返回值

nil

示例

-
    node.dsleep(us);
-
- +
    node.dsleep(us);
+

参见

-

@@ -1201,9 +1137,8 @@ node模块中删除了log函数。

返回值

number:芯片ID

示例

-
    id = node.chipid();
-
- +
    id = node.chipid();
+

参见

-

@@ -1218,9 +1153,8 @@ node模块中删除了log函数。

返回值

number: 系统剩余内存字节数

示例

-
    heap_size = node.heap();
-
- +
    heap_size = node.heap();
+

参见

-

@@ -1237,9 +1171,8 @@ function(): 用户自定义的按键回调函数。 如果为nil, 则取消用

返回值

nil

示例

-
    node.key("long", function(){print('hello world')})
-
- +
    node.key("long", function(){print('hello world')})
+

参见

-

@@ -1255,10 +1188,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms

返回值

nil

示例

-
    -- LED常亮.
-    node.led(0);
-
- +
    -- LED常亮.
+    node.led(0);
+

参见

-

@@ -1274,10 +1206,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms

返回值

nil

示例

-
    -- 注意:该函数不支持在命令行中使用。
-    sk:on("receive", function(conn, payload) node.input(payload) end)
-
- +
    -- 注意:该函数不支持在命令行中使用。
+    sk:on("receive", function(conn, payload) node.input(payload) end)
+

参见

-

@@ -1293,14 +1224,13 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口

返回值

nil

示例

-
    function tonet(str)
-      sk:send(str)
-      -- print(str) 错误!!! 千万不要在此函数中再使用print函数
-      -- 因为这样会导致函数的嵌套调用!!
-    end
-    node.ouput(tonet, 1)  -- serial also get the lua output.
-
- +
    function tonet(str)
+      sk:send(str)
+      -- print(str) 错误!!! 千万不要在此函数中再使用print函数
+      -- 因为这样会导致函数的嵌套调用!!
+    end
+    node.ouput(tonet, 1)  -- serial also get the lua output.
+

参见

-

@@ -1316,10 +1246,9 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口

返回值

nil

示例

-
    -- 删除foo.lua文件
-    file.remove("foo.lua")
-
- +
    -- 删除foo.lua文件
+    file.remove("foo.lua")
+

参见

- file.open()

@@ -1342,12 +1271,11 @@ mode:

返回值

nil

示例

-
    -- 打开'init.lua',并打印文件的第一行。
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- 打开'init.lua',并打印文件的第一行。
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

参见

- file.close()

@@ -1363,12 +1291,11 @@ mode:

返回值

nil

示例

-
    -- 打开'init.lua',并打印文件的第一行,然后关闭文件。
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- 打开'init.lua',并打印文件的第一行,然后关闭文件。
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

参见

- file.open()

@@ -1385,12 +1312,11 @@ mode:

逐行返回文件内容。返回值末尾包含EOL(‘\n’)

如果读到EOF返回nil。

示例

-
    -- 打开'init.lua',读取并打印文件的第一行,然后关闭文件。
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- 打开'init.lua',读取并打印文件的第一行,然后关闭文件。
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

参见

- file.open()

@@ -1407,13 +1333,12 @@ mode:

true: 写入成功

nil: 写入失败

示例

-
    -- 以'a+'的模式打开'init.lua'
-    file.open("init.lua", "a+")
-    -- 将'foo bar'写到文件的末尾
-    file.writeline('foo bar')
-    file.close()
-
- +
    -- 以'a+'的模式打开'init.lua'
+    file.open("init.lua", "a+")
+    -- 将'foo bar'写到文件的末尾
+    file.writeline('foo bar')
+    file.close()
+

参见

- file.open()

@@ -1430,13 +1355,12 @@ nil: 写入失败

true: 写入成功

nil: 写入失败

示例

-
    -- 以'a+'的模式打开'init.lua'
-    file.open("init.lua", "a+")
-    -- 将'foo bar'写到文件的末尾
-    file.writeline('foo bar')
-    file.close()
-
- +
    -- 以'a+'的模式打开'init.lua'
+    file.open("init.lua", "a+")
+    -- 将'foo bar'写到文件的末尾
+    file.writeline('foo bar')
+    file.close()
+

参见

- file.open()

@@ -1452,14 +1376,13 @@ nil: 写入失败

返回值

nil

示例

-
    -- 以'a+'的模式打开'init.lua'
-    file.open("init.lua", "a+")
-    -- 将'foo bar'写到文件的末尾
-    file.write('foo bar')
-    file.flush()
-    file.close()
-
- +
    -- 以'a+'的模式打开'init.lua'
+    file.open("init.lua", "a+")
+    -- 将'foo bar'写到文件的末尾
+    file.write('foo bar')
+    file.flush()
+    file.close()
+

参见

- file.open()

@@ -1480,18 +1403,17 @@ offset: default 0

成功: 返回当前的文件读写位置

失败: 返回nil

示例

-
    -- 以'a+'的模式打开'init.lua'
-    file.open("init.lua", "a+")
-    -- 将'foo bar'写到文件的末尾
-    file.write('foo bar')
-    file.flush()
-    --将文件读写位置设置在文件开始
-    file.seek("set")
-    --读取并打印文件的第一行
-    print(file.readline())
-    file.close()
-
- +
    -- 以'a+'的模式打开'init.lua'
+    file.open("init.lua", "a+")
+    -- 将'foo bar'写到文件的末尾
+    file.write('foo bar')
+    file.flush()
+    --将文件读写位置设置在文件开始
+    file.seek("set")
+    --读取并打印文件的第一行
+    print(file.readline())
+    file.close()
+

参见

- file.open()

@@ -1507,12 +1429,11 @@ offset: default 0

返回值

返回包含{文件名:文件大小}的lua table

示例

-
    l = file.list();
-    for k,v in pairs(l) do
-      print("name:"..k..", size:"..v)
-    end
-
- +
    l = file.list();
+    for k,v in pairs(l) do
+      print("name:"..k..", size:"..v)
+    end
+

参见

- file.remove()

@@ -1530,9 +1451,8 @@ offset: default 0

返回值

返回设置之后的mode值

示例

-
    wifi.setmode(wifi.STATION)
-
- +
    wifi.setmode(wifi.STATION)
+

参见

- wifi.getmode()

@@ -1547,9 +1467,8 @@ offset: default 0

返回值

返回wifi的工作模式

示例

-
    print(wifi.getmode())
-
- +
    print(wifi.getmode())
+

参见

- wifi.setmode()

@@ -1565,9 +1484,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调

返回值

nil

示例

-
    wifi.startsmart(6, cb())
-
- +
    wifi.startsmart(6, cb())
+

参见

- wifi.stopsmart()

@@ -1582,9 +1500,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调

返回值

nil

示例

-
    wifi.stopsmart()
-
- +
    wifi.stopsmart()
+

参见

- wifi.startsmart()

@@ -1601,9 +1518,8 @@ password: 字符串,长度小于64字节。

返回值

nil

示例

-
    wifi.sta.config("myssid","mypassword")
-
- +
    wifi.sta.config("myssid","mypassword")
+

参见

- wifi.sta.connect()

@@ -1619,9 +1535,8 @@ password: 字符串,长度小于64字节。

返回值

nil

示例

-
    wifi.sta.connect()
-
- +
    wifi.sta.connect()
+

参见

- wifi.sta.disconnect()

@@ -1637,9 +1552,8 @@ password: 字符串,长度小于64字节。

返回值

nil

示例

-
    wifi.sta.disconnect()
-
- +
    wifi.sta.disconnect()
+

参见

- wifi.sta.config()

@@ -1655,9 +1569,8 @@ password: 字符串,长度小于64字节。

返回值

nil

示例

-
    wifi.sta.autoconnect()
-
- +
    wifi.sta.autoconnect()
+

参见

- wifi.sta.config()

@@ -1674,10 +1587,9 @@ password: 字符串,长度小于64字节。

返回值

ip地址字符串,如:”192.168.0.111”

示例

-
    -- print current ip
-    print(wifi.sta.getip())
-
- +
    -- print current ip
+    print(wifi.sta.getip())
+

参见

- wifi.sta.getmac()

@@ -1692,674 +1604,688 @@ password: 字符串,长度小于64字节。

返回值

mac地址字符串,如:”18-33-44-FE-55-BB”

示例

-
    -- 打印当前的mac地址
-    print(wifi.sta.getmac())
-
- +
    -- 打印当前的mac地址
+    print(wifi.sta.getmac())
+

参见

- wifi.sta.getip()

+

+

wifi.sta.getap()

+

描述

+

扫描并列出ap,结果以一个lua table为参数传递给回调函数。

+

语法

+

wifi.sta.getap(function(table))

+

参数

+

function(table): 当扫描结束时,调用此回调函数

+ 扫描结果是一个lua table,key为ap的ssid,value为其他信息,格式:authmode,rssi,bssid,channel

+

返回值

+

nil

+

示例

+
    -- print ap list
+    function listap(t)
+      for k,v in pairs(t) do
+        print(k.." : "..v)
+      end
+    end
+    wifi.sta.getap(listap)
+
+ +

参见

+

- wifi.sta.getip()

wifi.ap 子模块

wifi.ap.config()

-

描述

+

描述

设置ap模式下的ssid和password

-

语法

+

语法

wifi.ap.config(cfg)

-

参数

+

参数

cfg: 设置AP的lua table

-

示例:

-
     cfg={}
-     cfg.ssid="myssid"
-     cfg.pwd="mypwd"
-     wifi.ap.setconfig(cfg)
-
+

示例:

+
     cfg={}
+     cfg.ssid="myssid"
+     cfg.pwd="mypwd"
+     wifi.ap.setconfig(cfg)
+
- -

返回值

+

返回值

nil

-

示例

-
    wifi.ap.config(ssid, 'password')
-
+

示例

+
    wifi.ap.config(ssid, 'password')
+
- -

参见

+

参见

-

wifi.ap.getip()

-

描述

-

ap模式下获取ip

-

语法

-

wifi.ap.getip()

-

参数

-

nil

-

返回值

-

ip地址字符串,如:”192.168.0.111”

-

示例

-
    wifi.ap.getip()
-
- - -

参见

-

- wifi.ap.getmac()

-

-

wifi.ap.getmac()

描述

-

ap模式下获取mac地址。

+

ap模式下获取ip

语法

-

wifi.ap.getmac()

+

wifi.ap.getip()

参数

nil

返回值

-

mac地址字符串,如:”1A-33-44-FE-55-BB”

+

ip地址字符串,如:”192.168.0.111”

示例

-
    wifi.ap.getmac()
-
- +
    wifi.ap.getip()
+

参见

+

- wifi.ap.getmac()

+

+

wifi.ap.getmac()

+

描述

+

ap模式下获取mac地址。

+

语法

+

wifi.ap.getmac()

+

参数

+

nil

+

返回值

+

mac地址字符串,如:”1A-33-44-FE-55-BB”

+

示例

+
    wifi.ap.getmac()
+
+ +

参见

- wifi.ap.getip()

timer 模块

tmr.delay()

-

描述

+

描述

延迟us微秒。

-

语法

+

语法

tmr.dealy(us)

-

参数

+

参数

us: 延迟时间,单位:微秒

-

返回值

+

返回值

nil

-

示例

-
    -- delay 100us
-    tmr.delay(100)
-
+

示例

+
    -- delay 100us
+    tmr.delay(100)
+
- -

参见

+

参见

- tmr.now()

tmr.now()

-

描述

+

描述

返回系统计数器的当前值,uint32,单位:us。

-

语法

+

语法

tmr.now()

-

参数

+

参数

nil

-

返回值

+

返回值

uint32: value of counter

-

示例

-
    -- 打印计数器的当前值。
-    print(tmr.now())
-
+

示例

+
    -- 打印计数器的当前值。
+    print(tmr.now())
+
- -

参见

+

参见

- tmr.delay()

tmr.alarm()

-

描述

+

描述

闹钟函数。

-注意: 只能允许存在一个闹钟,如果在调用tmr.stop()之前重复调用tmr.alarm(),以最后一次设置的为准,此前定义的闹钟都将失效。

-

语法

+

语法

tmr.alarm(interval, repeat, function do())

-

参数

+

参数

Interval: 定时时间,单位:毫秒。

repeat: 0:一次性闹钟;1:重复闹钟。

function do(): 定时器到时回调函数。

-

返回值

-

nil

-

示例

-
    -- 每1000ms输出一个hello world
-    tmr.alarm(1000, 1, function() print("hello world") end )
-
- - -

参见

-

- tmr.now()

-

-

tmr.stop()

-

描述

-

停止闹钟功能。

-

语法

-

tmr.stop()

-

参数

-

nil.

返回值

nil

示例

-
    -- 每隔1000ms打印hello world
-    tmr.alarm(1000, 1, function() print("hello world") end )
-
-    -- 其它代码
-
-    -- 停止闹钟
-    tmr.stop()
-
- +
    -- 每1000ms输出一个hello world
+    tmr.alarm(1000, 1, function() print("hello world") end )
+

参见

- tmr.now()

+

+

tmr.stop()

+

描述

+

停止闹钟功能。

+

语法

+

tmr.stop()

+

参数

+

nil.

+

返回值

+

nil

+

示例

+
    -- 每隔1000ms打印hello world
+    tmr.alarm(1000, 1, function() print("hello world") end )
+
+    -- 其它代码
+
+    -- 停止闹钟
+    tmr.stop()
+
+ +

参见

+

- tmr.now()

GPIO 模块

-

常量

+

常量

gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW

gpio.mode()

-

描述

+

描述

将pin初始化为GPIO并设置输入输出模式。

-

语法

+

语法

gpio.mode(pin, mode)

-

参数

+

参数

pin: 0~11, IO编号

mode: 取值为:gpio.OUTPUT or gpio.INPUT, or gpio.INT(中断模式)

-

返回值

+

返回值

nil

-

示例

-
    -- 将GPIO0设置为输出模式
-    gpio.mode(0, gpio.OUTPUT)
-
+

示例

+
    -- 将GPIO0设置为输出模式
+    gpio.mode(0, gpio.OUTPUT)
 
+
-

参见

+

参见

- gpio.read()

gpio.read()

-

描述

+

描述

读取管脚电平高低。

-

语法

+

语法

gpio.read(pin)

-

参数

+

参数

pin: 0~11, IO编号

-

返回值

+

返回值

number:0:低电平, 1:高电平。

-

示例

-
    -- 读取GPIO0的电平
-    gpio.read(0)
-
+

示例

+
    -- 读取GPIO0的电平
+    gpio.read(0)
+
- -

参见

+

参见

- gpio.mode()

gpio.write()

-

描述

+

描述

设置管脚电平

-

语法

+

语法

gpio.write(pin)

-

参数

+

参数

pin: 0~11, IO编号

level: gpio.HIGH or gpio.LOW

-

返回值

+

返回值

nil

-

示例

-
    -- 设置GPIP1为输出模式,并将输出电平设置为高
-    pin=1
-    gpio.mode(pin, gpio.OUTPUT)
-    gpio.write(pin, gpio.HIGH)
-
+

示例

+
    -- 设置GPIP1为输出模式,并将输出电平设置为高
+    pin=1
+    gpio.mode(pin, gpio.OUTPUT)
+    gpio.write(pin, gpio.HIGH)
+
- -

参见

+

参见

- gpio.mode()

- gpio.read()

gpio.trig()

-

描述

+

描述

设置管脚中断模式的回调函数。

-

语法

+

语法

gpio.trig(pin, type, function(level))

-

参数

+

参数

pin: 0~11, IO编号

type: 取值为”up”, “down”, “both”, “low”, “high”, 分别代表上升沿、下降沿、双边沿、低电平、高电平触发方式。

function(level): 中断触发的回调函数,GPIO的电平作为输入参数。如果此处没有定义函数,则使用之前定义的回调函数。

-

返回值

+

返回值

nil

-

示例

-
    -- 使用GPIO0检测输入脉冲宽度
-    pulse0 = 0
-    du = 0
-    gpio.mode(0,gpio.INT)
-    function pin0cb(level)
-     du = tmr.now()  pulse0
-     print(du)
-     pulse0 = tmr.now()
-     if level == 1 then gpio.trig(0, "down ") else gpio.trig(0, "up ") end
-    end
-    gpio.trig(0, "down ",pin0cb)
-
+

示例

+
    -- 使用GPIO0检测输入脉冲宽度
+    pulse0 = 0
+    du = 0
+    gpio.mode(0,gpio.INT)
+    function pin0cb(level)
+     du = tmr.now() – pulse0
+     print(du)
+     pulse0 = tmr.now()
+     if level == 1 then gpio.trig(0, "down ") else gpio.trig(0, "up ") end
+    end
+    gpio.trig(0, "down ",pin0cb)
 
+
-

参见

+

参见

- gpio.mode()

- gpio.write()

PWM模块

pwm.setup()

-

描述

+

描述

设置管脚为pwm模式,最多支持6个pwm。

-

语法

+

语法

pwm.setup(pin, clock, duty)

-

参数

+

参数

pin: 0~11, IO编号

clock: 1~500, pwm频率

duty: 0~100, pwm占空比,百分比表示。

-

返回值

-

nil

-

示例

-
    -- 将管脚0设置为pwm输出模式,频率100Hz,占空比50-50
-    pwm.setup(0, 100, 50)
-
- - -

参见

-

- pwm.start()

-

-

pwm.close()

-

描述

-

退出pwm模式。

-

语法

-

pwm.close(pin)

-

参数

-

pin: 0~11, IO编号

返回值

nil

示例

-
    pwm.close(0)
-
- +
    -- 将管脚0设置为pwm输出模式,频率100Hz,占空比50-50
+    pwm.setup(0, 100, 50)
+

参见

- pwm.start()

-

-

pwm.start()

+

+

pwm.close()

描述

-

pwm启动,可以在对应的GPIO检测到波形。

+

退出pwm模式。

语法

-

pwm.start(pin)

+

pwm.close(pin)

参数

pin: 0~11, IO编号

返回值

nil

示例

-
    pwm.start(0)
-
- +
    pwm.close(0)
+

参见

-

- pwm.stop()

-

-

pwm.stop()

+

- pwm.start()

+

+

pwm.start()

描述

-

暂停pwm输出波形。

+

pwm启动,可以在对应的GPIO检测到波形。

语法

-

pwm.stop(pin)

+

pwm.start(pin)

参数

pin: 0~11, IO编号

返回值

nil

示例

-
    pwm.stop(0)
-
- +
    pwm.start(0)
+

参见

-

- pwm.start()

-

-

pwm.setclock()

+

- pwm.stop()

+

+

pwm.stop()

描述

-

设置pwm的频率

--Note: 设置pwm频率将会同步改变其他pwm输出的频率,当前版本的所有pwm仅支持同一频率输出。

+

暂停pwm输出波形。

语法

-

pwm.setclock(pin, clock)

+

pwm.stop(pin)

参数

-

pin: 0~11, IO编号

-clock: 1~500, pwm周期

+

pin: 0~11, IO编号

返回值

nil

示例

-
    pwm.setclock(0, 100)
-
- +
    pwm.stop(0)
+

参见

+

- pwm.start()

+

+

pwm.setclock()

+

描述

+

设置pwm的频率

+-Note: 设置pwm频率将会同步改变其他pwm输出的频率,当前版本的所有pwm仅支持同一频率输出。

+

语法

+

pwm.setclock(pin, clock)

+

参数

+

pin: 0~11, IO编号

+clock: 1~500, pwm周期

+

返回值

+

nil

+

示例

+
    pwm.setclock(0, 100)
+
+ +

参见

- pwm.getclock()

pwm.getclock()

-

描述

+

描述

获取pin的pwm工作频率

-

语法

+

语法

pwm.getclock(pin)

-

参数

+

参数

pin: 0~11, IO编号

-

返回值

+

返回值

number:pin的pwm工作频率

-

示例

-
    print(pwm.getclock(0))
-
+

示例

+
    print(pwm.getclock(0))
+
- -

参见

+

参见

- pwm.setclock()

pwm.setduty()

-

描述

+

描述

设置pin的占空比。

-

语法

+

语法

pwm.setduty(pin, duty)

-

参数

+

参数

pin: 0~11, IO编号

duty: 0~100, pwm的占空比,以百分数表示

-

返回值

-

nil

-

示例

-
    pwm.setduty(0, 50)
-
- - -

参见

-

- pwm.getduty()

-

-

pwm.getduty()

-

描述

-

获取pin的pwm占空比。

-

语法

-

pwm.getduty(pin)

-

参数

-

pin: 0~11, IO编号

返回值

nil

示例

-
    -- D0 连接绿色led
-    -- D1 连接蓝色led
-    -- D2 连接红色led
-    pwm.setup(0,500,50)
-    pwm.setup(1,500,50)
-    pwm.setup(2,500,50)
-    pwm.start(0)
-    pwm.start(1)
-    pwm.start(2)
-    function led(r,g,b)
-      pwm.setduty(0,g)
-      pwm.setduty(1,b)
-      pwm.setduty(2,r)
-    end
-    led(50,0,0) --  led显示红色
-    led(0,0,50) -- led显示蓝色
-
- +
    pwm.setduty(0, 50)
+

参见

+

- pwm.getduty()

+

+

pwm.getduty()

+

描述

+

获取pin的pwm占空比。

+

语法

+

pwm.getduty(pin)

+

参数

+

pin: 0~11, IO编号

+

返回值

+

nil

+

示例

+
    -- D0 连接绿色led
+    -- D1 连接蓝色led
+    -- D2 连接红色led
+    pwm.setup(0,500,50)
+    pwm.setup(1,500,50)
+    pwm.setup(2,500,50)
+    pwm.start(0)
+    pwm.start(1)
+    pwm.start(2)
+    function led(r,g,b)
+      pwm.setduty(0,g)
+      pwm.setduty(1,b)
+      pwm.setduty(2,r)
+    end
+    led(50,0,0) --  led显示红色
+    led(0,0,50) -- led显示蓝色
+
+
+ +

参见

- pwm.setduty()

net 模块

-

常量

+

常量

net.TCP, net.UDP

net.createServer()

-

描述

-

创建一个server。

-

语法

-

net.createServer(type, secure)

-

参数

-

type: 取值为:net.TCP 或者 net.UDP

-secure: 设置为true或者false, true代表安全连接,false代表普通连接。

-

返回值

-

net.server子模块

-

示例

-
    net.createServer(net.TCP, true)
-
- - -

参见

-

- net.createConnection()

-

-

net.createConnection()

描述

-

创建一个client。

+

创建一个server。

语法

-

net.createConnection(type, secure)

+

net.createServer(type, secure)

参数

type: 取值为:net.TCP 或者 net.UDP

secure: 设置为true或者false, true代表安全连接,false代表普通连接。

返回值

net.server子模块

示例

-
    net.createConnection(net.UDP, false)
-
- +
    net.createServer(net.TCP, true)
+

参见

+

- net.createConnection()

+

+

net.createConnection()

+

描述

+

创建一个client。

+

语法

+

net.createConnection(type, secure)

+

参数

+

type: 取值为:net.TCP 或者 net.UDP

+secure: 设置为true或者false, true代表安全连接,false代表普通连接。

+

返回值

+

net.server子模块

+

示例

+
    net.createConnection(net.UDP, false)
+
+ +

参见

- net.createServer()

net.server 子模块

listen()

-

描述

+

描述

侦听指定ip地址的端口。

-

语法

+

语法

net.server.listen(port,[ip],function(net.socket))

-

参数

+

参数

port: 端口号

ip:ip地址字符串,可以省略

function(net.socket): 连接创建成功的回调函数,可以作为参数传给调用函数。

-

返回值

-

nil

-

示例

-
    -- 创建一个server
-    sv=net.createServer(net.TCP, false)
-    -- server侦听端口80,如果收到数据将数据打印至控制台,并向远端发送‘hello world’
-    sv:listen(80,function(c)
-      c:on("receive", function(sck, pl) print(pl) end)
-      c:send("hello world")
-      end)
-
- - -

参见

-

- net.createServer()

-

-

close()

-

描述

-

关闭server

-

语法

-

net.server.close()

-

参数

-

nil

返回值

nil

示例

-
    -- 创建server
-    sv=net.createServer(net.TCP, false)
-    -- 关闭server
-    sv:close()
-
- +
    -- 创建一个server
+    sv=net.createServer(net.TCP, false)
+    -- server侦听端口80,如果收到数据将数据打印至控制台,并向远端发送‘hello world’
+    sv:listen(80,function(c)
+      c:on("receive", function(sck, pl) print(pl) end)
+      c:send("hello world")
+      end)
+

参见

- net.createServer()

+

+

close()

+

描述

+

关闭server

+

语法

+

net.server.close()

+

参数

+

nil

+

返回值

+

nil

+

示例

+
    -- 创建server
+    sv=net.createServer(net.TCP, false)
+    -- 关闭server
+    sv:close()
+
+ +

参见

+

- net.createServer()

net.socket 子模块

connect()

-

描述

+

描述

连接至远端。

-

语法

+

语法

connect(port, ip)

-

参数

+

参数

port: 端口号

ip: ip地址字符串

-

返回值

+

返回值

nil

-

参见

+

参见

- net.socket:on()

send()

-

描述

+

描述

通过连接向远端发送数据。

-

语法

+

语法

send(string, function(sent))

-

参数

+

参数

string: 待发送的字符串

function(sent): 发送字符串后的回调函数。

-

返回值

+

返回值

nil

-

参见

+

参见

- net.socket:on()

on()

-

描述

+

描述

向事件注册回调函数。

-

语法

+

语法

on(event, function cb())

-

参数

+

参数

event: 字符串,取值为: “connection”, “reconnection”, “disconnection”, “receive”, “sent”

function cb(net.socket, [string]): 回调函数。第一个参数是socket.

如果事件是”receive”, 第二个参数则为接收到的字符串。

-

返回值

+

返回值

nil

-

示例

-
    sk=net.createConnection(net.TCP, false)
-    sk:on("receive", function(sck, c) print(c) end )
-    sk:connect(80,"192.168.0.66")
-    sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
-
+

示例

+
    sk=net.createConnection(net.TCP, false)
+    sk:on("receive", function(sck, c) print(c) end )
+    sk:connect(80,"192.168.0.66")
+    sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
+
- -

参见

+

参见

- net.createServer()

close()

-

描述

+

描述

关闭socket。

-

语法

+

语法

close()

-

参数

+

参数

nil

-

返回值

+

返回值

nil

-

参见

+

参见

- net.createServer()

dns()

-

描述

+

描述

获取当前域的ip

-

语法

+

语法

dns(domain, function(net.socket, ip))

-

参数

+

参数

domain: 当前域的名称

function (net.socket, ip): 回调函数。第一个参数是socket,第二个参数是当前域的ip字符串。

-

返回值

+

返回值

nil

-

参见

+

参见

- net.createServer()

i2c模块

-

常量

+

常量

i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)模式目前不支持。

i2c.setup()

-

描述

+

描述

初始化i2c。

-

语法

+

语法

i2c.setup(id, pinSDA, pinSCL, speed)

-

参数

+

参数

id = 0

pinSDA: 0~11, IO编号

pinSCL: 0~11, IO编号

speed: i2c.SLOW

-

返回值

+

返回值

nil

-

参见

+

参见

- i2c.read()

i2c.start()

-

描述

+

描述

启动i2c传输。

-

语法

+

语法

i2c.start(id)

-

参数

+

参数

id = 0

-

返回值

+

返回值

nil

-

参见

+

参见

- i2c.read()

i2c.stop()

-

描述

+

描述

停止i2c传输。

-

语法

+

语法

i2c.stop(id)

-

参数

+

参数

id = 0

-

返回值

+

返回值

nil

-

参见

+

参见

- i2c.read()

i2c.address()

-

描述

+

描述

设置i2c地址以及读写模式。

-

语法

+

语法

i2c.address(id, device_addr, direction)

-

参数

+

参数

id=0

device_addr: 设备地址。

direction: i2c.TRANSMITTER:写模式;i2c. RECEIVER:读模式。

-

返回值

+

返回值

nil

-

参见

+

参见

- i2c.read()

i2c.write()

-

描述

+

描述

向i2c写数据。数据可以是多个数字, 字符串或者lua table。

-

语法

+

语法

i2c.write(id, data1, data2,…)

-

参数

+

参数

id=0

data: 数据可以是多个数字, 字符串或者lua table。

-

返回值

+

返回值

nil

-

示例

-
    i2c.write(0, "hello", "world")
-
+

示例

+
    i2c.write(0, "hello", "world")
+
- -

参见

+

参见

- i2c.read()

i2c.read()

-

描述

+

描述

读取len个字节的数据。

-

语法

+

语法

i2c.read(id, len)

-

参数

+

参数

id=0

len: 数据长度。

-

返回值

+

返回值

string:接收到的数据。

-

示例

-
    id=0
-    sda=1
-    scl=0
+

示例

+
    id=0
+    sda=1
+    scl=0
 
-    -- 初始化i2c, 将pin1设置为sda, 将pin0设置为scl
-    i2c.setup(id,sda,scl,i2c.SLOW)
+    -- 初始化i2c, 将pin1设置为sda, 将pin0设置为scl
+    i2c.setup(id,sda,scl,i2c.SLOW)
 
-    -- 用户定义函数:读取地址dev_addr的寄存器reg_addr中的内容。
-    function read_reg(dev_addr, reg_addr)
-      i2c.start(id)
-      i2c.address(id, dev_addr ,i2c.TRANSMITTER)
-      i2c.write(id,reg_addr)
-      i2c.stop(id)
-      i2c.start(id)
-      i2c.address(id, dev_addr,i2c.RECEIVER)
-      c=i2c.read(id,1)
-      i2c.stop(id)
-      return c
-    end
+    -- 用户定义函数:读取地址dev_addr的寄存器reg_addr中的内容。
+    function read_reg(dev_addr, reg_addr)
+      i2c.start(id)
+      i2c.address(id, dev_addr ,i2c.TRANSMITTER)
+      i2c.write(id,reg_addr)
+      i2c.stop(id)
+      i2c.start(id)
+      i2c.address(id, dev_addr,i2c.RECEIVER)
+      c=i2c.read(id,1)
+      i2c.stop(id)
+      return c
+    end
 
-    -- 读取0x77的寄存器0xAA中的内容。
-    reg = read_reg(0x77, 0xAA)
-    pirnt(string.byte(reg))
-
+ -- 读取0x77的寄存器0xAA中的内容。 + reg = read_reg(0x77, 0xAA) + pirnt(string.byte(reg)) + -

参见

-

- i2c.write()

\ No newline at end of file +

参见

+

- i2c.write()

+

adc 模块

+

常量

+

+

+

adc.read()

+

描述

+

读取adc的值,esp8266只有一个10bit adc,id为0,最大值1024

+

语法

+

adc.read(id)

+

参数

+

id = 0

+

返回值

+

adc 值 10bit,最大1024.

+

参见

+

-

\ No newline at end of file diff --git a/nodemcu_api_cn.md b/nodemcu_api_cn.md index 16f3570b..a184b53b 100644 --- a/nodemcu_api_cn.md +++ b/nodemcu_api_cn.md @@ -1,8 +1,12 @@ # **nodeMcu API说明** # [English Version](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en) -###版本 0.9.2 build 2014-11-18 +###版本 0.9.2 build 2014-11-19 ###变更日志: +2014-11-19
+增加adc模块,adc.read(0)读取adc的值。
+wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。 + 2014-11-18
修正tcp服务器不能使用:close()函数关闭tcp连接的问题。
tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)
@@ -807,6 +811,36 @@ mac地址字符串,如:"18-33-44-FE-55-BB" ####参见 **-** [wifi.sta.getip()](#ws_getip) + +## wifi.sta.getap() +####描述 +扫描并列出ap,结果以一个lua table为参数传递给回调函数。 + +####语法 +wifi.sta.getap(function(table)) + +####参数 +function(table): 当扫描结束时,调用此回调函数
+ 扫描结果是一个lua table,key为ap的ssid,value为其他信息,格式:authmode,rssi,bssid,channel + + +####返回值 +nil + +####示例 + +```lua + -- print ap list + function listap(t) + for k,v in pairs(t) do + print(k.." : "..v) + end + end + wifi.sta.getap(listap) +``` + +####参见 +**-** [wifi.sta.getip()](#ws_getip) #wifi.ap 子模块 @@ -1707,4 +1741,25 @@ string:接收到的数据。 ``` ####参见 -**-** [i2c.write()](#ic_write) \ No newline at end of file +**-** [i2c.write()](#ic_write) + +#adc 模块 +##常量 +无 + + +## adc.read() +####描述 +读取adc的值,esp8266只有一个10bit adc,id为0,最大值1024 + +####语法 +adc.read(id) + +####参数 +id = 0
+ +####返回值 +adc 值 10bit,最大1024. + +####参见 +**-** []() diff --git a/nodemcu_api_en.html b/nodemcu_api_en.html index 3e0ac9a0..e5c9b0c7 100644 --- a/nodemcu_api_en.html +++ b/nodemcu_api_en.html @@ -1014,76 +1014,14 @@ body .markdown-body page-break-after: avoid; } } -nodemcu_api_en

nodeMcu API Instruction

+nodemcu_api_en

nodeMcu API Instruction

中文版本

-

version 0.9.2 build 2014-11-18

+

version 0.9.2 build 2014-11-19

change log:

+

2014-11-19

+add adc module, use adc.read(0) to read adc value, no tests made.

+add wifi.sta.getap() api to wifi.sta module, to get ap list.

2014-11-18

bug fixed: net.socket:connect() has no effect.

2014-11-18

@@ -1162,9 +1100,8 @@ key is triged only when key is released

Returns

nil

Example

-
    node.restart();
-
- +
    node.restart();
+

See also

-

@@ -1180,9 +1117,8 @@ key is triged only when key is released

Returns

nil

Example

-
    node.dsleep(us);
-
- +
    node.dsleep(us);
+

See also

-

@@ -1197,9 +1133,8 @@ key is triged only when key is released

Returns

number:chip ID

Example

-
    id = node.chipid();
-
- +
    id = node.chipid();
+

See also

-

@@ -1214,9 +1149,8 @@ key is triged only when key is released

Returns

number: system heap size left in bytes

Example

-
    heap_size = node.heap();
-
- +
    heap_size = node.heap();
+

See also

-

@@ -1233,9 +1167,8 @@ Default function: long: change LED blinking rate, short: reset chip

Returns

nil

Example

-
    node.key("long", function(){print('hello world')})
-
- +
    node.key("long", function(){print('hello world')})
+

See also

-

@@ -1251,10 +1184,9 @@ High: LED off time. Unit: milliseconds, time resolution: 80~100ms

Returns

nil

Example

-
    -- turn led on forever.
-    node.led(0);
-
- +
    -- turn led on forever.
+    node.led(0);
+

See also

-

@@ -1270,10 +1202,9 @@ same as pcall(loadstring(str)) but support multi seperated line.

Returns

nil

Example

-
    -- never use node.input() in console. no effect.
-    sk:on("receive", function(conn, payload) node.input(payload) end)
-
- +
    -- never use node.input() in console. no effect.
+    sk:on("receive", function(conn, payload) node.input(payload) end)
+

See also

-

@@ -1289,35 +1220,33 @@ serial_debug: 1 output also show in serial. 0: no serial output.

Returns

nil

Example

-
    function tonet(str)
-      sk:send(str)
-      -- print(str) WRONG!!! never ever print something in this function
-      -- because this will cause a recursive function call!!!
-    end
-    node.ouput(tonet, 1)  -- serial also get the lua output.
-
- - -
    -- 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)
-
+
    function tonet(str)
+      sk:send(str)
+      -- print(str) WRONG!!! never ever print something in this function
+      -- because this will cause a recursive function call!!!
+    end
+    node.ouput(tonet, 1)  -- serial also get the lua output.
+
+
    -- 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

-

@@ -1333,10 +1262,9 @@ serial_debug: 1 output also show in serial. 0: no serial output.

Returns

nil

Example

-
    -- remove "foo.lua" from file system.
-    file.remove("foo.lua")
-
- +
    -- remove "foo.lua" from file system.
+    file.remove("foo.lua")
+

See also

- file.open()

@@ -1359,12 +1287,11 @@ mode:

Returns

nil

Example

-
    -- open 'init.lua', print the first line.
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- open 'init.lua', print the first line.
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

See also

- file.close()

@@ -1380,12 +1307,11 @@ mode:

Returns

nil

Example

-
    -- open 'init.lua', print the first line.
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- open 'init.lua', print the first line.
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

See also

- file.open()

@@ -1402,12 +1328,11 @@ mode:

file content in string, line by line, include EOL(‘\n’)

return nil when EOF.

Example

-
    -- print the first line of 'init.lua'
-    file.open("init.lua", "r")
-    print(file.readline())
-    file.close()
-
- +
    -- print the first line of 'init.lua'
+    file.open("init.lua", "r")
+    print(file.readline())
+    file.close()
+

See also

- file.open()

@@ -1424,13 +1349,12 @@ return nil when EOF.

true: write ok.
nil: there is error

Example

-
    -- open 'init.lua' in 'a+' mode
-    file.open("init.lua", "a+")
-    -- write 'foo bar' to the end of the file
-    file.writeline('foo bar')
-    file.close()
-
- +
    -- open 'init.lua' in 'a+' mode
+    file.open("init.lua", "a+")
+    -- write 'foo bar' to the end of the file
+    file.writeline('foo bar')
+    file.close()
+

See also

- file.open()

@@ -1447,13 +1371,12 @@ nil: there is error

true: write ok.
nil: there is error

Example

-
    -- open 'init.lua' in 'a+' mode
-    file.open("init.lua", "a+")
-    -- write 'foo bar' to the end of the file
-    file.write('foo bar')
-    file.close()
-
- +
    -- open 'init.lua' in 'a+' mode
+    file.open("init.lua", "a+")
+    -- write 'foo bar' to the end of the file
+    file.write('foo bar')
+    file.close()
+

See also

- file.open()

@@ -1469,14 +1392,13 @@ nil: there is error

Returns

nil

Example

-
    -- open 'init.lua' in 'a+' mode
-    file.open("init.lua", "a+")
-    -- write 'foo bar' to the end of the file
-    file.write('foo bar')
-    file.flush()
-    file.close()
-
- +
    -- open 'init.lua' in 'a+' mode
+    file.open("init.lua", "a+")
+    -- write 'foo bar' to the end of the file
+    file.write('foo bar')
+    file.flush()
+    file.close()
+

See also

- file.open()

@@ -1497,16 +1419,15 @@ offset: default 0

success: returns the final file position

fail: returns nil

Example

-
    -- open 'init.lua' in 'a+' mode
-    file.open("init.lua", "a+")
-    -- write 'foo bar' to the end of the file
-    file.write('foo bar')
-    file.flush()
-    file.seek("set")
-    print(file.readline())
-    file.close()
-
- +
    -- open 'init.lua' in 'a+' mode
+    file.open("init.lua", "a+")
+    -- write 'foo bar' to the end of the file
+    file.write('foo bar')
+    file.flush()
+    file.seek("set")
+    print(file.readline())
+    file.close()
+

See also

- file.open()

@@ -1522,12 +1443,11 @@ fail: returns nil

Returns

a lua table which contains the {file name: file size} pairs

Example

-
    l = file.list();
-    for k,v in l do
-      print("name:"..k..", size:"..v)
-    end
-
- +
    l = file.list();
+    for k,v in l do
+      print("name:"..k..", size:"..v)
+    end
+

See also

- file.remove()

@@ -1545,9 +1465,8 @@ fail: returns nil

Returns

current mode after setup

Example

-
    wifi.setmode(wifi.STATION)
-
- +
    wifi.setmode(wifi.STATION)
+

See also

- wifi.getmode()

@@ -1562,9 +1481,8 @@ fail: returns nil

Returns

wifi operation mode

Example

-
    print(wifi.getmode())
-
- +
    print(wifi.getmode())
+

See also

- wifi.setmode()

@@ -1580,9 +1498,8 @@ succeed_callback: callback function called after configuration, which is called

Returns

nil

Example

-
    wifi.startsmart(6, cb())
-
- +
    wifi.startsmart(6, cb())
+

See also

- wifi.stopsmart()

@@ -1597,9 +1514,8 @@ succeed_callback: callback function called after configuration, which is called

Returns

nil

Example

-
    wifi.stopsmart()
-
- +
    wifi.stopsmart()
+

See also

- wifi.startsmart()

@@ -1616,9 +1532,8 @@ password: string which is less than 64 bytes.

Returns

nil

Example

-
    wifi.sta.config("myssid","mypassword")
-
- +
    wifi.sta.config("myssid","mypassword")
+

See also

- wifi.sta.connect()

@@ -1634,9 +1549,8 @@ password: string which is less than 64 bytes.

Returns

nil

Example

-
    wifi.sta.connect()
-
- +
    wifi.sta.connect()
+

See also

- wifi.sta.disconnect()

@@ -1652,9 +1566,8 @@ password: string which is less than 64 bytes.

Returns

nil

Example

-
    wifi.sta.disconnect()
-
- +
    wifi.sta.disconnect()
+

See also

- wifi.sta.config()

@@ -1670,9 +1583,8 @@ password: string which is less than 64 bytes.

Returns

nil

Example

-
    wifi.sta.autoconnect()
-
- +
    wifi.sta.autoconnect()
+

See also

- wifi.sta.config()

@@ -1689,10 +1601,9 @@ password: string which is less than 64 bytes.

Returns

ip address in string, for example:”192.168.0.111”

Example

-
    -- print current ip
-    print(wifi.sta.getip())
-
- +
    -- print current ip
+    print(wifi.sta.getip())
+

See also

- wifi.sta.getmac()

@@ -1707,674 +1618,688 @@ password: string which is less than 64 bytes.

Returns

mac address in string, for example:”18-33-44-FE-55-BB”

Example

-
    -- print current mac address
-    print(wifi.sta.getmac())
-
- +
    -- print current mac address
+    print(wifi.sta.getmac())
+

See also

- wifi.sta.getip()

+

+

wifi.sta.getap()

+

Description

+

scan and get ap list as a lua table into callback function.

+

Syntax

+

wifi.sta.getap(function(table))

+

Parameters

+

function(table): a callback function to receive ap table when scan is done

+ this function receive a table, the key is the ssid, value is other info in format: authmode,rssi,bssid,channel

+

Returns

+

nil

+

Example

+
    -- print ap list
+    function listap(t)
+      for k,v in pairs(t) do
+        print(k.." : "..v)
+      end
+    end
+    wifi.sta.getap(listap)
+
+ +

See also

+

- wifi.sta.getip()

wifi.ap module

wifi.ap.config()

-

Description

+

Description

set ssid and password in ap mode.

-

Syntax

+

Syntax

wifi.ap.config(cfg)

-

Parameters

+

Parameters

cfg: lua table to setup ap.

-

Example:

-
     cfg={}
-     cfg.ssid="myssid"
-     cfg.pwd="mypwd"
-     wifi.ap.setconfig(cfg)
-
+

Example:

+
     cfg={}
+     cfg.ssid="myssid"
+     cfg.pwd="mypwd"
+     wifi.ap.setconfig(cfg)
+
- -

Returns

+

Returns

nil

-

Example

-
    wifi.ap.config(ssid, 'password')
-
+

Example

+
    wifi.ap.config(ssid, 'password')
+
- -

See also

+

See also

-

wifi.ap.getip()

-

Description

-

get ip in ap mode.

-

Syntax

-

wifi.ap.getip()

-

Parameters

-

nil

-

Returns

-

ip address in string, for example:”192.168.0.111”

-

Example

-
    wifi.ap.getip()
-
- - -

See also

-

- wifi.ap.getmac()

-

-

wifi.ap.getmac()

Description

-

get mac address in ap mode.

+

get ip in ap mode.

Syntax

-

wifi.ap.getmac()

+

wifi.ap.getip()

Parameters

nil

Returns

-

mac address in string, for example:”1A-33-44-FE-55-BB”

+

ip address in string, for example:”192.168.0.111”

Example

-
    wifi.ap.getmac()
-
- +
    wifi.ap.getip()
+

See also

+

- wifi.ap.getmac()

+

+

wifi.ap.getmac()

+

Description

+

get mac address in ap mode.

+

Syntax

+

wifi.ap.getmac()

+

Parameters

+

nil

+

Returns

+

mac address in string, for example:”1A-33-44-FE-55-BB”

+

Example

+
    wifi.ap.getmac()
+
+ +

See also

- wifi.ap.getip()

timer module

tmr.delay()

-

Description

+

Description

delay us micro seconds.

-

Syntax

+

Syntax

tmr.dealy(us)

-

Parameters

+

Parameters

us: delay time in micro second

-

Returns

+

Returns

nil

-

Example

-
    -- delay 100us
-    tmr.delay(100)
-
+

Example

+
    -- delay 100us
+    tmr.delay(100)
+
- -

See also

+

See also

- tmr.now()

tmr.now()

-

Description

+

Description

return the current value of system counter: uint32, us.

-

Syntax

+

Syntax

tmr.now()

-

Parameters

+

Parameters

nil

-

Returns

+

Returns

uint32: value of counter

-

Example

-
    -- print current value of counter
-    print(tmr.now())
-
+

Example

+
    -- print current value of counter
+    print(tmr.now())
+
- -

See also

+

See also

- tmr.delay()

tmr.alarm()

-

Description

+

Description

alarm time.

-

Syntax

+

Syntax

tmr.alarm(interval, repeat, function do())

-

Parameters

+

Parameters

Interval: alarm time, unit: millisecond

repeat: 0 - one time alarm, 1 - repeat

function do(): callback function for alarm timed out

-

Returns

-

nil

-

Example

-
    -- print "hello world" every 1000ms
-    tmr.alarm(1000, 1, function() print("hello world") end )
-
- - -

See also

-

- tmr.now()

-

-

tmr.stop()

-

Description

-

stop alarm.

--Note: only one alarm is allowed, the previous one would be replaced if tmr.alarm() called again before tmr.stop().

-

Syntax

-

tmr.stop()

-

Parameters

-

nil.

Returns

nil

Example

-
    -- print "hello world" every 1000ms
-    tmr.alarm(1000, 1, function() print("hello world") end )
-
-    -- something else
-
-    -- stop alarm
-    tmr.stop()
-
- +
    -- print "hello world" every 1000ms
+    tmr.alarm(1000, 1, function() print("hello world") end )
+

See also

- tmr.now()

+

+

tmr.stop()

+

Description

+

stop alarm.

+-Note: only one alarm is allowed, the previous one would be replaced if tmr.alarm() called again before tmr.stop().

+

Syntax

+

tmr.stop()

+

Parameters

+

nil.

+

Returns

+

nil

+

Example

+
    -- print "hello world" every 1000ms
+    tmr.alarm(1000, 1, function() print("hello world") end )
+
+    -- something else
+
+    -- stop alarm
+    tmr.stop()
+
+ +

See also

+

- tmr.now()

GPIO module

CONSTANT

gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW

gpio.mode()

-

Description

+

Description

initialize pin to GPIO mode, set the pin in/out mode.

-

Syntax

+

Syntax

gpio.mode(pin, mode)

-

Parameters

+

Parameters

pin: 0~11, IO index

mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)

-

Returns

+

Returns

nil

-

Example

-
    -- set gpio 0 as output.
-    gpio.mode(0, gpio.OUTPUT)
-
+

Example

+
    -- set gpio 0 as output.
+    gpio.mode(0, gpio.OUTPUT)
 
+
-

See also

+

See also

- gpio.read()

gpio.read()

-

Description

+

Description

read pin value.

-

Syntax

+

Syntax

gpio.read(pin)

-

Parameters

+

Parameters

pin: 0~11, IO index

-

Returns

+

Returns

number:0 - low, 1 - high

-

Example

-
    -- read value of gpio 0.
-    gpio.read(0)
-
+

Example

+
    -- read value of gpio 0.
+    gpio.read(0)
+
- -

See also

+

See also

- gpio.mode()

gpio.write()

-

Description

+

Description

set pin value.

-

Syntax

+

Syntax

gpio.write(pin)

-

Parameters

+

Parameters

pin: 0~11, IO index

level: gpio.HIGH or gpio.LOW

-

Returns

+

Returns

nil

-

Example

-
    -- set pin index 1 to GPIO mode, and set the pin to high.
-    pin=1
-    gpio.mode(pin, gpio.OUTPUT)
-    gpio.write(pin, gpio.HIGH)
-
+

Example

+
    -- set pin index 1 to GPIO mode, and set the pin to high.
+    pin=1
+    gpio.mode(pin, gpio.OUTPUT)
+    gpio.write(pin, gpio.HIGH)
+
- -

See also

+

See also

- gpio.mode()

- gpio.read()

gpio.trig()

-

Description

+

Description

set the interrupt callback function for pin.

-

Syntax

+

Syntax

gpio.trig(pin, type, function(level))

-

Parameters

+

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.

-

Returns

+

Returns

nil

-

Example

-
    -- use pin 0 as the input pulse width counter
-    pulse0 = 0
-    du = 0
-    gpio.mode(0,gpio.INT)
-    function pin0cb(level)
-     du = tmr.now()  pulse0
-     print(du)
-     pulse0 = tmr.now()
-     if level == 1 then gpio.trig(0, "down ") else gpio.trig(0, "up ") end
-    end
-    gpio.trig(0, "down ",pin0cb)
-
+

Example

+
    -- use pin 0 as the input pulse width counter
+    pulse0 = 0
+    du = 0
+    gpio.mode(0,gpio.INT)
+    function pin0cb(level)
+     du = tmr.now() – pulse0
+     print(du)
+     pulse0 = tmr.now()
+     if level == 1 then gpio.trig(0, "down ") else gpio.trig(0, "up ") end
+    end
+    gpio.trig(0, "down ",pin0cb)
 
+
-

See also

+

See also

- gpio.mode()

- gpio.write()

PWM module

pwm.setup()

-

Description

+

Description

set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.

-

Syntax

+

Syntax

pwm.setup(pin, clock, duty)

-

Parameters

+

Parameters

pin: 0~11, IO index

clock: 1~500, pwm frequency

duty: 0~100, pwm duty cycle in percentage

-

Returns

-

nil

-

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()

-

-

pwm.close()

-

Description

-

quit PWM mode for specified pin.

-

Syntax

-

pwm.close(pin)

-

Parameters

-

pin: 0~11, IO index

Returns

nil

Example

-
    pwm.close(0)
-
- +
    -- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.
+    pwm.setup(0, 100, 50)
+

See also

- pwm.start()

-

-

pwm.start()

+

+

pwm.close()

Description

-

pwm starts, you can detect the waveform on the gpio.

+

quit PWM mode for specified pin.

Syntax

-

pwm.start(pin)

+

pwm.close(pin)

Parameters

pin: 0~11, IO index

Returns

nil

Example

-
    pwm.start(0)
-
- +
    pwm.close(0)
+

See also

-

- pwm.stop()

-

-

pwm.stop()

+

- pwm.start()

+

+

pwm.start()

Description

-

pause the output of PWM waveform.

+

pwm starts, you can detect the waveform on the gpio.

Syntax

-

pwm.stop(pin)

+

pwm.start(pin)

Parameters

pin: 0~11, IO index

Returns

nil

Example

-
    pwm.stop(0)
-
- +
    pwm.start(0)
+

See also

-

- pwm.start()

-

-

pwm.setclock()

+

- pwm.stop()

+

+

pwm.stop()

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.

+

pause the output of PWM waveform.

Syntax

-

pwm.setclock(pin, clock)

+

pwm.stop(pin)

Parameters

-

pin: 0~11, IO index.

-clock: 1~500, pwm frequency.

+

pin: 0~11, IO index

Returns

nil

Example

-
    pwm.setclock(0, 100)
-
- +
    pwm.stop(0)
+

See also

+

- pwm.start()

+

+

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.

+

Syntax

+

pwm.setclock(pin, clock)

+

Parameters

+

pin: 0~11, IO index.

+clock: 1~500, pwm frequency.

+

Returns

+

nil

+

Example

+
    pwm.setclock(0, 100)
+
+ +

See also

- pwm.getclock()

pwm.getclock()

-

Description

+

Description

get pwm frequency of pin.

-

Syntax

+

Syntax

pwm.getclock(pin)

-

Parameters

+

Parameters

pin: 0~11, IO index.

-

Returns

+

Returns

number:pwm frequency of pin

-

Example

-
    print(pwm.getclock(0))
-
+

Example

+
    print(pwm.getclock(0))
+
- -

See also

+

See also

- pwm.setclock()

pwm.setduty()

-

Description

+

Description

set duty clycle for pin.

-

Syntax

+

Syntax

pwm.setduty(pin, duty)

-

Parameters

+

Parameters

pin: 0~11, IO index

duty: 0~100, pwm duty cycle in percentage

-

Returns

-

nil

-

Example

-
    pwm.setduty(0, 50)
-
- - -

See also

-

- pwm.getduty()

-

-

pwm.getduty()

-

Description

-

get duty clycle for pin.

-

Syntax

-

pwm.getduty(pin)

-

Parameters

-

pin: 0~11, IO index

Returns

nil

Example

-
    -- D0 is connected to green led
-    -- D1 is connected to blue led
-    -- D2 is connected to red led
-    pwm.setup(0,500,50)
-    pwm.setup(1,500,50)
-    pwm.setup(2,500,50)
-    pwm.start(0)
-    pwm.start(1)
-    pwm.start(2)
-    function led(r,g,b)
-      pwm.setduty(0,g)
-      pwm.setduty(1,b)
-      pwm.setduty(2,r)
-    end
-    led(50,0,0) --  set led to red
-    led(0,0,50) -- set led to blue.
-
- +
    pwm.setduty(0, 50)
+

See also

+

- pwm.getduty()

+

+

pwm.getduty()

+

Description

+

get duty clycle for pin.

+

Syntax

+

pwm.getduty(pin)

+

Parameters

+

pin: 0~11, IO index

+

Returns

+

nil

+

Example

+
    -- D0 is connected to green led
+    -- D1 is connected to blue led
+    -- D2 is connected to red led
+    pwm.setup(0,500,50)
+    pwm.setup(1,500,50)
+    pwm.setup(2,500,50)
+    pwm.start(0)
+    pwm.start(1)
+    pwm.start(2)
+    function led(r,g,b)
+      pwm.setduty(0,g)
+      pwm.setduty(1,b)
+      pwm.setduty(2,r)
+    end
+    led(50,0,0) --  set led to red
+    led(0,0,50) -- set led to blue.
+
+
+ +

See also

- pwm.setduty()

net module

CONSTANT

net.TCP, net.UDP

net.createServer()

-

Description

-

create a server.

-

Syntax

-

net.createServer(type, secure)

-

Parameters

-

type: net.TCP or net.UDP

-secure: true or false, true for safe link, false for ordinary link

-

Returns

-

net.server sub module

-

Example

-
    net.createServer(net.TCP, true)
-
- - -

See also

-

- net.createConnection()

-

-

net.createConnection()

Description

-

create a client.

+

create a server.

Syntax

-

net.createConnection(type, secure)

+

net.createServer(type, secure)

Parameters

type: net.TCP or net.UDP

secure: true or false, true for safe link, false for ordinary link

Returns

net.server sub module

Example

-
    net.createConnection(net.UDP, false)
-
- +
    net.createServer(net.TCP, true)
+

See also

+

- net.createConnection()

+

+

net.createConnection()

+

Description

+

create a client.

+

Syntax

+

net.createConnection(type, secure)

+

Parameters

+

type: net.TCP or net.UDP

+secure: true or false, true for safe link, false for ordinary link

+

Returns

+

net.server sub module

+

Example

+
    net.createConnection(net.UDP, false)
+
+ +

See also

- net.createServer()

net.server module

listen()

-

Description

+

Description

listen on port from [ip] address.

-

Syntax

+

Syntax

net.server.listen(port,[ip],function(net.socket))

-

Parameters

+

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

-

nil

-

Example

-
    -- create a server
-    sv=net.createServer(net.TCP, false)
-    -- server listen on 80, if data received, print data to console, and send "hello world" to remote.
-    sv:listen(80,function(c)
-      c:on("receive", function(sck, pl) print(pl) end)
-      c:send("hello world")
-      end)
-
- - -

See also

-

- net.createServer()

-

-

close()

-

Description

-

close server.

-

Syntax

-

net.server.close()

-

Parameters

-

nil

Returns

nil

Example

-
    -- create a server
-    sv=net.createServer(net.TCP, false)
-    -- close server
-    sv:close()
-
- +
    -- create a server
+    sv=net.createServer(net.TCP, false)
+    -- server listen on 80, if data received, print data to console, and send "hello world" to remote.
+    sv:listen(80,function(c)
+      c:on("receive", function(sck, pl) print(pl) end)
+      c:send("hello world")
+      end)
+

See also

- net.createServer()

+

+

close()

+

Description

+

close server.

+

Syntax

+

net.server.close()

+

Parameters

+

nil

+

Returns

+

nil

+

Example

+
    -- create a server
+    sv=net.createServer(net.TCP, false)
+    -- close server
+    sv:close()
+
+ +

See also

+

- net.createServer()

net.socket module

connect()

-

Description

+

Description

connect to remote.

-

Syntax

+

Syntax

connect(port, ip)

-

Parameters

+

Parameters

port: port number

ip: ip address in string

-

Returns

-

nil

-

See also

-

- net.socket:on()

-

-

send()

-

Description

-

send data to remote via connection.

-

Syntax

-

send(string, function(sent))

-

Parameters

-

string: data in string which will be sent to remote

-function(sent): callback function for sending string

Returns

nil

See also

- net.socket:on()

+

+

send()

+

Description

+

send data to remote via connection.

+

Syntax

+

send(string, function(sent))

+

Parameters

+

string: data in string which will be sent to remote

+function(sent): callback function for sending string

+

Returns

+

nil

+

See also

+

- net.socket:on()

on()

-

Description

+

Description

register callback function for event.

-

Syntax

+

Syntax

on(event, function cb())

-

Parameters

+

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

+

Returns

nil

-

Example

-
    sk=net.createConnection(net.TCP, false)
-    sk:on("receive", function(sck, c) print(c) end )
-    sk:connect(80,"192.168.0.66")
-    sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
-
+

Example

+
    sk=net.createConnection(net.TCP, false)
+    sk:on("receive", function(sck, c) print(c) end )
+    sk:connect(80,"192.168.0.66")
+    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()

close()

-

Description

-

close socket.

-

Syntax

-

close()

-

Parameters

-

nil

-

Returns

-

nil

-

See also

-

- net.createServer()

-

-

dns()

Description

-

get domain ip

+

close socket.

Syntax

-

dns(domain, function(net.socket, ip))

+

close()

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.

+

nil

Returns

nil

See also

- net.createServer()

+

+

dns()

+

Description

+

get domain 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.

+

Returns

+

nil

+

See also

+

- net.createServer()

i2c module

CONSTANT

i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.

i2c.setup()

-

Description

+

Description

initialize i2c.

-

Syntax

+

Syntax

i2c.setup(id, pinSDA, pinSCL, speed)

-

Parameters

+

Parameters

id = 0

pinSDA: 0~11, IO index

pinSCL: 0~11, IO index

speed: i2c.SLOW

-

Returns

-

nil

-

See also

-

- i2c.read()

-

-

i2c.start()

-

Description

-

start i2c transporting.

-

Syntax

-

i2c.start(id)

-

Parameters

-

id = 0

Returns

nil

See also

- i2c.read()

-

-

i2c.stop()

+

+

i2c.start()

Description

-

stop i2c transporting.

+

start i2c transporting.

Syntax

-

i2c.stop(id)

+

i2c.start(id)

Parameters

id = 0

Returns

nil

See also

- i2c.read()

-

-

i2c.address()

+

+

i2c.stop()

Description

-

setup i2c address and read/write mode.

+

stop i2c transporting.

Syntax

-

i2c.address(id, device_addr, direction)

+

i2c.stop(id)

Parameters

-

id=0

-device_addr: device address.

-direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode

+

id = 0

Returns

nil

See also

- i2c.read()

-

-

i2c.write()

+

+

i2c.address()

Description

-

write data to i2c, data can be multi numbers, string or lua table.

+

setup i2c address and read/write mode.

Syntax

-

i2c.write(id, data1, data2,…)

+

i2c.address(id, device_addr, direction)

Parameters

id=0

-data: data can be numbers, string or lua table.

+device_addr: device address.

+direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode

Returns

nil

-

Example

-
    i2c.write(0, "hello", "world")
-
- -

See also

- i2c.read()

+

+

i2c.write()

+

Description

+

write data to i2c, data can be multi numbers, string or lua table.

+

Syntax

+

i2c.write(id, data1, data2,…)

+

Parameters

+

id=0

+data: data can be numbers, string or lua table.

+

Returns

+

nil

+

Example

+
    i2c.write(0, "hello", "world")
+
+ +

See also

+

- i2c.read()

i2c.read()

-

Description

+

Description

read data for len bytes.

-

Syntax

+

Syntax

i2c.read(id, len)

-

Parameters

+

Parameters

id=0

len: data length

-

Returns

+

Returns

string:data received.

-

Example

-
    id=0
-    sda=1
-    scl=0
+

Example

+
    id=0
+    sda=1
+    scl=0
 
-    -- initialize i2c, set pin1 as sda, set pin0 as scl
-    i2c.setup(id,sda,scl,i2c.SLOW)
+    -- initialize i2c, set pin1 as sda, set pin0 as scl
+    i2c.setup(id,sda,scl,i2c.SLOW)
 
-    -- user defined function: read from reg_addr content of dev_addr
-    function read_reg(dev_addr, reg_addr)
-      i2c.start(id)
-      i2c.address(id, dev_addr ,i2c.TRANSMITTER)
-      i2c.write(id,reg_addr)
-      i2c.stop(id)
-      i2c.start(id)
-      i2c.address(id, dev_addr,i2c.RECEIVER)
-      c=i2c.read(id,1)
-      i2c.stop(id)
-      return c
-    end
+    -- user defined function: read from reg_addr content of dev_addr
+    function read_reg(dev_addr, reg_addr)
+      i2c.start(id)
+      i2c.address(id, dev_addr ,i2c.TRANSMITTER)
+      i2c.write(id,reg_addr)
+      i2c.stop(id)
+      i2c.start(id)
+      i2c.address(id, dev_addr,i2c.RECEIVER)
+      c=i2c.read(id,1)
+      i2c.stop(id)
+      return c
+    end
 
-    -- get content of register 0xAA of device 0x77
-    reg = read_reg(0x77, 0xAA)
-    pirnt(string.byte(reg))
-
+ -- get content of register 0xAA of device 0x77 + reg = read_reg(0x77, 0xAA) + pirnt(string.byte(reg)) + -

See also

-

- i2c.write()

\ No newline at end of file +

See also

+

- i2c.write()

+

adc module

+

CONSTANT

+

none

+

+

adc.read()

+

Description

+

read adc value of id, esp8266 has only one 10bit adc, id=0

+

Syntax

+

adc.read(id)

+

Parameters

+

id = 0

+

Returns

+

adc value

+

See also

+

-

\ No newline at end of file diff --git a/nodemcu_api_en.md b/nodemcu_api_en.md index d8f24c99..37fb253b 100644 --- a/nodemcu_api_en.md +++ b/nodemcu_api_en.md @@ -1,8 +1,12 @@ # **nodeMcu API Instruction** # [中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn) -###version 0.9.2 build 2014-11-18 +###version 0.9.2 build 2014-11-19 ###change log: +2014-11-19
+add adc module, use adc.read(0) to read adc value, no tests made.
+add wifi.sta.getap() api to wifi.sta module, to get ap list. + 2014-11-18
bug fixed: net.socket:connect() has no effect. @@ -824,6 +828,36 @@ mac address in string, for example:"18-33-44-FE-55-BB" ####See also **-** [wifi.sta.getip()](#ws_getip) + +## wifi.sta.getap() +####Description +scan and get ap list as a lua table into callback function. + +####Syntax +wifi.sta.getap(function(table)) + +####Parameters +function(table): a callback function to receive ap table when scan is done
+ this function receive a table, the key is the ssid, value is other info in format: authmode,rssi,bssid,channel + + +####Returns +nil + +####Example + +```lua + -- print ap list + function listap(t) + for k,v in pairs(t) do + print(k.." : "..v) + end + end + wifi.sta.getap(listap) +``` + +####See also +**-** [wifi.sta.getip()](#ws_getip) #wifi.ap module @@ -1728,3 +1762,23 @@ string:data received. ####See also **-** [i2c.write()](#ic_write) +#adc module +##CONSTANT +none + + +## adc.read() +####Description +read adc value of id, esp8266 has only one 10bit adc, id=0 + +####Syntax +adc.read(id) + +####Parameters +id = 0
+ +####Returns +adc value + +####See also +**-** []()