add chinese api instruction, update wiki
This commit is contained in:
parent
b67b552e39
commit
c49d438c8e
File diff suppressed because it is too large
Load Diff
|
@ -2,8 +2,8 @@
|
|||
###A lua based firmware for wifi-soc esp8266
|
||||
version 0.9.2 build 2014-11-18
|
||||
# Change log
|
||||
[change log](https://github.com/funshine/nodemcu-firmware/wiki/nodeMcu:-lua-based-interactive-firmware-for-mcu#change_log)
|
||||
|
||||
[change log](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log)<br />
|
||||
[变更日志](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log)
|
||||
# Summary
|
||||
- Easy to access wireless router
|
||||
- Based on Lua 5.1.4
|
||||
|
|
292
README_cn.md
292
README_cn.md
|
@ -1,292 +0,0 @@
|
|||
nodeMcu API说明
|
||||
=======
|
||||
version 0.1 2014-10-11
|
||||
<a id="upupup"> up </a>
|
||||
flash 错误
|
||||
----
|
||||
注意:有些模块在烧写之后启动,串口输出 ERROR in flash_read: r=。。。
|
||||
这是因为模块原来的flash内部没有擦除。
|
||||
可使用blank.bin(4k),
|
||||
重复烧入起始地址0x47000, 0x48000, 0x49000, 0x4a000扇区.
|
||||
或者生成一个512k大小的blank512k.bin, 内容为全0xFF,从0x00000开始烧入。
|
||||
烧入之后可以正常运行。
|
||||
|
||||
概述
|
||||
------
|
||||
支持一键配置
|
||||
|
||||
基于Lua 5.1.4,使用者需了解最简单的Lua语法。
|
||||
|
||||
采用事件驱动的编程模型。
|
||||
|
||||
内置 timer,pwm,i2c,net,gpio,wifi module。
|
||||
|
||||
对模块的引脚进行编号;gpio,i2c,pwm等模块需要使用引脚编号进行索引。
|
||||
|
||||
###目前的编号对应表格:
|
||||
|
||||
IO索引编号 ESP8266实际IO IO索引编号 ESP8266实际IO
|
||||
0 GPIO12 8 GPIO0
|
||||
1 GPIO13 9 GPIO2
|
||||
2 GPIO14 10 GPIO4
|
||||
3 GPIO15 11 GPIO5
|
||||
4 GPIO3
|
||||
5 GPIO1
|
||||
6 GPIO9
|
||||
7 GPIO10
|
||||
|
||||
###串口波特率
|
||||
9600
|
||||
|
||||
###固件烧写地址:
|
||||
|
||||
eagle.app.v6.flash.bin:0x00000
|
||||
eagle.app.v6.irom0text.bin:0x10000
|
||||
esp_init_data_default.bin:0x7c000
|
||||
blank.bin:0x7e000
|
||||
|
||||
第一次使用建议将blank512k.bin烧写在地址0x00000
|
||||
|
||||
node module
|
||||
------
|
||||
node.restart()
|
||||
|
||||
描述:重新启动
|
||||
|
||||
node.dsleep( us )
|
||||
|
||||
描述:深度睡眠 us 微秒,时间到之后将重新启动
|
||||
us:时间,单位微秒
|
||||
|
||||
node.chipid()
|
||||
|
||||
描述:返回芯片id
|
||||
返回:number
|
||||
|
||||
node.heap()
|
||||
|
||||
描述:返回可用内存 in bytes
|
||||
返回:系统heap剩余
|
||||
|
||||
node.format()
|
||||
|
||||
描述:格式化用户flash区
|
||||
|
||||
node.startlog( filename, noparse)
|
||||
|
||||
描述:开始记录输入
|
||||
filename:log所保存的文件名,不支持目录
|
||||
noparse:1表示lua虚拟机不对输入进行解析,0表示lua虚拟机对输入进行解析
|
||||
|
||||
node.stoplog()
|
||||
|
||||
描述:结束log
|
||||
|
||||
例子:录制log到init.lua文件,可以在系统启动之后自动调用该文件。
|
||||
|
||||
node.format()
|
||||
node.startlog("init.lua", 1)
|
||||
print("hello world")
|
||||
node.stoplog()
|
||||
|
||||
此时,文件init.lua内部将含有内容,重启之后,系统执行print("hello world")
|
||||
|
||||
node.readlog( filename)
|
||||
|
||||
描述:读取文件
|
||||
filename:log文件名,不支持目录
|
||||
返回:读取的内容,字符串形式
|
||||
|
||||
node.list()
|
||||
|
||||
描述:返回所有文件
|
||||
返回:一个包含 <文件名:文件大小> pair 的map
|
||||
|
||||
wifi module
|
||||
-----------
|
||||
[up](#upupup)
|
||||
|
||||
常量:wifi.STATION, wifi.SOFTAP, wifi.STATIONAP
|
||||
|
||||
wifi.setmode(mode)
|
||||
|
||||
描述:设置wifi的工作模式
|
||||
mode:取值:wifi.STATION, wifi.SOFTAP或wifi.STATIONAP
|
||||
返回设置之后的当前mode
|
||||
|
||||
wifi.getmode()
|
||||
|
||||
描述:获取wifi的工作模式
|
||||
返回:wifi.STATION, wifi.SOFTAP或wifi.STATIONAP
|
||||
|
||||
wifi.startconfig( channel, function succeed_callback )
|
||||
|
||||
描述:开始智能配置,若成功自动设置ssid和pwd并退出
|
||||
channel:1~13,起始搜索信道。若不指定,默认为6,每个信道搜索20秒
|
||||
succeed_callback:配置成功后的回调函数,将在获取密码正确并连接上ap之后调用
|
||||
|
||||
wifi.stopconfig()
|
||||
|
||||
描述:中断智能配置
|
||||
|
||||
wifi.station module
|
||||
-----------------
|
||||
wifi.station.setconfig(ssid, password)
|
||||
|
||||
描述:设置station模式下的ssid和password
|
||||
ssid:字符串形式,长度小于32
|
||||
password:字符串形式,长度小于64
|
||||
|
||||
wifi.station.connect()
|
||||
|
||||
描述:station模式下连接至ap
|
||||
|
||||
wifi.station.disconnect()
|
||||
|
||||
描述:station模式下断开与ap的连接
|
||||
|
||||
wifi.station.autoconnect(auto)
|
||||
|
||||
描述:station模式下设置自动连接至ap
|
||||
auto:0表示设置为不自动连,1表示设置为自动连接
|
||||
|
||||
wifi.station.getip()
|
||||
|
||||
描述:station模式下获取ip
|
||||
返回:字符串形式的ip,如"192.168.0.2"
|
||||
|
||||
wifi.station.getmac()
|
||||
|
||||
描述:station模式下获取mac
|
||||
返回:字符串形式的mac,如"18-33-44-FE-55-BB"
|
||||
|
||||
wifi.ap module
|
||||
---------------
|
||||
wifi.ap.setconfig(cfg)
|
||||
|
||||
描述:设置station模式下的ssid和password
|
||||
cfg:设置需要的map
|
||||
|
||||
例子:
|
||||
|
||||
cfg={}
|
||||
cfg.ssid="myssid"
|
||||
cfg.pwd="mypwd"
|
||||
wifi.ap.setconfig(cfg)
|
||||
|
||||
wifi.ap.getip()
|
||||
|
||||
描述:ap模式下获取ip
|
||||
返回:字符串形式的ip,如"192.168.0.2"
|
||||
|
||||
wifi.ap.getmac()
|
||||
|
||||
描述:ap模式下获取mac
|
||||
返回:字符串形式的mac,如"1A-33-44-FE-55-BB"
|
||||
|
||||
gpio module
|
||||
-----------
|
||||
常量:gpio.OUTPUT, gpio.INPUT, gpio.HIGH, gpio.LOW
|
||||
|
||||
gpio.mode( pin, mode)
|
||||
|
||||
描述:设置对应pin的输入输出模式,将该pin初始化为gpio模式。
|
||||
pin:0~11,IO索引编号
|
||||
mode:gpio.OUTPUT或者gpio.INPUT
|
||||
|
||||
gpio.read(pin)
|
||||
|
||||
描述:读取对应pin的值
|
||||
pin:0~11,IO索引编号
|
||||
返回:0表示低,1表示高
|
||||
|
||||
gpio.write(pin, level)
|
||||
|
||||
描述:设置对应pin的值
|
||||
pin:0~11,IO索引编号
|
||||
level:gpio.HIGH或者gpio.LOW
|
||||
|
||||
例子:
|
||||
|
||||
pin=1
|
||||
gpio.mode(pin, gpio.OUTPUT)
|
||||
gpio.write(pin, gpio.HIGH)
|
||||
|
||||
将索引1的pin设置为GPIO模式,并设置为高电平。
|
||||
|
||||
net module
|
||||
---------------
|
||||
常量:net.TCP, net.UDP
|
||||
|
||||
net.createServer(type)
|
||||
|
||||
描述:建立一个服务器
|
||||
type:net.TCP或 net.UDP
|
||||
返回:net.server子模块
|
||||
|
||||
net.createConnection(type)
|
||||
|
||||
描述:建立一个客户端
|
||||
type:net.TCP或 net.UDP
|
||||
返回:net.socket子模块
|
||||
|
||||
net.server module
|
||||
-------------
|
||||
listen(port,[ip],function(net.socket))
|
||||
|
||||
描述:监听某端口
|
||||
port:端口号
|
||||
ip:可忽略,ip字符串
|
||||
function(net.socket): 回调函数,当有连接建立的时候,作为参数传给回调函数。
|
||||
|
||||
例子:
|
||||
|
||||
sv=net.createServer(net.TCP, false)
|
||||
sv:listen(80,function(c)
|
||||
c:on("receive", function(sck, pl) print(pl) end)
|
||||
c:send("hello world")
|
||||
end)
|
||||
|
||||
close()
|
||||
|
||||
描述:关闭服务器
|
||||
|
||||
net.socket module
|
||||
-------
|
||||
connect(port, ip)
|
||||
|
||||
描述:连接到某ip和端口
|
||||
port:端口号
|
||||
ip:ip字符串
|
||||
|
||||
send( string, function(sent) )
|
||||
|
||||
描述:向连接发送数据
|
||||
string:需要发送的数据字符串
|
||||
|
||||
on(event, function cb())
|
||||
|
||||
描述:注册事件的回调函数
|
||||
event:字符串
|
||||
可为:"connection","reconnection","disconnection","receive","sent"
|
||||
function cb(net.socket, [string]):回调函数。第一个参数为socket连接。
|
||||
若event为"receive", 第二个参数为接收到数据,字符串形式。
|
||||
|
||||
例子:
|
||||
|
||||
sk=net.createConnection(net.TCP, false)
|
||||
sk:on("receive", function(sck, pl) print(pl) end )
|
||||
sk:connect(80,"115.239.210.27")
|
||||
sk:send("GET / HTTP/1.1\r\nHost: 115.239.210.27\r\n
|
||||
Connection: keep-alive\r\nAccept: */*\r\n\r\n")
|
||||
|
||||
close()
|
||||
|
||||
描述:关闭socket
|
||||
|
||||
dns(domain, function cb(net.socket, ip) )
|
||||
|
||||
描述:获取domain的ip
|
||||
domain:字符串
|
||||
function cb(net.socket, ip):回调函数。
|
||||
第一个参数为socket连接本身, 第二个为获取的ip, 字符串形式。
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1014,7 +1014,73 @@ body .markdown-body
|
|||
page-break-after: avoid;
|
||||
}
|
||||
}
|
||||
</style><title>API</title></head><body><article class="markdown-body"><h1 id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
|
||||
</style><style>.codehilite pre .hll { background-color: #f8eec7 }
|
||||
.codehilite pre { background: #ffffff; color: #333333 }
|
||||
.codehilite pre .c { color: #999988; font-style: italic } /* Comment */
|
||||
.codehilite pre .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
||||
.codehilite pre .k { font-weight: bold } /* Keyword */
|
||||
.codehilite pre .n { color: #333333 } /* Name */
|
||||
.codehilite pre .o { font-weight: bold } /* Operator */
|
||||
.codehilite pre .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
||||
.codehilite pre .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
|
||||
.codehilite pre .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
||||
.codehilite pre .cs { color: #999988; font-style: italic } /* Comment.Special */
|
||||
.codehilite pre .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
||||
.codehilite pre .ge { font-style: italic } /* Generic.Emph */
|
||||
.codehilite pre .gr { color: #aa0000 } /* Generic.Error */
|
||||
.codehilite pre .gh { color: #999999 } /* Generic.Heading */
|
||||
.codehilite pre .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
||||
.codehilite pre .go { color: #888888 } /* Generic.Output */
|
||||
.codehilite pre .gp { color: #555555 } /* Generic.Prompt */
|
||||
.codehilite pre .gs { font-weight: bold } /* Generic.Strong */
|
||||
.codehilite pre .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.codehilite pre .gt { color: #aa0000 } /* Generic.Traceback */
|
||||
.codehilite pre .kc { font-weight: bold } /* Keyword.Constant */
|
||||
.codehilite pre .kd { font-weight: bold } /* Keyword.Declaration */
|
||||
.codehilite pre .kn { font-weight: bold } /* Keyword.Namespace */
|
||||
.codehilite pre .kp { font-weight: bold } /* Keyword.Pseudo */
|
||||
.codehilite pre .kr { font-weight: bold } /* Keyword.Reserved */
|
||||
.codehilite pre .kt { font-weight: bold } /* Keyword.Type */
|
||||
.codehilite pre .m { color: #945277 } /* Literal.Number */
|
||||
.codehilite pre .s { color: #df5000 } /* Literal.String */
|
||||
.codehilite pre .na { color: #008080 } /* Name.Attribute */
|
||||
.codehilite pre .nb { color: #0086b3 } /* Name.Builtin */
|
||||
.codehilite pre .nc { color: #445588; font-weight: bold } /* Name.Class */
|
||||
.codehilite pre .no { color: #094e99 } /* Name.Constant */
|
||||
.codehilite pre .nd { color: #333333 } /* Name.Decorator */
|
||||
.codehilite pre .ni { color: #800080 } /* Name.Entity */
|
||||
.codehilite pre .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
||||
.codehilite pre .nf { color: #945277; font-weight: bold } /* Name.Function */
|
||||
.codehilite pre .nl { color: #333333 } /* Name.Label */
|
||||
.codehilite pre .nn { color: #555555 } /* Name.Namespace */
|
||||
.codehilite pre .nx { color: #333333 } /* Name.Other */
|
||||
.codehilite pre .py { color: #333333 } /* Name.Property */
|
||||
.codehilite pre .nt { color: #000080 } /* Name.Tag */
|
||||
.codehilite pre .nv { color: #008080 } /* Name.Variable */
|
||||
.codehilite pre .ow { font-weight: bold } /* Operator.Word */
|
||||
.codehilite pre .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
.codehilite pre .mb { color: #945277 } /* Literal.Number.Bin */
|
||||
.codehilite pre .mf { color: #945277 } /* Literal.Number.Float */
|
||||
.codehilite pre .mh { color: #945277 } /* Literal.Number.Hex */
|
||||
.codehilite pre .mi { color: #945277 } /* Literal.Number.Integer */
|
||||
.codehilite pre .mo { color: #945277 } /* Literal.Number.Oct */
|
||||
.codehilite pre .sb { color: #df5000 } /* Literal.String.Backtick */
|
||||
.codehilite pre .sc { color: #df5000 } /* Literal.String.Char */
|
||||
.codehilite pre .sd { color: #df5000 } /* Literal.String.Doc */
|
||||
.codehilite pre .s2 { color: #df5000 } /* Literal.String.Double */
|
||||
.codehilite pre .se { color: #df5000 } /* Literal.String.Escape */
|
||||
.codehilite pre .sh { color: #df5000 } /* Literal.String.Heredoc */
|
||||
.codehilite pre .si { color: #df5000 } /* Literal.String.Interpol */
|
||||
.codehilite pre .sx { color: #df5000 } /* Literal.String.Other */
|
||||
.codehilite pre .sr { color: #017936 } /* Literal.String.Regex */
|
||||
.codehilite pre .s1 { color: #df5000 } /* Literal.String.Single */
|
||||
.codehilite pre .ss { color: #8b467f } /* Literal.String.Symbol */
|
||||
.codehilite pre .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
||||
.codehilite pre .vc { color: #008080 } /* Name.Variable.Class */
|
||||
.codehilite pre .vg { color: #008080 } /* Name.Variable.Global */
|
||||
.codehilite pre .vi { color: #008080 } /* Name.Variable.Instance */
|
||||
.codehilite pre .il { color: #945277 } /* Literal.Number.Integer.Long */</style><title>nodemcu_api_en</title></head><body><article class="markdown-body"><h1 id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
|
||||
<p><a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn">中文版本</a></p>
|
||||
<h3 id="version-092-build-2014-11-18"><a name="user-content-version-092-build-2014-11-18" href="#version-092-build-2014-11-18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>version 0.9.2 build 2014-11-18</h3>
|
||||
<p><a id="change_log"></a></p>
|
||||
<h3 id="change-log"><a name="user-content-change-log" href="#change-log" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>change log:</h3>
|
||||
|
@ -1096,8 +1162,9 @@ key is triged only when key is released<br /></p>
|
|||
<h4 id="returns"><a name="user-content-returns" href="#returns" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example"><a name="user-content-example" href="#example" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> node.restart();
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">node</span><span class="p">.</span><span class="n">restart</span><span class="p">();</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also"><a name="user-content-see-also" href="#see-also" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1113,8 +1180,9 @@ key is triged only when key is released<br /></p>
|
|||
<h4 id="returns_1"><a name="user-content-returns_1" href="#returns_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_1"><a name="user-content-example_1" href="#example_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> node.dsleep(us);
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">node</span><span class="p">.</span><span class="n">dsleep</span><span class="p">(</span><span class="n">us</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_1"><a name="user-content-see-also_1" href="#see-also_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1129,8 +1197,9 @@ key is triged only when key is released<br /></p>
|
|||
<h4 id="returns_2"><a name="user-content-returns_2" href="#returns_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>number:chip ID</p>
|
||||
<h4 id="example_2"><a name="user-content-example_2" href="#example_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> id = node.chipid();
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">id</span> <span class="o">=</span> <span class="n">node</span><span class="p">.</span><span class="n">chipid</span><span class="p">();</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_2"><a name="user-content-see-also_2" href="#see-also_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1145,8 +1214,9 @@ key is triged only when key is released<br /></p>
|
|||
<h4 id="returns_3"><a name="user-content-returns_3" href="#returns_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>number: system heap size left in bytes</p>
|
||||
<h4 id="example_3"><a name="user-content-example_3" href="#example_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> heap_size = node.heap();
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">heap_size</span> <span class="o">=</span> <span class="n">node</span><span class="p">.</span><span class="n">heap</span><span class="p">();</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_3"><a name="user-content-see-also_3" href="#see-also_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1163,8 +1233,9 @@ Default function: long: change LED blinking rate, short: reset chip</p>
|
|||
<h4 id="returns_4"><a name="user-content-returns_4" href="#returns_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_4"><a name="user-content-example_4" href="#example_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> node.key("long", function(){print('hello world')})
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">node</span><span class="p">.</span><span class="n">key</span><span class="p">(</span><span class="s2">"</span><span class="s">long"</span><span class="p">,</span> <span class="k">function</span><span class="p">(){</span><span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="s">hello world'</span><span class="p">)})</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_4"><a name="user-content-see-also_4" href="#see-also_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1180,9 +1251,10 @@ High: LED off time. Unit: milliseconds, time resolution: 80~100ms</p>
|
|||
<h4 id="returns_5"><a name="user-content-returns_5" href="#returns_5" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_5"><a name="user-content-example_5" href="#example_5" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- turn led on forever.
|
||||
node.led(0);
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- turn led on forever.</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">led</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_5"><a name="user-content-see-also_5" href="#see-also_5" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1198,9 +1270,10 @@ same as pcall(loadstring(str)) but support multi seperated line.</p>
|
|||
<h4 id="returns_6"><a name="user-content-returns_6" href="#returns_6" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_6"><a name="user-content-example_6" href="#example_6" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- never use node.input() in console. no effect.
|
||||
sk:on("receive", function(conn, payload) node.input(payload) end)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- never use node.input() in console. no effect.</span>
|
||||
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span> <span class="n">payload</span><span class="p">)</span> <span class="n">node</span><span class="p">.</span><span class="n">input</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span> <span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_6"><a name="user-content-see-also_6" href="#see-also_6" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1216,33 +1289,35 @@ serial_debug: 1 output also show in serial. 0: no serial output.</p>
|
|||
<h4 id="returns_7"><a name="user-content-returns_7" href="#returns_7" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_7"><a name="user-content-example_7" href="#example_7" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> 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.
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="k">function</span> <span class="nf">tonet</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="n">sk</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="c1">-- print(str) WRONG!!! never ever print something in this function</span>
|
||||
<span class="c1">-- because this will cause a recursive function call!!!</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">ouput</span><span class="p">(</span><span class="n">tonet</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="c1">-- serial also get the lua output.</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<div class="codehilite"><pre> <span class="c1">-- a simple telnet server</span>
|
||||
<span class="n">s</span><span class="o">=</span><span class="n">net</span><span class="p">.</span><span class="n">createServer</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">)</span>
|
||||
<span class="n">s</span><span class="p">:</span><span class="n">listen</span><span class="p">(</span><span class="mi">2323</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
|
||||
<span class="n">con_std</span> <span class="o">=</span> <span class="n">c</span>
|
||||
<span class="k">function</span> <span class="nf">s_output</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="n">con_std</span><span class="o">~=</span><span class="kc">nil</span><span class="p">)</span>
|
||||
<span class="k">then</span> <span class="n">con_std</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">output</span><span class="p">(</span><span class="n">s_output</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="c1">-- re-direct output to function s_ouput.</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">,</span><span class="n">l</span><span class="p">)</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">input</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="c1">-- works like pcall(loadstring(l)) but support multiple separate line</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">disconnection"</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
|
||||
<span class="n">con_std</span> <span class="o">=</span> <span class="kc">nil</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">output</span><span class="p">(</span><span class="kc">nil</span><span class="p">)</span> <span class="c1">-- un-regist the redirect output function, output goes to serial</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> -- a simple telnet server
|
||||
s=net.createServer(net.TCP)
|
||||
s:listen(23,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)
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_7"><a name="user-content-see-also_7" href="#see-also_7" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1258,9 +1333,10 @@ serial_debug: 1 output also show in serial. 0: no serial output.</p>
|
|||
<h4 id="returns_8"><a name="user-content-returns_8" href="#returns_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_8"><a name="user-content-example_8" href="#example_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- remove "foo.lua" from file system.
|
||||
file.remove("foo.lua")
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- remove "foo.lua" from file system.</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">"</span><span class="s">foo.lua"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_8"><a name="user-content-see-also_8" href="#see-also_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1283,11 +1359,12 @@ mode:<br /><br />
|
|||
<h4 id="returns_9"><a name="user-content-returns_9" href="#returns_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_9"><a name="user-content-example_9" href="#example_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- open 'init.lua', print the first line.
|
||||
file.open("init.lua", "r")
|
||||
print(file.readline())
|
||||
file.close()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua', print the first line.</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">r"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="n">readline</span><span class="p">())</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_9"><a name="user-content-see-also_9" href="#see-also_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_close">file.close()</a><br /><br />
|
||||
|
@ -1303,11 +1380,12 @@ mode:<br /><br />
|
|||
<h4 id="returns_10"><a name="user-content-returns_10" href="#returns_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_10"><a name="user-content-example_10" href="#example_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- open 'init.lua', print the first line.
|
||||
file.open("init.lua", "r")
|
||||
print(file.readline())
|
||||
file.close()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua', print the first line.</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">r"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="n">readline</span><span class="p">())</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_10"><a name="user-content-see-also_10" href="#see-also_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1324,11 +1402,12 @@ mode:<br /><br />
|
|||
<p>file content in string, line by line, include EOL(‘\n’)<br /><br />
|
||||
return nil when EOF.</p>
|
||||
<h4 id="example_11"><a name="user-content-example_11" href="#example_11" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print the first line of 'init.lua'
|
||||
file.open("init.lua", "r")
|
||||
print(file.readline())
|
||||
file.close()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- print the first line of 'init.lua'</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">r"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="n">readline</span><span class="p">())</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_11"><a name="user-content-see-also_11" href="#see-also_11" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1345,12 +1424,13 @@ return nil when EOF.</p>
|
|||
<p>true: write ok.<br />
|
||||
nil: there is error</p>
|
||||
<h4 id="example_12"><a name="user-content-example_12" href="#example_12" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua' in 'a+' mode</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">a+"</span><span class="p">)</span>
|
||||
<span class="c1">-- write 'foo bar' to the end of the file</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s1">'</span><span class="s">foo bar'</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_12"><a name="user-content-see-also_12" href="#see-also_12" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1367,12 +1447,13 @@ nil: there is error</p>
|
|||
<p>true: write ok.<br />
|
||||
nil: there is error</p>
|
||||
<h4 id="example_13"><a name="user-content-example_13" href="#example_13" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua' in 'a+' mode</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">a+"</span><span class="p">)</span>
|
||||
<span class="c1">-- write 'foo bar' to the end of the file</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="s">foo bar'</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_13"><a name="user-content-see-also_13" href="#see-also_13" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1388,13 +1469,14 @@ nil: there is error</p>
|
|||
<h4 id="returns_14"><a name="user-content-returns_14" href="#returns_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_14"><a name="user-content-example_14" href="#example_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua' in 'a+' mode</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">a+"</span><span class="p">)</span>
|
||||
<span class="c1">-- write 'foo bar' to the end of the file</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="s">foo bar'</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_14"><a name="user-content-see-also_14" href="#see-also_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1415,15 +1497,16 @@ offset: default 0</p>
|
|||
<p>success: returns the final file position<br /><br />
|
||||
fail: returns nil</p>
|
||||
<h4 id="example_15"><a name="user-content-example_15" href="#example_15" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- open 'init.lua' in 'a+' mode</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span> <span class="s2">"</span><span class="s">a+"</span><span class="p">)</span>
|
||||
<span class="c1">-- write 'foo bar' to the end of the file</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'</span><span class="s">foo bar'</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">seek</span><span class="p">(</span><span class="s2">"</span><span class="s">set"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">file</span><span class="p">.</span><span class="n">readline</span><span class="p">())</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_15"><a name="user-content-see-also_15" href="#see-also_15" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
|
||||
|
@ -1439,11 +1522,12 @@ fail: returns nil</p>
|
|||
<h4 id="returns_16"><a name="user-content-returns_16" href="#returns_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>a lua table which contains the {file name: file size} pairs</p>
|
||||
<h4 id="example_16"><a name="user-content-example_16" href="#example_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> l = file.list();
|
||||
for k,v in l do
|
||||
print("name:"..k..", size:"..v)
|
||||
end
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">l</span> <span class="o">=</span> <span class="n">file</span><span class="p">.</span><span class="n">list</span><span class="p">();</span>
|
||||
<span class="k">for</span> <span class="n">k</span><span class="p">,</span><span class="n">v</span> <span class="k">in</span> <span class="n">l</span> <span class="k">do</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="s">name:"</span><span class="o">..</span><span class="n">k</span><span class="o">..</span><span class="s2">"</span><span class="s">, size:"</span><span class="o">..</span><span class="n">v</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_16"><a name="user-content-see-also_16" href="#see-also_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#fl_remove">file.remove()</a></p>
|
||||
|
@ -1461,8 +1545,9 @@ fail: returns nil</p>
|
|||
<h4 id="returns_17"><a name="user-content-returns_17" href="#returns_17" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>current mode after setup</p>
|
||||
<h4 id="example_17"><a name="user-content-example_17" href="#example_17" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.setmode(wifi.STATION)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">setmode</span><span class="p">(</span><span class="n">wifi</span><span class="p">.</span><span class="n">STATION</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_17"><a name="user-content-see-also_17" href="#see-also_17" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wf_getmode">wifi.getmode()</a></p>
|
||||
|
@ -1477,8 +1562,9 @@ fail: returns nil</p>
|
|||
<h4 id="returns_18"><a name="user-content-returns_18" href="#returns_18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>wifi operation mode</p>
|
||||
<h4 id="example_18"><a name="user-content-example_18" href="#example_18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> print(wifi.getmode())
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="nb">print</span><span class="p">(</span><span class="n">wifi</span><span class="p">.</span><span class="n">getmode</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_18"><a name="user-content-see-also_18" href="#see-also_18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wf_setmode">wifi.setmode()</a></p>
|
||||
|
@ -1494,8 +1580,9 @@ succeed_callback: callback function called after configuration, which is called
|
|||
<h4 id="returns_19"><a name="user-content-returns_19" href="#returns_19" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_19"><a name="user-content-example_19" href="#example_19" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.startsmart(6, cb())
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">startsmart</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="n">cb</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_19"><a name="user-content-see-also_19" href="#see-also_19" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wf_stopsmart">wifi.stopsmart()</a></p>
|
||||
|
@ -1510,8 +1597,9 @@ succeed_callback: callback function called after configuration, which is called
|
|||
<h4 id="returns_20"><a name="user-content-returns_20" href="#returns_20" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_20"><a name="user-content-example_20" href="#example_20" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.stopsmart()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">stopsmart</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_20"><a name="user-content-see-also_20" href="#see-also_20" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wf_startsmart">wifi.startsmart()</a></p>
|
||||
|
@ -1528,8 +1616,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_21"><a name="user-content-returns_21" href="#returns_21" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_21"><a name="user-content-example_21" href="#example_21" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.sta.config("myssid","mypassword")
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">config</span><span class="p">(</span><span class="s2">"</span><span class="s">myssid"</span><span class="p">,</span><span class="s2">"</span><span class="s">mypassword"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_21"><a name="user-content-see-also_21" href="#see-also_21" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_connect">wifi.sta.connect()</a><br /><br />
|
||||
|
@ -1545,8 +1634,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_22"><a name="user-content-returns_22" href="#returns_22" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_22"><a name="user-content-example_22" href="#example_22" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.sta.connect()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">connect</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_22"><a name="user-content-see-also_22" href="#see-also_22" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_disconnect">wifi.sta.disconnect()</a><br /><br />
|
||||
|
@ -1562,8 +1652,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_23"><a name="user-content-returns_23" href="#returns_23" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_23"><a name="user-content-example_23" href="#example_23" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.sta.disconnect()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">disconnect</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_23"><a name="user-content-see-also_23" href="#see-also_23" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
|
||||
|
@ -1579,8 +1670,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_24"><a name="user-content-returns_24" href="#returns_24" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_24"><a name="user-content-example_24" href="#example_24" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.sta.autoconnect()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">autoconnect</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_24"><a name="user-content-see-also_24" href="#see-also_24" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
|
||||
|
@ -1597,9 +1689,10 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_25"><a name="user-content-returns_25" href="#returns_25" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>ip address in string, for example:”192.168.0.111”</p>
|
||||
<h4 id="example_25"><a name="user-content-example_25" href="#example_25" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print current ip
|
||||
print(wifi.sta.getip())
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- print current ip</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">getip</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_25"><a name="user-content-see-also_25" href="#see-also_25" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_getmac">wifi.sta.getmac()</a></p>
|
||||
|
@ -1614,9 +1707,10 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_26"><a name="user-content-returns_26" href="#returns_26" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>mac address in string, for example:”18-33-44-FE-55-BB”</p>
|
||||
<h4 id="example_26"><a name="user-content-example_26" href="#example_26" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print current mac address
|
||||
print(wifi.sta.getmac())
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- print current mac address</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">getmac</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_26"><a name="user-content-see-also_26" href="#see-also_26" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ws_getip">wifi.sta.getip()</a></p>
|
||||
|
@ -1630,17 +1724,19 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="parameters_27"><a name="user-content-parameters_27" href="#parameters_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
|
||||
<p>cfg: lua table to setup ap.</p>
|
||||
<h4 id="example_27"><a name="user-content-example_27" href="#example_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example:</h4>
|
||||
<pre><code class="lua"> cfg={}
|
||||
cfg.ssid="myssid"
|
||||
cfg.pwd="mypwd"
|
||||
wifi.ap.setconfig(cfg)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">cfg</span><span class="o">=</span><span class="p">{}</span>
|
||||
<span class="n">cfg</span><span class="p">.</span><span class="n">ssid</span><span class="o">=</span><span class="s2">"</span><span class="s">myssid"</span>
|
||||
<span class="n">cfg</span><span class="p">.</span><span class="n">pwd</span><span class="o">=</span><span class="s2">"</span><span class="s">mypwd"</span>
|
||||
<span class="n">wifi</span><span class="p">.</span><span class="n">ap</span><span class="p">.</span><span class="n">setconfig</span><span class="p">(</span><span class="n">cfg</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="returns_27"><a name="user-content-returns_27" href="#returns_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_28"><a name="user-content-example_28" href="#example_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.ap.config(ssid, 'password')
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">ap</span><span class="p">.</span><span class="n">config</span><span class="p">(</span><span class="n">ssid</span><span class="p">,</span> <span class="s1">'</span><span class="s">password'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_27"><a name="user-content-see-also_27" href="#see-also_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href=""></a></p>
|
||||
|
@ -1655,8 +1751,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_28"><a name="user-content-returns_28" href="#returns_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>ip address in string, for example:”192.168.0.111”</p>
|
||||
<h4 id="example_29"><a name="user-content-example_29" href="#example_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.ap.getip()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">ap</span><span class="p">.</span><span class="n">getip</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_28"><a name="user-content-see-also_28" href="#see-also_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wa_getmac">wifi.ap.getmac()</a></p>
|
||||
|
@ -1671,8 +1768,9 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_29"><a name="user-content-returns_29" href="#returns_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>mac address in string, for example:”1A-33-44-FE-55-BB”</p>
|
||||
<h4 id="example_30"><a name="user-content-example_30" href="#example_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> wifi.ap.getmac()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">ap</span><span class="p">.</span><span class="n">getmac</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_29"><a name="user-content-see-also_29" href="#see-also_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#wa_getip">wifi.ap.getip()</a></p>
|
||||
|
@ -1688,9 +1786,10 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_30"><a name="user-content-returns_30" href="#returns_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_31"><a name="user-content-example_31" href="#example_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- delay 100us
|
||||
tmr.delay(100)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- delay 100us</span>
|
||||
<span class="n">tmr</span><span class="p">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_30"><a name="user-content-see-also_30" href="#see-also_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
|
||||
|
@ -1705,9 +1804,10 @@ password: string which is less than 64 bytes.</p>
|
|||
<h4 id="returns_31"><a name="user-content-returns_31" href="#returns_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>uint32: value of counter</p>
|
||||
<h4 id="example_32"><a name="user-content-example_32" href="#example_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print current value of counter
|
||||
print(tmr.now())
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- print current value of counter</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">tmr</span><span class="p">.</span><span class="n">now</span><span class="p">())</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_31"><a name="user-content-see-also_31" href="#see-also_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#tm_delay">tmr.delay()</a></p>
|
||||
|
@ -1724,9 +1824,10 @@ function do(): callback function for alarm timed out</p>
|
|||
<h4 id="returns_32"><a name="user-content-returns_32" href="#returns_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_33"><a name="user-content-example_33" href="#example_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print "hello world" every 1000ms
|
||||
tmr.alarm(1000, 1, function() print("hello world") end )
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- print "hello world" every 1000ms</span>
|
||||
<span class="n">tmr</span><span class="p">.</span><span class="n">alarm</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="k">function</span><span class="p">()</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="s">hello world"</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_32"><a name="user-content-see-also_32" href="#see-also_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
|
||||
|
@ -1742,14 +1843,15 @@ function do(): callback function for alarm timed out</p>
|
|||
<h4 id="returns_33"><a name="user-content-returns_33" href="#returns_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_34"><a name="user-content-example_34" href="#example_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- print "hello world" every 1000ms
|
||||
tmr.alarm(1000, 1, function() print("hello world") end )
|
||||
<div class="codehilite"><pre> <span class="c1">-- print "hello world" every 1000ms</span>
|
||||
<span class="n">tmr</span><span class="p">.</span><span class="n">alarm</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="k">function</span><span class="p">()</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="s">hello world"</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span>
|
||||
|
||||
-- something else
|
||||
<span class="c1">-- something else</span>
|
||||
|
||||
<span class="c1">-- stop alarm</span>
|
||||
<span class="n">tmr</span><span class="p">.</span><span class="n">stop</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
-- stop alarm
|
||||
tmr.stop()
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_33"><a name="user-content-see-also_33" href="#see-also_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
|
||||
|
@ -1768,10 +1870,10 @@ mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)</p>
|
|||
<h4 id="returns_34"><a name="user-content-returns_34" href="#returns_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_35"><a name="user-content-example_35" href="#example_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- set gpio 0 as output.
|
||||
gpio.mode(0, gpio.OUTPUT)
|
||||
<div class="codehilite"><pre> <span class="c1">-- set gpio 0 as output.</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">mode</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">gpio</span><span class="p">.</span><span class="n">OUTPUT</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_34"><a name="user-content-see-also_34" href="#see-also_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#io_read">gpio.read()</a></p>
|
||||
|
@ -1786,9 +1888,10 @@ mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)</p>
|
|||
<h4 id="returns_35"><a name="user-content-returns_35" href="#returns_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>number:0 - low, 1 - high</p>
|
||||
<h4 id="example_36"><a name="user-content-example_36" href="#example_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- read value of gpio 0.
|
||||
gpio.read(0)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- read value of gpio 0.</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_35"><a name="user-content-see-also_35" href="#see-also_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a></p>
|
||||
|
@ -1804,11 +1907,12 @@ level: gpio.HIGH or gpio.LOW</p>
|
|||
<h4 id="returns_36"><a name="user-content-returns_36" href="#returns_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_37"><a name="user-content-example_37" href="#example_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- set pin index 1 to GPIO mode, and set the pin to high.</span>
|
||||
<span class="n">pin</span><span class="o">=</span><span class="mi">1</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">mode</span><span class="p">(</span><span class="n">pin</span><span class="p">,</span> <span class="n">gpio</span><span class="p">.</span><span class="n">OUTPUT</span><span class="p">)</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">pin</span><span class="p">,</span> <span class="n">gpio</span><span class="p">.</span><span class="n">HIGH</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_36"><a name="user-content-see-also_36" href="#see-also_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
|
||||
|
@ -1826,19 +1930,19 @@ function(level): callback function when triggered. The gpio level is the param.
|
|||
<h4 id="returns_37"><a name="user-content-returns_37" href="#returns_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_38"><a name="user-content-example_38" href="#example_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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)
|
||||
<div class="codehilite"><pre> <span class="c1">-- use pin 0 as the input pulse width counter</span>
|
||||
<span class="n">pulse0</span> <span class="o">=</span> <span class="mi">0</span>
|
||||
<span class="n">du</span> <span class="o">=</span> <span class="mi">0</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">mode</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">gpio</span><span class="p">.</span><span class="n">INT</span><span class="p">)</span>
|
||||
<span class="k">function</span> <span class="nf">pin0cb</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
|
||||
<span class="n">du</span> <span class="o">=</span> <span class="n">tmr</span><span class="p">.</span><span class="n">now</span><span class="p">()</span> <span class="err">–</span> <span class="n">pulse0</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">du</span><span class="p">)</span>
|
||||
<span class="n">pulse0</span> <span class="o">=</span> <span class="n">tmr</span><span class="p">.</span><span class="n">now</span><span class="p">()</span>
|
||||
<span class="k">if</span> <span class="n">level</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">then</span> <span class="n">gpio</span><span class="p">.</span><span class="n">trig</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">"</span><span class="s">down "</span><span class="p">)</span> <span class="k">else</span> <span class="n">gpio</span><span class="p">.</span><span class="n">trig</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">"</span><span class="s">up "</span><span class="p">)</span> <span class="k">end</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">trig</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">"</span><span class="s">down "</span><span class="p">,</span><span class="n">pin0cb</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_37"><a name="user-content-see-also_37" href="#see-also_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
|
||||
|
@ -1857,9 +1961,10 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_38"><a name="user-content-returns_38" href="#returns_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_39"><a name="user-content-example_39" href="#example_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.
|
||||
pwm.setup(0, 100, 50)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">50</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_38"><a name="user-content-see-also_38" href="#see-also_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
|
||||
|
@ -1874,8 +1979,9 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_39"><a name="user-content-returns_39" href="#returns_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_40"><a name="user-content-example_40" href="#example_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> pwm.close(0)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">pwm</span><span class="p">.</span><span class="n">close</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_39"><a name="user-content-see-also_39" href="#see-also_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
|
||||
|
@ -1890,8 +1996,9 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_40"><a name="user-content-returns_40" href="#returns_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_41"><a name="user-content-example_41" href="#example_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> pwm.start(0)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_40"><a name="user-content-see-also_40" href="#see-also_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_stop">pwm.stop()</a></p>
|
||||
|
@ -1906,8 +2013,9 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_41"><a name="user-content-returns_41" href="#returns_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_42"><a name="user-content-example_42" href="#example_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> pwm.stop(0)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">pwm</span><span class="p">.</span><span class="n">stop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_41"><a name="user-content-see-also_41" href="#see-also_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
|
||||
|
@ -1924,8 +2032,9 @@ clock: 1~500, pwm frequency.</p>
|
|||
<h4 id="returns_42"><a name="user-content-returns_42" href="#returns_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_43"><a name="user-content-example_43" href="#example_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> pwm.setclock(0, 100)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">pwm</span><span class="p">.</span><span class="n">setclock</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_42"><a name="user-content-see-also_42" href="#see-also_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_getclock">pwm.getclock()</a></p>
|
||||
|
@ -1940,8 +2049,9 @@ clock: 1~500, pwm frequency.</p>
|
|||
<h4 id="returns_43"><a name="user-content-returns_43" href="#returns_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>number:pwm frequency of pin</p>
|
||||
<h4 id="example_44"><a name="user-content-example_44" href="#example_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> print(pwm.getclock(0))
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="nb">print</span><span class="p">(</span><span class="n">pwm</span><span class="p">.</span><span class="n">getclock</span><span class="p">(</span><span class="mi">0</span><span class="p">))</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_43"><a name="user-content-see-also_43" href="#see-also_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_setclock">pwm.setclock()</a></p>
|
||||
|
@ -1957,8 +2067,9 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_44"><a name="user-content-returns_44" href="#returns_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_45"><a name="user-content-example_45" href="#example_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> pwm.setduty(0, 50)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">pwm</span><span class="p">.</span><span class="n">setduty</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">50</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_44"><a name="user-content-see-also_44" href="#see-also_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_getduty">pwm.getduty()</a></p>
|
||||
|
@ -1973,24 +2084,24 @@ duty: 0~100, pwm duty cycle in percentage</p>
|
|||
<h4 id="returns_45"><a name="user-content-returns_45" href="#returns_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_46"><a name="user-content-example_46" href="#example_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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.
|
||||
<div class="codehilite"><pre> <span class="c1">-- D0 is connected to green led</span>
|
||||
<span class="c1">-- D1 is connected to blue led</span>
|
||||
<span class="c1">-- D2 is connected to red led</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
|
||||
<span class="k">function</span> <span class="nf">led</span><span class="p">(</span><span class="n">r</span><span class="p">,</span><span class="n">g</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setduty</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">g</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setduty</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setduty</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">r</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">led</span><span class="p">(</span><span class="mi">50</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span> <span class="c1">-- set led to red</span>
|
||||
<span class="n">led</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span> <span class="c1">-- set led to blue.</span>
|
||||
</pre></div>
|
||||
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_45"><a name="user-content-see-also_45" href="#see-also_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#pw_setduty">pwm.setduty()</a></p>
|
||||
|
@ -2009,8 +2120,9 @@ secure: true or false, true for safe link, false for ordinary link</p>
|
|||
<h4 id="returns_46"><a name="user-content-returns_46" href="#returns_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>net.server sub module</p>
|
||||
<h4 id="example_47"><a name="user-content-example_47" href="#example_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> net.createServer(net.TCP, true)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">net</span><span class="p">.</span><span class="n">createServer</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_46"><a name="user-content-see-also_46" href="#see-also_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#nt_createConnection">net.createConnection()</a></p>
|
||||
|
@ -2026,8 +2138,9 @@ secure: true or false, true for safe link, false for ordinary link</p>
|
|||
<h4 id="returns_47"><a name="user-content-returns_47" href="#returns_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>net.server sub module</p>
|
||||
<h4 id="example_48"><a name="user-content-example_48" href="#example_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> net.createConnection(net.UDP, false)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">net</span><span class="p">.</span><span class="n">createConnection</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">UDP</span><span class="p">,</span> <span class="kc">false</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_47"><a name="user-content-see-also_47" href="#see-also_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
|
||||
|
@ -2045,14 +2158,15 @@ function(net.socket): callback function, pass to Caller function as param if a c
|
|||
<h4 id="returns_48"><a name="user-content-returns_48" href="#returns_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_49"><a name="user-content-example_49" href="#example_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- 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)
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- create a server</span>
|
||||
<span class="n">sv</span><span class="o">=</span><span class="n">net</span><span class="p">.</span><span class="n">createServer</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">,</span> <span class="kc">false</span><span class="p">)</span>
|
||||
<span class="c1">-- server listen on 80, if data received, print data to console, and send "hello world" to remote.</span>
|
||||
<span class="n">sv</span><span class="p">:</span><span class="n">listen</span><span class="p">(</span><span class="mi">80</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="n">sck</span><span class="p">,</span> <span class="n">pl</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="n">pl</span><span class="p">)</span> <span class="k">end</span><span class="p">)</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">"</span><span class="s">hello world"</span><span class="p">)</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_48"><a name="user-content-see-also_48" href="#see-also_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
|
||||
|
@ -2067,11 +2181,12 @@ function(net.socket): callback function, pass to Caller function as param if a c
|
|||
<h4 id="returns_49"><a name="user-content-returns_49" href="#returns_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_50"><a name="user-content-example_50" href="#example_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> -- create a server
|
||||
sv=net.createServer(net.TCP, false)
|
||||
-- close server
|
||||
sv:close()
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="c1">-- create a server</span>
|
||||
<span class="n">sv</span><span class="o">=</span><span class="n">net</span><span class="p">.</span><span class="n">createServer</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">,</span> <span class="kc">false</span><span class="p">)</span>
|
||||
<span class="c1">-- close server</span>
|
||||
<span class="n">sv</span><span class="p">:</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_49"><a name="user-content-see-also_49" href="#see-also_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
|
||||
|
@ -2115,11 +2230,12 @@ If event is”receive”, the second param is received data in string.
|
|||
<h4 id="returns_52"><a name="user-content-returns_52" href="#returns_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_51"><a name="user-content-example_51" href="#example_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> 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")
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">sk</span><span class="o">=</span><span class="n">net</span><span class="p">.</span><span class="n">createConnection</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">,</span> <span class="kc">false</span><span class="p">)</span>
|
||||
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="n">sck</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span>
|
||||
<span class="n">sk</span><span class="p">:</span><span class="n">connect</span><span class="p">(</span><span class="mi">80</span><span class="p">,</span><span class="s2">"</span><span class="s">192.168.0.66"</span><span class="p">)</span>
|
||||
<span class="n">sk</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">"</span><span class="s">GET / HTTP/1.1</span><span class="se">\r\n</span><span class="s">Host: 192.168.0.66</span><span class="se">\r\n</span><span class="s">Connection: keep-alive</span><span class="se">\r\n</span><span class="s">Accept: */*</span><span class="se">\r\n\r\n</span><span class="s">"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_52"><a name="user-content-see-also_52" href="#see-also_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
|
||||
|
@ -2216,8 +2332,9 @@ data: data can be numbers, string or lua table.</p>
|
|||
<h4 id="returns_59"><a name="user-content-returns_59" href="#returns_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>nil</p>
|
||||
<h4 id="example_52"><a name="user-content-example_52" href="#example_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> i2c.write(0, "hello", "world")
|
||||
</code></pre>
|
||||
<div class="codehilite"><pre> <span class="n">i2c</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">"</span><span class="s">hello"</span><span class="p">,</span> <span class="s2">"</span><span class="s">world"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
||||
<h4 id="see-also_59"><a name="user-content-see-also_59" href="#see-also_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
|
||||
|
@ -2233,31 +2350,31 @@ len: data length</p>
|
|||
<h4 id="returns_60"><a name="user-content-returns_60" href="#returns_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
|
||||
<p>string:data received.</p>
|
||||
<h4 id="example_53"><a name="user-content-example_53" href="#example_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
|
||||
<pre><code class="lua"> id=0
|
||||
sda=1
|
||||
scl=0
|
||||
<div class="codehilite"><pre> <span class="n">id</span><span class="o">=</span><span class="mi">0</span>
|
||||
<span class="n">sda</span><span class="o">=</span><span class="mi">1</span>
|
||||
<span class="n">scl</span><span class="o">=</span><span class="mi">0</span>
|
||||
|
||||
-- initialize i2c, set pin1 as sda, set pin0 as scl
|
||||
i2c.setup(id,sda,scl,i2c.SLOW)
|
||||
<span class="c1">-- initialize i2c, set pin1 as sda, set pin0 as scl</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="n">id</span><span class="p">,</span><span class="n">sda</span><span class="p">,</span><span class="n">scl</span><span class="p">,</span><span class="n">i2c</span><span class="p">.</span><span class="n">SLOW</span><span class="p">)</span>
|
||||
|
||||
-- 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
|
||||
<span class="c1">-- user defined function: read from reg_addr content of dev_addr</span>
|
||||
<span class="k">function</span> <span class="nf">read_reg</span><span class="p">(</span><span class="n">dev_addr</span><span class="p">,</span> <span class="n">reg_addr</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">address</span><span class="p">(</span><span class="n">id</span><span class="p">,</span> <span class="n">dev_addr</span> <span class="p">,</span><span class="n">i2c</span><span class="p">.</span><span class="n">TRANSMITTER</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">id</span><span class="p">,</span><span class="n">reg_addr</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">stop</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">address</span><span class="p">(</span><span class="n">id</span><span class="p">,</span> <span class="n">dev_addr</span><span class="p">,</span><span class="n">i2c</span><span class="p">.</span><span class="n">RECEIVER</span><span class="p">)</span>
|
||||
<span class="n">c</span><span class="o">=</span><span class="n">i2c</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="n">id</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="n">i2c</span><span class="p">.</span><span class="n">stop</span><span class="p">(</span><span class="n">id</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="n">c</span>
|
||||
<span class="k">end</span>
|
||||
|
||||
-- get content of register 0xAA of device 0x77
|
||||
reg = read_reg(0x77, 0xAA)
|
||||
pirnt(string.byte(reg))
|
||||
<span class="c1">-- get content of register 0xAA of device 0x77</span>
|
||||
<span class="n">reg</span> <span class="o">=</span> <span class="n">read_reg</span><span class="p">(</span><span class="mh">0x77</span><span class="p">,</span> <span class="mh">0xAA</span><span class="p">)</span>
|
||||
<span class="n">pirnt</span><span class="p">(</span><span class="nb">string.byte</span><span class="p">(</span><span class="n">reg</span><span class="p">))</span>
|
||||
</pre></div>
|
||||
|
||||
</code></pre>
|
||||
|
||||
<h4 id="see-also_60"><a name="user-content-see-also_60" href="#see-also_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
|
||||
<p><strong>-</strong> <a href="#ic_write">i2c.write()</a></p></article></body></html>
|
|
@ -1,4 +1,5 @@
|
|||
# **nodeMcu API Instruction** #
|
||||
[中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn)
|
||||
###version 0.9.2 build 2014-11-18
|
||||
<a id="change_log"></a>
|
||||
###change log:
|
Loading…
Reference in New Issue