Commit 6f9c17a2 authored by funshine's avatar funshine
Browse files

add adc module, wifi.sta.getap() api, update doc

parent c49d438c
...@@ -1014,74 +1014,9 @@ body .markdown-body ...@@ -1014,74 +1014,9 @@ body .markdown-body
page-break-after: avoid; page-break-after: avoid;
} }
} }
</style><style>.codehilite pre .hll { background-color: #f8eec7 } </style><title>README</title></head><body><article class="markdown-body"><h1 id="nodemcu"><strong>NodeMcu</strong></h1>
.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>README</title></head><body><article class="markdown-body"><h1 id="nodemcu"><strong>NodeMcu</strong></h1>
<h3 id="a-lua-based-firmware-for-wifi-soc-esp8266"><a name="user-content-a-lua-based-firmware-for-wifi-soc-esp8266" href="#a-lua-based-firmware-for-wifi-soc-esp8266" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>A lua based firmware for wifi-soc esp8266</h3> <h3 id="a-lua-based-firmware-for-wifi-soc-esp8266"><a name="user-content-a-lua-based-firmware-for-wifi-soc-esp8266" href="#a-lua-based-firmware-for-wifi-soc-esp8266" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>A lua based firmware for wifi-soc esp8266</h3>
<p>version 0.9.2 build 2014-11-18</p> <p>version 0.9.2 build 2014-11-19</p>
<h1 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</h1> <h1 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</h1>
<p><a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log">change log</a><br /><br /> <p><a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log">change log</a><br /><br />
<a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log">变更日志</a></p> <a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log">变更日志</a></p>
...@@ -1131,106 +1066,98 @@ for most esp8266 modules, just pull GPIO0 down and restart.</p> ...@@ -1131,106 +1066,98 @@ for most esp8266 modules, just pull GPIO0 down and restart.</p>
<p>braudrate:9600</p> <p>braudrate:9600</p>
<h1 id="start-play"><a name="user-content-start-play" href="#start-play" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Start play</h1> <h1 id="start-play"><a name="user-content-start-play" href="#start-play" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Start play</h1>
<h4 id="connect-to-your-ap"><a name="user-content-connect-to-your-ap" href="#connect-to-your-ap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Connect to your ap</h4> <h4 id="connect-to-your-ap"><a name="user-content-connect-to-your-ap" href="#connect-to-your-ap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Connect to your ap</h4>
<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">sta</span><span class="p">.</span><span class="n">getip</span><span class="p">())</span> <pre><code class="lua"> print(wifi.sta.getip())
<span class="c1">--0.0.0.0</span> --0.0.0.0
<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> wifi.setmode(wifi.STATION)
<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">&quot;</span><span class="s">SSID&quot;</span><span class="p">,</span><span class="s2">&quot;</span><span class="s">password&quot;</span><span class="p">)</span> wifi.sta.config(&quot;SSID&quot;,&quot;password&quot;)
<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> print(wifi.sta.getip())
<span class="c1">--192.168.18.110</span> --192.168.18.110
</pre></div> </code></pre>
<h4 id="manipulate-hardware-like-a-arduino"><a name="user-content-manipulate-hardware-like-a-arduino" href="#manipulate-hardware-like-a-arduino" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Manipulate hardware like a arduino</h4> <h4 id="manipulate-hardware-like-a-arduino"><a name="user-content-manipulate-hardware-like-a-arduino" href="#manipulate-hardware-like-a-arduino" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Manipulate hardware like a arduino</h4>
<div class="codehilite"><pre> <span class="n">pin</span> <span class="o">=</span> <span class="mi">1</span> <pre><code class="lua"> pin = 1
<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> gpio.mode(pin,gpio.OUTPUT)
<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> gpio.write(pin,gpio.HIGH)
<span class="nb">print</span><span class="p">(</span><span class="n">gpio</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="n">pin</span><span class="p">))</span> print(gpio.read(pin))
</pre></div> </code></pre>
<h4 id="write-network-application-in-nodejs-style"><a name="user-content-write-network-application-in-nodejs-style" href="#write-network-application-in-nodejs-style" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Write network application in nodejs style</h4> <h4 id="write-network-application-in-nodejs-style"><a name="user-content-write-network-application-in-nodejs-style" href="#write-network-application-in-nodejs-style" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Write network application in nodejs style</h4>
<div class="codehilite"><pre> <span class="c1">-- A simple http client</span> <pre><code class="lua"> -- A simple http client
<span class="n">conn</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> conn=net.createConnection(net.TCP, false)
<span class="n">conn</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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="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> conn:on(&quot;receive&quot;, function(conn, payload) print(c) end )
<span class="n">conn</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">&quot;</span><span class="s">115.239.210.27&quot;</span><span class="p">)</span> conn:connect(80,&quot;115.239.210.27&quot;)
<span class="n">conn</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">GET / HTTP/1.1</span><span class="se">\r\n</span><span class="s">Host: www.baidu.com</span><span class="se">\r\n</span><span class="s">&quot;</span> conn:send(&quot;GET / HTTP/1.1\r\nHost: www.baidu.com\r\n&quot;
<span class="o">..</span><span class="s2">&quot;</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">&quot;</span><span class="p">)</span> ..&quot;Connection: keep-alive\r\nAccept: */*\r\n\r\n&quot;)
</pre></div> </code></pre>
<h4 id="or-a-simple-http-server"><a name="user-content-or-a-simple-http-server" href="#or-a-simple-http-server" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Or a simple http server</h4> <h4 id="or-a-simple-http-server"><a name="user-content-or-a-simple-http-server" href="#or-a-simple-http-server" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Or a simple http server</h4>
<div class="codehilite"><pre> <span class="c1">-- A simple http server</span> <pre><code class="lua"> -- A simple http server
<span class="n">srv</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> srv=net.createServer(net.TCP)
<span class="n">srv</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">conn</span><span class="p">)</span> srv:listen(80,function(conn)
<span class="n">conn</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> conn:on(&quot;receive&quot;,function(conn,payload)
<span class="nb">print</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span> print(payload)
<span class="n">conn</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">&lt;h1&gt; Hello, NodeMcu.&lt;/h1&gt;&quot;</span><span class="p">)</span> conn:send(&quot;&lt;h1&gt; Hello, NodeMcu.&lt;/h1&gt;&quot;)
<span class="k">end</span><span class="p">)</span> end)
<span class="k">end</span><span class="p">)</span> end)
</pre></div> </code></pre>
<h4 id="do-something-shining"><a name="user-content-do-something-shining" href="#do-something-shining" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Do something shining</h4> <h4 id="do-something-shining"><a name="user-content-do-something-shining" href="#do-something-shining" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Do something shining</h4>
<div class="codehilite"><pre> <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> <pre><code class="lua"> function led(r,g,b)
<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">r</span><span class="p">)</span> pwm.setduty(0,r)
<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">g</span><span class="p">)</span> pwm.setduty(1,g)
<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">b</span><span class="p">)</span> pwm.setduty(2,b)
<span class="k">end</span> end
<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> pwm.setup(0,500,50)
<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> pwm.setup(1,500,50)
<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> pwm.setup(2,500,50)
<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> pwm.start(0)
<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> pwm.start(1)
<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> pwm.start(2)
<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">-- red</span> led(50,0,0) -- red
<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">-- blue</span> led(0,0,50) -- blue
</pre></div> </code></pre>
<h4 id="and-blink-it"><a name="user-content-and-blink-it" href="#and-blink-it" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>And blink it</h4> <h4 id="and-blink-it"><a name="user-content-and-blink-it" href="#and-blink-it" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>And blink it</h4>
<div class="codehilite"><pre> <span class="n">lighton</span><span class="o">=</span><span class="mi">0</span> <pre><code class="lua"> lighton=0
<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> tmr.alarm(1000,1,function()
<span class="k">if</span> <span class="n">lighton</span><span class="o">==</span><span class="mi">0</span> <span class="k">then</span> if lighton==0 then
<span class="n">lighton</span><span class="o">=</span><span class="mi">1</span> lighton=1
<span class="n">led</span><span class="p">(</span><span class="mi">50</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span> led(50,50,50)
<span class="k">else</span> else
<span class="n">lighton</span><span class="o">=</span><span class="mi">0</span> lighton=0
<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">0</span><span class="p">)</span> led(0,0,0)
<span class="k">end</span> end
<span class="k">end</span><span class="p">)</span> end)
</pre></div> </code></pre>
<h4 id="if-you-want-to-run-something-when-system-started"><a name="user-content-if-you-want-to-run-something-when-system-started" href="#if-you-want-to-run-something-when-system-started" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>If you want to run something when system started</h4> <h4 id="if-you-want-to-run-something-when-system-started"><a name="user-content-if-you-want-to-run-something-when-system-started" href="#if-you-want-to-run-something-when-system-started" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>If you want to run something when system started</h4>
<div class="codehilite"><pre> <span class="c1">--init.lua will be excuted</span> <pre><code class="lua"> --init.lua will be excuted
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span><span class="s2">&quot;</span><span class="s">w&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;,&quot;w&quot;)
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s">[[print(&quot;Hello, do this at the beginning.&quot;)]]</span><span class="p">)</span> file.writeline([[print(&quot;Hello, do this at the beginning.&quot;)]])
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
<span class="n">node</span><span class="p">.</span><span class="n">restart</span><span class="p">()</span> <span class="c1">-- this will restart the module.</span> node.restart() -- this will restart the module.
</pre></div> </code></pre>
<h4 id="with-below-code-you-can-telnet-to-your-esp8266-now"><a name="user-content-with-below-code-you-can-telnet-to-your-esp8266-now" href="#with-below-code-you-can-telnet-to-your-esp8266-now" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>With below code, you can telnet to your esp8266 now</h4> <h4 id="with-below-code-you-can-telnet-to-your-esp8266-now"><a name="user-content-with-below-code-you-can-telnet-to-your-esp8266-now" href="#with-below-code-you-can-telnet-to-your-esp8266-now" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>With below code, you can telnet to your esp8266 now</h4>
<div class="codehilite"><pre> <span class="c1">-- a simple telnet server</span> <pre><code class="lua"> -- a simple telnet server
<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> s=net.createServer(net.TCP)
<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> s:listen(2323,function(c)
<span class="n">con_std</span> <span class="o">=</span> <span class="n">c</span> con_std = c
<span class="k">function</span> <span class="nf">s_output</span><span class="p">(</span><span class="n">str</span><span class="p">)</span> function s_output(str)
<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> if(con_std~=nil)
<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> then con_std:send(str)
<span class="k">end</span> end
<span class="k">end</span> end
<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> node.output(s_output, 0) -- re-direct output to function s_ouput.
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> c:on(&quot;receive&quot;,function(c,l)
<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> node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
<span class="k">end</span><span class="p">)</span> end)
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">disconnection&quot;</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> c:on(&quot;disconnection&quot;,function(c)
<span class="n">con_std</span> <span class="o">=</span> <span class="kc">nil</span> con_std = nil
<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> node.output(nil) -- un-regist the redirect output function, output goes to serial
<span class="k">end</span><span class="p">)</span> end)
<span class="k">end</span><span class="p">)</span> end)
</pre></div> </code></pre>
<h1 id="check-this-out"><a name="user-content-check-this-out" href="#check-this-out" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Check this out</h1> <h1 id="check-this-out"><a name="user-content-check-this-out" href="#check-this-out" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Check this out</h1>
<p>Tencent QQ group: 309957875<br/><br /> <p>Tencent QQ group: 309957875<br/><br />
......
# **NodeMcu** # # **NodeMcu** #
###A lua based firmware for wifi-soc esp8266 ###A lua based firmware for wifi-soc esp8266
version 0.9.2 build 2014-11-18 version 0.9.2 build 2014-11-19
# Change log # Change log
[change log](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log)<br /> [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) [变更日志](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log)
......
...@@ -1014,76 +1014,14 @@ body .markdown-body ...@@ -1014,76 +1014,14 @@ body .markdown-body
page-break-after: avoid; page-break-after: avoid;
} }
} }
</style><style>.codehilite pre .hll { background-color: #f8eec7 } </style><title>nodemcu_api_cn</title></head><body><article class="markdown-body"><h1 id="nodemcu-api"><strong>nodeMcu API说明</strong></h1>
.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_cn</title></head><body><article class="markdown-body"><h1 id="nodemcu-api"><strong>nodeMcu API说明</strong></h1>
<p><a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en">English Version</a></p> <p><a href="https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en">English Version</a></p>
<h3 id="092-build-2014-11-18"><a name="user-content-092-build-2014-11-18" href="#092-build-2014-11-18" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>版本 0.9.2 build 2014-11-18</h3> <h3 id="092-build-2014-11-19"><a name="user-content-092-build-2014-11-19" href="#092-build-2014-11-19" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>版本 0.9.2 build 2014-11-19</h3>
<p><a id="change_log"></a></p> <p><a id="change_log"></a></p>
<h3 id="_1"><a name="user-content-_1" href="#_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>变更日志:</h3> <h3 id="_1"><a name="user-content-_1" href="#_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>变更日志:</h3>
<p>2014-11-19<br /><br />
增加adc模块,adc.read(0)读取adc的值。<br /><br />
wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。</p>
<p>2014-11-18<br /><br /> <p>2014-11-18<br /><br />
修正tcp服务器不能使用:close()函数关闭tcp连接的问题。<br /><br /> 修正tcp服务器不能使用:close()函数关闭tcp连接的问题。<br /><br />
tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)<br /><br /> tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)<br /><br />
...@@ -1166,9 +1104,8 @@ node模块中删除了log函数。<br /><br /> ...@@ -1166,9 +1104,8 @@ node模块中删除了log函数。<br /><br />
<h4 id="_8"><a name="user-content-_8" href="#_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_8"><a name="user-content-_8" href="#_8" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_9"><a name="user-content-_9" href="#_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_9"><a name="user-content-_9" href="#_9" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="n">node</span><span class="p">.</span><span class="n">restart</span><span class="p">();</span> <pre><code class="lua"> node.restart();
</pre></div> </code></pre>
<h4 id="_10"><a name="user-content-_10" href="#_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_10"><a name="user-content-_10" href="#_10" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1184,9 +1121,8 @@ node模块中删除了log函数。<br /><br /> ...@@ -1184,9 +1121,8 @@ node模块中删除了log函数。<br /><br />
<h4 id="_14"><a name="user-content-_14" href="#_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_14"><a name="user-content-_14" href="#_14" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_15"><a name="user-content-_15" href="#_15" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_15"><a name="user-content-_15" href="#_15" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> node.dsleep(us);
</pre></div> </code></pre>
<h4 id="_16"><a name="user-content-_16" href="#_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_16"><a name="user-content-_16" href="#_16" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1201,9 +1137,8 @@ node模块中删除了log函数。<br /><br /> ...@@ -1201,9 +1137,8 @@ node模块中删除了log函数。<br /><br />
<h4 id="_20"><a name="user-content-_20" href="#_20" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_20"><a name="user-content-_20" href="#_20" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>number:芯片ID</p> <p>number:芯片ID</p>
<h4 id="_21"><a name="user-content-_21" href="#_21" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_21"><a name="user-content-_21" href="#_21" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> id = node.chipid();
</pre></div> </code></pre>
<h4 id="_22"><a name="user-content-_22" href="#_22" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_22"><a name="user-content-_22" href="#_22" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1218,9 +1153,8 @@ node模块中删除了log函数。<br /><br /> ...@@ -1218,9 +1153,8 @@ node模块中删除了log函数。<br /><br />
<h4 id="_26"><a name="user-content-_26" href="#_26" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_26"><a name="user-content-_26" href="#_26" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>number: 系统剩余内存字节数</p> <p>number: 系统剩余内存字节数</p>
<h4 id="_27"><a name="user-content-_27" href="#_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_27"><a name="user-content-_27" href="#_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> heap_size = node.heap();
</pre></div> </code></pre>
<h4 id="_28"><a name="user-content-_28" href="#_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_28"><a name="user-content-_28" href="#_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1237,9 +1171,8 @@ function(): 用户自定义的按键回调函数。 如果为nil, 则取消用 ...@@ -1237,9 +1171,8 @@ function(): 用户自定义的按键回调函数。 如果为nil, 则取消用
<h4 id="_32"><a name="user-content-_32" href="#_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_32"><a name="user-content-_32" href="#_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_33"><a name="user-content-_33" href="#_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_33"><a name="user-content-_33" href="#_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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">&quot;</span><span class="s">long&quot;</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">&#39;</span><span class="s">hello world&#39;</span><span class="p">)})</span> <pre><code class="lua"> node.key(&quot;long&quot;, function(){print('hello world')})
</pre></div> </code></pre>
<h4 id="_34"><a name="user-content-_34" href="#_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_34"><a name="user-content-_34" href="#_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1255,10 +1188,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms</p> ...@@ -1255,10 +1188,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms</p>
<h4 id="_38"><a name="user-content-_38" href="#_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_38"><a name="user-content-_38" href="#_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_39"><a name="user-content-_39" href="#_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_39"><a name="user-content-_39" href="#_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- LED常亮.</span> <pre><code class="lua"> -- LED常亮.
<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> node.led(0);
</pre></div> </code></pre>
<h4 id="_40"><a name="user-content-_40" href="#_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_40"><a name="user-content-_40" href="#_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1274,10 +1206,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms</p> ...@@ -1274,10 +1206,9 @@ High: LED打开时间,单位:毫秒,时间分辨率:80~100ms</p>
<h4 id="_44"><a name="user-content-_44" href="#_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_44"><a name="user-content-_44" href="#_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_45"><a name="user-content-_45" href="#_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_45"><a name="user-content-_45" href="#_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 注意:该函数不支持在命令行中使用。</span> <pre><code class="lua"> -- 注意:该函数不支持在命令行中使用。
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> sk:on(&quot;receive&quot;, function(conn, payload) node.input(payload) end)
</pre></div> </code></pre>
<h4 id="_46"><a name="user-content-_46" href="#_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_46"><a name="user-content-_46" href="#_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1293,14 +1224,13 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口</p> ...@@ -1293,14 +1224,13 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口</p>
<h4 id="_50"><a name="user-content-_50" href="#_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_50"><a name="user-content-_50" href="#_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_51"><a name="user-content-_51" href="#_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_51"><a name="user-content-_51" href="#_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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> <pre><code class="lua"> function tonet(str)
<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> sk:send(str)
<span class="c1">-- print(str) 错误!!! 千万不要在此函数中再使用print函数</span> -- print(str) 错误!!! 千万不要在此函数中再使用print函数
<span class="c1">-- 因为这样会导致函数的嵌套调用!!</span> -- 因为这样会导致函数的嵌套调用!!
<span class="k">end</span> end
<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> node.ouput(tonet, 1) -- serial also get the lua output.
</pre></div> </code></pre>
<h4 id="_52"><a name="user-content-_52" href="#_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_52"><a name="user-content-_52" href="#_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
...@@ -1316,10 +1246,9 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口</p> ...@@ -1316,10 +1246,9 @@ serial_debug: 1:将输出送至串口; 0:输出不送至串口</p>
<h4 id="_56"><a name="user-content-_56" href="#_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_56"><a name="user-content-_56" href="#_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_57"><a name="user-content-_57" href="#_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_57"><a name="user-content-_57" href="#_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 删除foo.lua文件</span> <pre><code class="lua"> -- 删除foo.lua文件
<span class="n">file</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">foo.lua&quot;</span><span class="p">)</span> file.remove(&quot;foo.lua&quot;)
</pre></div> </code></pre>
<h4 id="_58"><a name="user-content-_58" href="#_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_58"><a name="user-content-_58" href="#_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1342,12 +1271,11 @@ mode:<br /><br /> ...@@ -1342,12 +1271,11 @@ mode:<br /><br />
<h4 id="_62"><a name="user-content-_62" href="#_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_62"><a name="user-content-_62" href="#_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_63"><a name="user-content-_63" href="#_63" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_63"><a name="user-content-_63" href="#_63" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 打开&#39;init.lua&#39;,并打印文件的第一行。</span> <pre><code class="lua"> -- 打开'init.lua',并打印文件的第一行。
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_64"><a name="user-content-_64" href="#_64" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_64"><a name="user-content-_64" href="#_64" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_close">file.close()</a><br /><br /> <p><strong>-</strong> <a href="#fl_close">file.close()</a><br /><br />
...@@ -1363,12 +1291,11 @@ mode:<br /><br /> ...@@ -1363,12 +1291,11 @@ mode:<br /><br />
<h4 id="_68"><a name="user-content-_68" href="#_68" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_68"><a name="user-content-_68" href="#_68" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_69"><a name="user-content-_69" href="#_69" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_69"><a name="user-content-_69" href="#_69" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 打开&#39;init.lua&#39;,并打印文件的第一行,然后关闭文件。</span> <pre><code class="lua"> -- 打开'init.lua',并打印文件的第一行,然后关闭文件。
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_70"><a name="user-content-_70" href="#_70" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_70"><a name="user-content-_70" href="#_70" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1385,12 +1312,11 @@ mode:<br /><br /> ...@@ -1385,12 +1312,11 @@ mode:<br /><br />
<p>逐行返回文件内容。返回值末尾包含EOL(&lsquo;\n&rsquo;)<br /><br /> <p>逐行返回文件内容。返回值末尾包含EOL(&lsquo;\n&rsquo;)<br /><br />
如果读到EOF返回nil。</p> 如果读到EOF返回nil。</p>
<h4 id="_75"><a name="user-content-_75" href="#_75" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_75"><a name="user-content-_75" href="#_75" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 打开&#39;init.lua&#39;,读取并打印文件的第一行,然后关闭文件。</span> <pre><code class="lua"> -- 打开'init.lua',读取并打印文件的第一行,然后关闭文件。
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_76"><a name="user-content-_76" href="#_76" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_76"><a name="user-content-_76" href="#_76" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1407,13 +1333,12 @@ mode:<br /><br /> ...@@ -1407,13 +1333,12 @@ mode:<br /><br />
<p>true: 写入成功<br /><br /> <p>true: 写入成功<br /><br />
nil: 写入失败</p> nil: 写入失败</p>
<h4 id="_81"><a name="user-content-_81" href="#_81" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_81"><a name="user-content-_81" href="#_81" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 以&#39;a+&#39;的模式打开&#39;init.lua&#39;</span> <pre><code class="lua"> -- 以'a+'的模式打开'init.lua'
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- 将&#39;foo bar&#39;写到文件的末尾</span> -- 将'foo bar'写到文件的末尾
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.writeline('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_82"><a name="user-content-_82" href="#_82" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_82"><a name="user-content-_82" href="#_82" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1430,13 +1355,12 @@ nil: 写入失败</p> ...@@ -1430,13 +1355,12 @@ nil: 写入失败</p>
<p>true: 写入成功<br /><br /> <p>true: 写入成功<br /><br />
nil: 写入失败</p> nil: 写入失败</p>
<h4 id="_87"><a name="user-content-_87" href="#_87" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_87"><a name="user-content-_87" href="#_87" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 以&#39;a+&#39;的模式打开&#39;init.lua&#39;</span> <pre><code class="lua"> -- 以'a+'的模式打开'init.lua'
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- 将&#39;foo bar&#39;写到文件的末尾</span> -- 将'foo bar'写到文件的末尾
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.writeline('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_88"><a name="user-content-_88" href="#_88" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_88"><a name="user-content-_88" href="#_88" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1452,14 +1376,13 @@ nil: 写入失败</p> ...@@ -1452,14 +1376,13 @@ nil: 写入失败</p>
<h4 id="_92"><a name="user-content-_92" href="#_92" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_92"><a name="user-content-_92" href="#_92" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_93"><a name="user-content-_93" href="#_93" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_93"><a name="user-content-_93" href="#_93" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 以&#39;a+&#39;的模式打开&#39;init.lua&#39;</span> <pre><code class="lua"> -- 以'a+'的模式打开'init.lua'
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- 将&#39;foo bar&#39;写到文件的末尾</span> -- 将'foo bar'写到文件的末尾
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.write('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span> file.flush()
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_94"><a name="user-content-_94" href="#_94" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_94"><a name="user-content-_94" href="#_94" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1480,18 +1403,17 @@ offset: default 0</p> ...@@ -1480,18 +1403,17 @@ offset: default 0</p>
<p>成功: 返回当前的文件读写位置<br /><br /> <p>成功: 返回当前的文件读写位置<br /><br />
失败: 返回nil</p> 失败: 返回nil</p>
<h4 id="_99"><a name="user-content-_99" href="#_99" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_99"><a name="user-content-_99" href="#_99" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 以&#39;a+&#39;的模式打开&#39;init.lua&#39;</span> <pre><code class="lua"> -- 以'a+'的模式打开'init.lua'
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- 将&#39;foo bar&#39;写到文件的末尾</span> -- 将'foo bar'写到文件的末尾
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.write('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span> file.flush()
<span class="c1">--将文件读写位置设置在文件开始</span> --将文件读写位置设置在文件开始
<span class="n">file</span><span class="p">.</span><span class="n">seek</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">set&quot;</span><span class="p">)</span> file.seek(&quot;set&quot;)
<span class="c1">--读取并打印文件的第一行</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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<h4 id="_100"><a name="user-content-_100" href="#_100" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_100"><a name="user-content-_100" href="#_100" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1507,12 +1429,11 @@ offset: default 0</p> ...@@ -1507,12 +1429,11 @@ offset: default 0</p>
<h4 id="_104"><a name="user-content-_104" href="#_104" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_104"><a name="user-content-_104" href="#_104" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>返回包含{文件名:文件大小}的lua table</p> <p>返回包含{文件名:文件大小}的lua table</p>
<h4 id="_105"><a name="user-content-_105" href="#_105" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_105"><a name="user-content-_105" href="#_105" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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> <pre><code class="lua"> l = file.list();
<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="nb">pairs</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="k">do</span> for k,v in pairs(l) do
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">name:&quot;</span><span class="o">..</span><span class="n">k</span><span class="o">..</span><span class="s2">&quot;</span><span class="s">, size:&quot;</span><span class="o">..</span><span class="n">v</span><span class="p">)</span> print(&quot;name:&quot;..k..&quot;, size:&quot;..v)
<span class="k">end</span> end
</pre></div> </code></pre>
<h4 id="_106"><a name="user-content-_106" href="#_106" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_106"><a name="user-content-_106" href="#_106" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#fl_remove">file.remove()</a></p> <p><strong>-</strong> <a href="#fl_remove">file.remove()</a></p>
...@@ -1530,9 +1451,8 @@ offset: default 0</p> ...@@ -1530,9 +1451,8 @@ offset: default 0</p>
<h4 id="_111"><a name="user-content-_111" href="#_111" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_111"><a name="user-content-_111" href="#_111" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>返回设置之后的mode值</p> <p>返回设置之后的mode值</p>
<h4 id="_112"><a name="user-content-_112" href="#_112" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_112"><a name="user-content-_112" href="#_112" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.setmode(wifi.STATION)
</pre></div> </code></pre>
<h4 id="_113"><a name="user-content-_113" href="#_113" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_113"><a name="user-content-_113" href="#_113" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wf_getmode">wifi.getmode()</a></p> <p><strong>-</strong> <a href="#wf_getmode">wifi.getmode()</a></p>
...@@ -1547,9 +1467,8 @@ offset: default 0</p> ...@@ -1547,9 +1467,8 @@ offset: default 0</p>
<h4 id="_117"><a name="user-content-_117" href="#_117" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_117"><a name="user-content-_117" href="#_117" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>返回wifi的工作模式</p> <p>返回wifi的工作模式</p>
<h4 id="_118"><a name="user-content-_118" href="#_118" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_118"><a name="user-content-_118" href="#_118" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> print(wifi.getmode())
</pre></div> </code></pre>
<h4 id="_119"><a name="user-content-_119" href="#_119" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_119"><a name="user-content-_119" href="#_119" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wf_setmode">wifi.setmode()</a></p> <p><strong>-</strong> <a href="#wf_setmode">wifi.setmode()</a></p>
...@@ -1565,9 +1484,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调 ...@@ -1565,9 +1484,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调
<h4 id="_123"><a name="user-content-_123" href="#_123" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_123"><a name="user-content-_123" href="#_123" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_124"><a name="user-content-_124" href="#_124" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_124"><a name="user-content-_124" href="#_124" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.startsmart(6, cb())
</pre></div> </code></pre>
<h4 id="_125"><a name="user-content-_125" href="#_125" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_125"><a name="user-content-_125" href="#_125" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wf_stopsmart">wifi.stopsmart()</a></p> <p><strong>-</strong> <a href="#wf_stopsmart">wifi.stopsmart()</a></p>
...@@ -1582,9 +1500,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调 ...@@ -1582,9 +1500,8 @@ succeed_callback: 配置成功的回调函数,配置成功并连接至AP后调
<h4 id="_129"><a name="user-content-_129" href="#_129" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_129"><a name="user-content-_129" href="#_129" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_130"><a name="user-content-_130" href="#_130" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_130"><a name="user-content-_130" href="#_130" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">stopsmart</span><span class="p">()</span> <pre><code class="lua"> wifi.stopsmart()
</pre></div> </code></pre>
<h4 id="_131"><a name="user-content-_131" href="#_131" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_131"><a name="user-content-_131" href="#_131" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wf_startsmart">wifi.startsmart()</a></p> <p><strong>-</strong> <a href="#wf_startsmart">wifi.startsmart()</a></p>
...@@ -1601,9 +1518,8 @@ password: 字符串,长度小于64字节。</p> ...@@ -1601,9 +1518,8 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_135"><a name="user-content-_135" href="#_135" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_135"><a name="user-content-_135" href="#_135" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_136"><a name="user-content-_136" href="#_136" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_136"><a name="user-content-_136" href="#_136" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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">&quot;</span><span class="s">myssid&quot;</span><span class="p">,</span><span class="s2">&quot;</span><span class="s">mypassword&quot;</span><span class="p">)</span> <pre><code class="lua"> wifi.sta.config(&quot;myssid&quot;,&quot;mypassword&quot;)
</pre></div> </code></pre>
<h4 id="_137"><a name="user-content-_137" href="#_137" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_137"><a name="user-content-_137" href="#_137" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_connect">wifi.sta.connect()</a><br /><br /> <p><strong>-</strong> <a href="#ws_connect">wifi.sta.connect()</a><br /><br />
...@@ -1619,9 +1535,8 @@ password: 字符串,长度小于64字节。</p> ...@@ -1619,9 +1535,8 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_141"><a name="user-content-_141" href="#_141" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_141"><a name="user-content-_141" href="#_141" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_142"><a name="user-content-_142" href="#_142" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_142"><a name="user-content-_142" href="#_142" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.sta.connect()
</pre></div> </code></pre>
<h4 id="_143"><a name="user-content-_143" href="#_143" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_143"><a name="user-content-_143" href="#_143" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_disconnect">wifi.sta.disconnect()</a><br /><br /> <p><strong>-</strong> <a href="#ws_disconnect">wifi.sta.disconnect()</a><br /><br />
...@@ -1637,9 +1552,8 @@ password: 字符串,长度小于64字节。</p> ...@@ -1637,9 +1552,8 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_147"><a name="user-content-_147" href="#_147" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_147"><a name="user-content-_147" href="#_147" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_148"><a name="user-content-_148" href="#_148" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_148"><a name="user-content-_148" href="#_148" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.sta.disconnect()
</pre></div> </code></pre>
<h4 id="_149"><a name="user-content-_149" href="#_149" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_149"><a name="user-content-_149" href="#_149" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br /> <p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
...@@ -1655,9 +1569,8 @@ password: 字符串,长度小于64字节。</p> ...@@ -1655,9 +1569,8 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_153"><a name="user-content-_153" href="#_153" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_153"><a name="user-content-_153" href="#_153" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_154"><a name="user-content-_154" href="#_154" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_154"><a name="user-content-_154" href="#_154" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.sta.autoconnect()
</pre></div> </code></pre>
<h4 id="_155"><a name="user-content-_155" href="#_155" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_155"><a name="user-content-_155" href="#_155" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br /> <p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
...@@ -1674,10 +1587,9 @@ password: 字符串,长度小于64字节。</p> ...@@ -1674,10 +1587,9 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_159"><a name="user-content-_159" href="#_159" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_159"><a name="user-content-_159" href="#_159" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>ip地址字符串,如:&rdquo;192.168.0.111&rdquo;</p> <p>ip地址字符串,如:&rdquo;192.168.0.111&rdquo;</p>
<h4 id="_160"><a name="user-content-_160" href="#_160" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_160"><a name="user-content-_160" href="#_160" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- print current ip</span> <pre><code class="lua"> -- print current ip
<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> print(wifi.sta.getip())
</pre></div> </code></pre>
<h4 id="_161"><a name="user-content-_161" href="#_161" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_161"><a name="user-content-_161" href="#_161" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_getmac">wifi.sta.getmac()</a></p> <p><strong>-</strong> <a href="#ws_getmac">wifi.sta.getmac()</a></p>
...@@ -1692,674 +1604,688 @@ password: 字符串,长度小于64字节。</p> ...@@ -1692,674 +1604,688 @@ password: 字符串,长度小于64字节。</p>
<h4 id="_165"><a name="user-content-_165" href="#_165" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_165"><a name="user-content-_165" href="#_165" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>mac地址字符串,如:&rdquo;18-33-44-FE-55-BB&rdquo;</p> <p>mac地址字符串,如:&rdquo;18-33-44-FE-55-BB&rdquo;</p>
<h4 id="_166"><a name="user-content-_166" href="#_166" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_166"><a name="user-content-_166" href="#_166" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 打印当前的mac地址</span> <pre><code class="lua"> -- 打印当前的mac地址
<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> print(wifi.sta.getmac())
</pre></div> </code></pre>
<h4 id="_167"><a name="user-content-_167" href="#_167" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_167"><a name="user-content-_167" href="#_167" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_getip">wifi.sta.getip()</a></p> <p><strong>-</strong> <a href="#ws_getip">wifi.sta.getip()</a></p>
<p><a id="ws_getap"></a></p>
<h2 id="wifistagetap"><a name="user-content-wifistagetap" href="#wifistagetap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.sta.getap()</h2>
<h4 id="_168"><a name="user-content-_168" href="#_168" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>扫描并列出ap,结果以一个lua table为参数传递给回调函数。</p>
<h4 id="_169"><a name="user-content-_169" href="#_169" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>wifi.sta.getap(function(table))</p>
<h4 id="_170"><a name="user-content-_170" href="#_170" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>function(table): 当扫描结束时,调用此回调函数<br /><br />
扫描结果是一个lua table,key为ap的ssid,value为其他信息,格式:authmode,rssi,bssid,channel</p>
<h4 id="_171"><a name="user-content-_171" href="#_171" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p>
<h4 id="_172"><a name="user-content-_172" href="#_172" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<pre><code class="lua"> -- print ap list
function listap(t)
for k,v in pairs(t) do
print(k..&quot; : &quot;..v)
end
end
wifi.sta.getap(listap)
</code></pre>
<h4 id="_173"><a name="user-content-_173" href="#_173" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ws_getip">wifi.sta.getip()</a></p>
<h1 id="wifiap"><a name="user-content-wifiap" href="#wifiap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap 子模块</h1> <h1 id="wifiap"><a name="user-content-wifiap" href="#wifiap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap 子模块</h1>
<p><a id="wa_config"></a></p> <p><a id="wa_config"></a></p>
<h2 id="wifiapconfig"><a name="user-content-wifiapconfig" href="#wifiapconfig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.config()</h2> <h2 id="wifiapconfig"><a name="user-content-wifiapconfig" href="#wifiapconfig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.config()</h2>
<h4 id="_168"><a name="user-content-_168" href="#_168" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_174"><a name="user-content-_174" href="#_174" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置ap模式下的ssid和password</p> <p>设置ap模式下的ssid和password</p>
<h4 id="_169"><a name="user-content-_169" href="#_169" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_175"><a name="user-content-_175" href="#_175" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>wifi.ap.config(cfg)</p> <p>wifi.ap.config(cfg)</p>
<h4 id="_170"><a name="user-content-_170" href="#_170" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_176"><a name="user-content-_176" href="#_176" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>cfg: 设置AP的lua table</p> <p>cfg: 设置AP的lua table</p>
<h4 id="_171"><a name="user-content-_171" href="#_171" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例:</h4> <h4 id="_177"><a name="user-content-_177" href="#_177" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例:</h4>
<div class="codehilite"><pre> <span class="n">cfg</span><span class="o">=</span><span class="p">{}</span> <pre><code class="lua"> cfg={}
<span class="n">cfg</span><span class="p">.</span><span class="n">ssid</span><span class="o">=</span><span class="s2">&quot;</span><span class="s">myssid&quot;</span> cfg.ssid=&quot;myssid&quot;
<span class="n">cfg</span><span class="p">.</span><span class="n">pwd</span><span class="o">=</span><span class="s2">&quot;</span><span class="s">mypwd&quot;</span> cfg.pwd=&quot;mypwd&quot;
<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> wifi.ap.setconfig(cfg)
</pre></div> </code></pre>
<h4 id="_172"><a name="user-content-_172" href="#_172" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_178"><a name="user-content-_178" href="#_178" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_173"><a name="user-content-_173" href="#_173" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_179"><a name="user-content-_179" href="#_179" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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">&#39;</span><span class="s">password&#39;</span><span class="p">)</span> <pre><code class="lua"> wifi.ap.config(ssid, 'password')
</pre></div> </code></pre>
<h4 id="_174"><a name="user-content-_174" href="#_174" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_180"><a name="user-content-_180" href="#_180" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p> <p><strong>-</strong> <a href=""></a></p>
<p><a id="wa_getip"></a></p> <p><a id="wa_getip"></a></p>
<h2 id="wifiapgetip"><a name="user-content-wifiapgetip" href="#wifiapgetip" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getip()</h2> <h2 id="wifiapgetip"><a name="user-content-wifiapgetip" href="#wifiapgetip" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getip()</h2>
<h4 id="_175"><a name="user-content-_175" href="#_175" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_181"><a name="user-content-_181" href="#_181" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>ap模式下获取ip</p> <p>ap模式下获取ip</p>
<h4 id="_176"><a name="user-content-_176" href="#_176" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_182"><a name="user-content-_182" href="#_182" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>wifi.ap.getip()</p> <p>wifi.ap.getip()</p>
<h4 id="_177"><a name="user-content-_177" href="#_177" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_183"><a name="user-content-_183" href="#_183" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil</p> <p>nil</p>
<h4 id="_178"><a name="user-content-_178" href="#_178" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_184"><a name="user-content-_184" href="#_184" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>ip地址字符串,如:&rdquo;192.168.0.111&rdquo;</p> <p>ip地址字符串,如:&rdquo;192.168.0.111&rdquo;</p>
<h4 id="_179"><a name="user-content-_179" href="#_179" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_185"><a name="user-content-_185" href="#_185" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.ap.getip()
</pre></div> </code></pre>
<h4 id="_180"><a name="user-content-_180" href="#_180" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_186"><a name="user-content-_186" href="#_186" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wa_getmac">wifi.ap.getmac()</a></p> <p><strong>-</strong> <a href="#wa_getmac">wifi.ap.getmac()</a></p>
<p><a id="wa_getmac"></a></p> <p><a id="wa_getmac"></a></p>
<h2 id="wifiapgetmac"><a name="user-content-wifiapgetmac" href="#wifiapgetmac" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getmac()</h2> <h2 id="wifiapgetmac"><a name="user-content-wifiapgetmac" href="#wifiapgetmac" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getmac()</h2>
<h4 id="_181"><a name="user-content-_181" href="#_181" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_187"><a name="user-content-_187" href="#_187" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>ap模式下获取mac地址。</p> <p>ap模式下获取mac地址。</p>
<h4 id="_182"><a name="user-content-_182" href="#_182" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_188"><a name="user-content-_188" href="#_188" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>wifi.ap.getmac()</p> <p>wifi.ap.getmac()</p>
<h4 id="_183"><a name="user-content-_183" href="#_183" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_189"><a name="user-content-_189" href="#_189" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil</p> <p>nil</p>
<h4 id="_184"><a name="user-content-_184" href="#_184" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_190"><a name="user-content-_190" href="#_190" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>mac地址字符串,如:&rdquo;1A-33-44-FE-55-BB&rdquo;</p> <p>mac地址字符串,如:&rdquo;1A-33-44-FE-55-BB&rdquo;</p>
<h4 id="_185"><a name="user-content-_185" href="#_185" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_191"><a name="user-content-_191" href="#_191" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> wifi.ap.getmac()
</pre></div> </code></pre>
<h4 id="_186"><a name="user-content-_186" href="#_186" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_192"><a name="user-content-_192" href="#_192" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#wa_getip">wifi.ap.getip()</a></p> <p><strong>-</strong> <a href="#wa_getip">wifi.ap.getip()</a></p>
<h1 id="timer"><a name="user-content-timer" href="#timer" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>timer 模块</h1> <h1 id="timer"><a name="user-content-timer" href="#timer" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>timer 模块</h1>
<p><a id="tm_delay"></a></p> <p><a id="tm_delay"></a></p>
<h2 id="tmrdelay"><a name="user-content-tmrdelay" href="#tmrdelay" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.delay()</h2> <h2 id="tmrdelay"><a name="user-content-tmrdelay" href="#tmrdelay" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.delay()</h2>
<h4 id="_187"><a name="user-content-_187" href="#_187" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_193"><a name="user-content-_193" href="#_193" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>延迟us微秒。</p> <p>延迟us微秒。</p>
<h4 id="_188"><a name="user-content-_188" href="#_188" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_194"><a name="user-content-_194" href="#_194" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>tmr.dealy(us)</p> <p>tmr.dealy(us)</p>
<h4 id="_189"><a name="user-content-_189" href="#_189" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_195"><a name="user-content-_195" href="#_195" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>us: 延迟时间,单位:微秒</p> <p>us: 延迟时间,单位:微秒</p>
<h4 id="_190"><a name="user-content-_190" href="#_190" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_196"><a name="user-content-_196" href="#_196" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_191"><a name="user-content-_191" href="#_191" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_197"><a name="user-content-_197" href="#_197" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- delay 100us</span> <pre><code class="lua"> -- delay 100us
<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> tmr.delay(100)
</pre></div> </code></pre>
<h4 id="_192"><a name="user-content-_192" href="#_192" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_198"><a name="user-content-_198" href="#_198" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<p><a id="tm_now"></a></p> <p><a id="tm_now"></a></p>
<h2 id="tmrnow"><a name="user-content-tmrnow" href="#tmrnow" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.now()</h2> <h2 id="tmrnow"><a name="user-content-tmrnow" href="#tmrnow" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.now()</h2>
<h4 id="_193"><a name="user-content-_193" href="#_193" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_199"><a name="user-content-_199" href="#_199" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>返回系统计数器的当前值,uint32,单位:us。</p> <p>返回系统计数器的当前值,uint32,单位:us。</p>
<h4 id="_194"><a name="user-content-_194" href="#_194" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_200"><a name="user-content-_200" href="#_200" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>tmr.now()</p> <p>tmr.now()</p>
<h4 id="_195"><a name="user-content-_195" href="#_195" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_201"><a name="user-content-_201" href="#_201" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil</p> <p>nil</p>
<h4 id="_196"><a name="user-content-_196" href="#_196" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_202"><a name="user-content-_202" href="#_202" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>uint32: value of counter</p> <p>uint32: value of counter</p>
<h4 id="_197"><a name="user-content-_197" href="#_197" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_203"><a name="user-content-_203" href="#_203" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 打印计数器的当前值。</span> <pre><code class="lua"> -- 打印计数器的当前值。
<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> print(tmr.now())
</pre></div> </code></pre>
<h4 id="_198"><a name="user-content-_198" href="#_198" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_204"><a name="user-content-_204" href="#_204" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#tm_delay">tmr.delay()</a></p> <p><strong>-</strong> <a href="#tm_delay">tmr.delay()</a></p>
<p><a id="tm_alarm"></a></p> <p><a id="tm_alarm"></a></p>
<h2 id="tmralarm"><a name="user-content-tmralarm" href="#tmralarm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.alarm()</h2> <h2 id="tmralarm"><a name="user-content-tmralarm" href="#tmralarm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.alarm()</h2>
<h4 id="_199"><a name="user-content-_199" href="#_199" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_205"><a name="user-content-_205" href="#_205" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>闹钟函数。<br /><br /> <p>闹钟函数。<br /><br />
<strong>-注意:</strong> 只能允许存在一个闹钟,如果在调用tmr.stop()之前重复调用tmr.alarm(),以最后一次设置的为准,此前定义的闹钟都将失效。</p> <strong>-注意:</strong> 只能允许存在一个闹钟,如果在调用tmr.stop()之前重复调用tmr.alarm(),以最后一次设置的为准,此前定义的闹钟都将失效。</p>
<h4 id="_200"><a name="user-content-_200" href="#_200" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_206"><a name="user-content-_206" href="#_206" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>tmr.alarm(interval, repeat, function do())</p> <p>tmr.alarm(interval, repeat, function do())</p>
<h4 id="_201"><a name="user-content-_201" href="#_201" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_207"><a name="user-content-_207" href="#_207" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>Interval: 定时时间,单位:毫秒。<br /><br /> <p>Interval: 定时时间,单位:毫秒。<br /><br />
repeat: 0:一次性闹钟;1:重复闹钟。<br /><br /> repeat: 0:一次性闹钟;1:重复闹钟。<br /><br />
function do(): 定时器到时回调函数。</p> function do(): 定时器到时回调函数。</p>
<h4 id="_202"><a name="user-content-_202" href="#_202" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_208"><a name="user-content-_208" href="#_208" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_203"><a name="user-content-_203" href="#_203" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_209"><a name="user-content-_209" href="#_209" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 每1000ms输出一个hello world</span> <pre><code class="lua"> -- 每1000ms输出一个hello world
<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">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span> tmr.alarm(1000, 1, function() print(&quot;hello world&quot;) end )
</pre></div> </code></pre>
<h4 id="_204"><a name="user-content-_204" href="#_204" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_210"><a name="user-content-_210" href="#_210" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<p><a id="tm_stop"></a></p> <p><a id="tm_stop"></a></p>
<h2 id="tmrstop"><a name="user-content-tmrstop" href="#tmrstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.stop()</h2> <h2 id="tmrstop"><a name="user-content-tmrstop" href="#tmrstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.stop()</h2>
<h4 id="_205"><a name="user-content-_205" href="#_205" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_211"><a name="user-content-_211" href="#_211" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>停止闹钟功能。<br /></p> <p>停止闹钟功能。<br /></p>
<h4 id="_206"><a name="user-content-_206" href="#_206" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_212"><a name="user-content-_212" href="#_212" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>tmr.stop()</p> <p>tmr.stop()</p>
<h4 id="_207"><a name="user-content-_207" href="#_207" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_213"><a name="user-content-_213" href="#_213" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil.</p> <p>nil.</p>
<h4 id="_208"><a name="user-content-_208" href="#_208" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_214"><a name="user-content-_214" href="#_214" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_209"><a name="user-content-_209" href="#_209" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_215"><a name="user-content-_215" href="#_215" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 每隔1000ms打印hello world</span> <pre><code class="lua"> -- 每隔1000ms打印hello world
<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">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span> tmr.alarm(1000, 1, function() print(&quot;hello world&quot;) end )
<span class="c1">-- 其它代码</span>
<span class="c1">-- 停止闹钟</span> -- 其它代码
<span class="n">tmr</span><span class="p">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
-- 停止闹钟
tmr.stop()
</code></pre>
<h4 id="_210"><a name="user-content-_210" href="#_210" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_216"><a name="user-content-_216" href="#_216" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<h1 id="gpio"><a name="user-content-gpio" href="#gpio" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>GPIO 模块</h1> <h1 id="gpio"><a name="user-content-gpio" href="#gpio" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>GPIO 模块</h1>
<h2 id="_211"><a name="user-content-_211" href="#_211" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2> <h2 id="_217"><a name="user-content-_217" href="#_217" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2>
<p>gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW</p> <p>gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW</p>
<p><a id="io_mode"></a></p> <p><a id="io_mode"></a></p>
<h2 id="gpiomode"><a name="user-content-gpiomode" href="#gpiomode" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.mode()</h2> <h2 id="gpiomode"><a name="user-content-gpiomode" href="#gpiomode" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.mode()</h2>
<h4 id="_212"><a name="user-content-_212" href="#_212" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_218"><a name="user-content-_218" href="#_218" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>将pin初始化为GPIO并设置输入输出模式。</p> <p>将pin初始化为GPIO并设置输入输出模式。</p>
<h4 id="_213"><a name="user-content-_213" href="#_213" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_219"><a name="user-content-_219" href="#_219" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>gpio.mode(pin, mode)</p> <p>gpio.mode(pin, mode)</p>
<h4 id="_214"><a name="user-content-_214" href="#_214" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_220"><a name="user-content-_220" href="#_220" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
mode: 取值为:gpio.OUTPUT or gpio.INPUT, or gpio.INT(中断模式)</p> mode: 取值为:gpio.OUTPUT or gpio.INPUT, or gpio.INT(中断模式)</p>
<h4 id="_215"><a name="user-content-_215" href="#_215" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_221"><a name="user-content-_221" href="#_221" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_216"><a name="user-content-_216" href="#_216" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_222"><a name="user-content-_222" href="#_222" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 将GPIO0设置为输出模式</span> <pre><code class="lua"> -- 将GPIO0设置为输出模式
<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> gpio.mode(0, gpio.OUTPUT)
</pre></div>
</code></pre>
<h4 id="_217"><a name="user-content-_217" href="#_217" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_223"><a name="user-content-_223" href="#_223" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#io_read">gpio.read()</a></p> <p><strong>-</strong> <a href="#io_read">gpio.read()</a></p>
<p><a id="io_read"></a></p> <p><a id="io_read"></a></p>
<h2 id="gpioread"><a name="user-content-gpioread" href="#gpioread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.read()</h2> <h2 id="gpioread"><a name="user-content-gpioread" href="#gpioread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.read()</h2>
<h4 id="_218"><a name="user-content-_218" href="#_218" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_224"><a name="user-content-_224" href="#_224" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>读取管脚电平高低。</p> <p>读取管脚电平高低。</p>
<h4 id="_219"><a name="user-content-_219" href="#_219" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_225"><a name="user-content-_225" href="#_225" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>gpio.read(pin)</p> <p>gpio.read(pin)</p>
<h4 id="_220"><a name="user-content-_220" href="#_220" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_226"><a name="user-content-_226" href="#_226" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_221"><a name="user-content-_221" href="#_221" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_227"><a name="user-content-_227" href="#_227" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>number:0:低电平, 1:高电平。</p> <p>number:0:低电平, 1:高电平。</p>
<h4 id="_222"><a name="user-content-_222" href="#_222" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_228"><a name="user-content-_228" href="#_228" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 读取GPIO0的电平</span> <pre><code class="lua"> -- 读取GPIO0的电平
<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> gpio.read(0)
</pre></div> </code></pre>
<h4 id="_223"><a name="user-content-_223" href="#_223" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_229"><a name="user-content-_229" href="#_229" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a></p> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a></p>
<p><a id="io_write"></a></p> <p><a id="io_write"></a></p>
<h2 id="gpiowrite"><a name="user-content-gpiowrite" href="#gpiowrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.write()</h2> <h2 id="gpiowrite"><a name="user-content-gpiowrite" href="#gpiowrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.write()</h2>
<h4 id="_224"><a name="user-content-_224" href="#_224" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_230"><a name="user-content-_230" href="#_230" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置管脚电平</p> <p>设置管脚电平</p>
<h4 id="_225"><a name="user-content-_225" href="#_225" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_231"><a name="user-content-_231" href="#_231" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>gpio.write(pin)</p> <p>gpio.write(pin)</p>
<h4 id="_226"><a name="user-content-_226" href="#_226" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_232"><a name="user-content-_232" href="#_232" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
level: gpio.HIGH or gpio.LOW</p> level: gpio.HIGH or gpio.LOW</p>
<h4 id="_227"><a name="user-content-_227" href="#_227" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_233"><a name="user-content-_233" href="#_233" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_228"><a name="user-content-_228" href="#_228" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_234"><a name="user-content-_234" href="#_234" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 设置GPIP1为输出模式,并将输出电平设置为高</span> <pre><code class="lua"> -- 设置GPIP1为输出模式,并将输出电平设置为高
<span class="n">pin</span><span class="o">=</span><span class="mi">1</span> pin=1
<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> gpio.mode(pin, gpio.OUTPUT)
<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> gpio.write(pin, gpio.HIGH)
</pre></div> </code></pre>
<h4 id="_229"><a name="user-content-_229" href="#_229" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_235"><a name="user-content-_235" href="#_235" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br /> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
<strong>-</strong> <a href="#io_read">gpio.read()</a></p> <strong>-</strong> <a href="#io_read">gpio.read()</a></p>
<p><a id="io_trig"></a></p> <p><a id="io_trig"></a></p>
<h2 id="gpiotrig"><a name="user-content-gpiotrig" href="#gpiotrig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.trig()</h2> <h2 id="gpiotrig"><a name="user-content-gpiotrig" href="#gpiotrig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.trig()</h2>
<h4 id="_230"><a name="user-content-_230" href="#_230" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_236"><a name="user-content-_236" href="#_236" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置管脚中断模式的回调函数。</p> <p>设置管脚中断模式的回调函数。</p>
<h4 id="_231"><a name="user-content-_231" href="#_231" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_237"><a name="user-content-_237" href="#_237" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>gpio.trig(pin, type, function(level))</p> <p>gpio.trig(pin, type, function(level))</p>
<h4 id="_232"><a name="user-content-_232" href="#_232" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_238"><a name="user-content-_238" href="#_238" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
type: 取值为&rdquo;up&rdquo;, &ldquo;down&rdquo;, &ldquo;both&rdquo;, &ldquo;low&rdquo;, &ldquo;high&rdquo;, 分别代表上升沿、下降沿、双边沿、低电平、高电平触发方式。<br /><br /> type: 取值为&rdquo;up&rdquo;, &ldquo;down&rdquo;, &ldquo;both&rdquo;, &ldquo;low&rdquo;, &ldquo;high&rdquo;, 分别代表上升沿、下降沿、双边沿、低电平、高电平触发方式。<br /><br />
function(level): 中断触发的回调函数,GPIO的电平作为输入参数。如果此处没有定义函数,则使用之前定义的回调函数。</p> function(level): 中断触发的回调函数,GPIO的电平作为输入参数。如果此处没有定义函数,则使用之前定义的回调函数。</p>
<h4 id="_233"><a name="user-content-_233" href="#_233" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_239"><a name="user-content-_239" href="#_239" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_234"><a name="user-content-_234" href="#_234" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_240"><a name="user-content-_240" href="#_240" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 使用GPIO0检测输入脉冲宽度</span> <pre><code class="lua"> -- 使用GPIO0检测输入脉冲宽度
<span class="n">pulse0</span> <span class="o">=</span> <span class="mi">0</span> pulse0 = 0
<span class="n">du</span> <span class="o">=</span> <span class="mi">0</span> du = 0
<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> gpio.mode(0,gpio.INT)
<span class="k">function</span> <span class="nf">pin0cb</span><span class="p">(</span><span class="n">level</span><span class="p">)</span> function pin0cb(level)
<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> du = tmr.now() – pulse0
<span class="nb">print</span><span class="p">(</span><span class="n">du</span><span class="p">)</span> print(du)
<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> pulse0 = tmr.now()
<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">&quot;</span><span class="s">down &quot;</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">&quot;</span><span class="s">up &quot;</span><span class="p">)</span> <span class="k">end</span> if level == 1 then gpio.trig(0, &quot;down &quot;) else gpio.trig(0, &quot;up &quot;) end
<span class="k">end</span> end
<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">&quot;</span><span class="s">down &quot;</span><span class="p">,</span><span class="n">pin0cb</span><span class="p">)</span> gpio.trig(0, &quot;down &quot;,pin0cb)
</pre></div>
</code></pre>
<h4 id="_235"><a name="user-content-_235" href="#_235" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_241"><a name="user-content-_241" href="#_241" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br /> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
<strong>-</strong> <a href="#io_write">gpio.write()</a></p> <strong>-</strong> <a href="#io_write">gpio.write()</a></p>
<h1 id="pwm"><a name="user-content-pwm" href="#pwm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>PWM模块</h1> <h1 id="pwm"><a name="user-content-pwm" href="#pwm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>PWM模块</h1>
<p><a id="pw_setup"></a></p> <p><a id="pw_setup"></a></p>
<h2 id="pwmsetup"><a name="user-content-pwmsetup" href="#pwmsetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setup()</h2> <h2 id="pwmsetup"><a name="user-content-pwmsetup" href="#pwmsetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setup()</h2>
<h4 id="_236"><a name="user-content-_236" href="#_236" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_242"><a name="user-content-_242" href="#_242" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置管脚为pwm模式,最多支持6个pwm。</p> <p>设置管脚为pwm模式,最多支持6个pwm。</p>
<h4 id="_237"><a name="user-content-_237" href="#_237" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_243"><a name="user-content-_243" href="#_243" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.setup(pin, clock, duty)</p> <p>pwm.setup(pin, clock, duty)</p>
<h4 id="_238"><a name="user-content-_238" href="#_238" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_244"><a name="user-content-_244" href="#_244" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
clock: 1~500, pwm频率<br /><br /> clock: 1~500, pwm频率<br /><br />
duty: 0~100, pwm占空比,百分比表示。</p> duty: 0~100, pwm占空比,百分比表示。</p>
<h4 id="_239"><a name="user-content-_239" href="#_239" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_245"><a name="user-content-_245" href="#_245" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_240"><a name="user-content-_240" href="#_240" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_246"><a name="user-content-_246" href="#_246" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 将管脚0设置为pwm输出模式,频率100Hz,占空比50-50</span> <pre><code class="lua"> -- 将管脚0设置为pwm输出模式,频率100Hz,占空比50-50
<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> pwm.setup(0, 100, 50)
</pre></div> </code></pre>
<h4 id="_241"><a name="user-content-_241" href="#_241" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_247"><a name="user-content-_247" href="#_247" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_close"></a></p> <p><a id="pw_close"></a></p>
<h2 id="pwmclose"><a name="user-content-pwmclose" href="#pwmclose" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.close()</h2> <h2 id="pwmclose"><a name="user-content-pwmclose" href="#pwmclose" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.close()</h2>
<h4 id="_242"><a name="user-content-_242" href="#_242" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_248"><a name="user-content-_248" href="#_248" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>退出pwm模式。</p> <p>退出pwm模式。</p>
<h4 id="_243"><a name="user-content-_243" href="#_243" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_249"><a name="user-content-_249" href="#_249" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.close(pin)</p> <p>pwm.close(pin)</p>
<h4 id="_244"><a name="user-content-_244" href="#_244" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_250"><a name="user-content-_250" href="#_250" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_245"><a name="user-content-_245" href="#_245" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_251"><a name="user-content-_251" href="#_251" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_246"><a name="user-content-_246" href="#_246" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_252"><a name="user-content-_252" href="#_252" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> pwm.close(0)
</pre></div> </code></pre>
<h4 id="_247"><a name="user-content-_247" href="#_247" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_253"><a name="user-content-_253" href="#_253" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_start"></a></p> <p><a id="pw_start"></a></p>
<h2 id="pwmstart"><a name="user-content-pwmstart" href="#pwmstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.start()</h2> <h2 id="pwmstart"><a name="user-content-pwmstart" href="#pwmstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.start()</h2>
<h4 id="_248"><a name="user-content-_248" href="#_248" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_254"><a name="user-content-_254" href="#_254" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>pwm启动,可以在对应的GPIO检测到波形。</p> <p>pwm启动,可以在对应的GPIO检测到波形。</p>
<h4 id="_249"><a name="user-content-_249" href="#_249" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_255"><a name="user-content-_255" href="#_255" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.start(pin)</p> <p>pwm.start(pin)</p>
<h4 id="_250"><a name="user-content-_250" href="#_250" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_256"><a name="user-content-_256" href="#_256" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_251"><a name="user-content-_251" href="#_251" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_257"><a name="user-content-_257" href="#_257" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_252"><a name="user-content-_252" href="#_252" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_258"><a name="user-content-_258" href="#_258" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> pwm.start(0)
</pre></div> </code></pre>
<h4 id="_253"><a name="user-content-_253" href="#_253" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_259"><a name="user-content-_259" href="#_259" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_stop">pwm.stop()</a></p> <p><strong>-</strong> <a href="#pw_stop">pwm.stop()</a></p>
<p><a id="pw_stop"></a></p> <p><a id="pw_stop"></a></p>
<h2 id="pwmstop"><a name="user-content-pwmstop" href="#pwmstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.stop()</h2> <h2 id="pwmstop"><a name="user-content-pwmstop" href="#pwmstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.stop()</h2>
<h4 id="_254"><a name="user-content-_254" href="#_254" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_260"><a name="user-content-_260" href="#_260" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>暂停pwm输出波形。</p> <p>暂停pwm输出波形。</p>
<h4 id="_255"><a name="user-content-_255" href="#_255" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_261"><a name="user-content-_261" href="#_261" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.stop(pin)</p> <p>pwm.stop(pin)</p>
<h4 id="_256"><a name="user-content-_256" href="#_256" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_262"><a name="user-content-_262" href="#_262" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_257"><a name="user-content-_257" href="#_257" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_263"><a name="user-content-_263" href="#_263" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_258"><a name="user-content-_258" href="#_258" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_264"><a name="user-content-_264" href="#_264" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> pwm.stop(0)
</pre></div> </code></pre>
<h4 id="_259"><a name="user-content-_259" href="#_259" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_265"><a name="user-content-_265" href="#_265" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_setclock"></a></p> <p><a id="pw_setclock"></a></p>
<h2 id="pwmsetclock"><a name="user-content-pwmsetclock" href="#pwmsetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setclock()</h2> <h2 id="pwmsetclock"><a name="user-content-pwmsetclock" href="#pwmsetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setclock()</h2>
<h4 id="_260"><a name="user-content-_260" href="#_260" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_266"><a name="user-content-_266" href="#_266" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置pwm的频率<br /><br /> <p>设置pwm的频率<br /><br />
<strong>-Note:</strong> 设置pwm频率将会同步改变其他pwm输出的频率,当前版本的所有pwm仅支持同一频率输出。</p> <strong>-Note:</strong> 设置pwm频率将会同步改变其他pwm输出的频率,当前版本的所有pwm仅支持同一频率输出。</p>
<h4 id="_261"><a name="user-content-_261" href="#_261" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_267"><a name="user-content-_267" href="#_267" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.setclock(pin, clock)</p> <p>pwm.setclock(pin, clock)</p>
<h4 id="_262"><a name="user-content-_262" href="#_262" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_268"><a name="user-content-_268" href="#_268" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
clock: 1~500, pwm周期</p> clock: 1~500, pwm周期</p>
<h4 id="_263"><a name="user-content-_263" href="#_263" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_269"><a name="user-content-_269" href="#_269" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_264"><a name="user-content-_264" href="#_264" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_270"><a name="user-content-_270" href="#_270" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> pwm.setclock(0, 100)
</pre></div> </code></pre>
<h4 id="_265"><a name="user-content-_265" href="#_265" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_271"><a name="user-content-_271" href="#_271" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_getclock">pwm.getclock()</a></p> <p><strong>-</strong> <a href="#pw_getclock">pwm.getclock()</a></p>
<p><a id="pw_getclock"></a></p> <p><a id="pw_getclock"></a></p>
<h2 id="pwmgetclock"><a name="user-content-pwmgetclock" href="#pwmgetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getclock()</h2> <h2 id="pwmgetclock"><a name="user-content-pwmgetclock" href="#pwmgetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getclock()</h2>
<h4 id="_266"><a name="user-content-_266" href="#_266" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_272"><a name="user-content-_272" href="#_272" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>获取pin的pwm工作频率</p> <p>获取pin的pwm工作频率</p>
<h4 id="_267"><a name="user-content-_267" href="#_267" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_273"><a name="user-content-_273" href="#_273" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.getclock(pin)</p> <p>pwm.getclock(pin)</p>
<h4 id="_268"><a name="user-content-_268" href="#_268" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_274"><a name="user-content-_274" href="#_274" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_269"><a name="user-content-_269" href="#_269" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_275"><a name="user-content-_275" href="#_275" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>number:pin的pwm工作频率</p> <p>number:pin的pwm工作频率</p>
<h4 id="_270"><a name="user-content-_270" href="#_270" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_276"><a name="user-content-_276" href="#_276" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> print(pwm.getclock(0))
</pre></div> </code></pre>
<h4 id="_271"><a name="user-content-_271" href="#_271" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_277"><a name="user-content-_277" href="#_277" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_setclock">pwm.setclock()</a></p> <p><strong>-</strong> <a href="#pw_setclock">pwm.setclock()</a></p>
<p><a id="pw_setduty"></a></p> <p><a id="pw_setduty"></a></p>
<h2 id="pwmsetduty"><a name="user-content-pwmsetduty" href="#pwmsetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setduty()</h2> <h2 id="pwmsetduty"><a name="user-content-pwmsetduty" href="#pwmsetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setduty()</h2>
<h4 id="_272"><a name="user-content-_272" href="#_272" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_278"><a name="user-content-_278" href="#_278" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置pin的占空比。</p> <p>设置pin的占空比。</p>
<h4 id="_273"><a name="user-content-_273" href="#_273" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_279"><a name="user-content-_279" href="#_279" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.setduty(pin, duty)</p> <p>pwm.setduty(pin, duty)</p>
<h4 id="_274"><a name="user-content-_274" href="#_274" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_280"><a name="user-content-_280" href="#_280" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号<br /><br /> <p>pin: 0~11, IO编号<br /><br />
duty: 0~100, pwm的占空比,以百分数表示</p> duty: 0~100, pwm的占空比,以百分数表示</p>
<h4 id="_275"><a name="user-content-_275" href="#_275" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_281"><a name="user-content-_281" href="#_281" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_276"><a name="user-content-_276" href="#_276" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_282"><a name="user-content-_282" href="#_282" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> pwm.setduty(0, 50)
</pre></div> </code></pre>
<h4 id="_277"><a name="user-content-_277" href="#_277" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_283"><a name="user-content-_283" href="#_283" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_getduty">pwm.getduty()</a></p> <p><strong>-</strong> <a href="#pw_getduty">pwm.getduty()</a></p>
<p><a id="pw_getduty"></a></p> <p><a id="pw_getduty"></a></p>
<h2 id="pwmgetduty"><a name="user-content-pwmgetduty" href="#pwmgetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getduty()</h2> <h2 id="pwmgetduty"><a name="user-content-pwmgetduty" href="#pwmgetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getduty()</h2>
<h4 id="_278"><a name="user-content-_278" href="#_278" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_284"><a name="user-content-_284" href="#_284" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>获取pin的pwm占空比。</p> <p>获取pin的pwm占空比。</p>
<h4 id="_279"><a name="user-content-_279" href="#_279" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_285"><a name="user-content-_285" href="#_285" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>pwm.getduty(pin)</p> <p>pwm.getduty(pin)</p>
<h4 id="_280"><a name="user-content-_280" href="#_280" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_286"><a name="user-content-_286" href="#_286" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>pin: 0~11, IO编号</p> <p>pin: 0~11, IO编号</p>
<h4 id="_281"><a name="user-content-_281" href="#_281" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_287"><a name="user-content-_287" href="#_287" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_282"><a name="user-content-_282" href="#_282" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_288"><a name="user-content-_288" href="#_288" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- D0 连接绿色led</span> <pre><code class="lua"> -- D0 连接绿色led
<span class="c1">-- D1 连接蓝色led</span> -- D1 连接蓝色led
<span class="c1">-- D2 连接红色led</span> -- D2 连接红色led
<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> pwm.setup(0,500,50)
<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> pwm.setup(1,500,50)
<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> pwm.setup(2,500,50)
<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> pwm.start(0)
<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> pwm.start(1)
<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> pwm.start(2)
<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> function led(r,g,b)
<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> pwm.setduty(0,g)
<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> pwm.setduty(1,b)
<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> pwm.setduty(2,r)
<span class="k">end</span> end
<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">-- led显示红色</span> led(50,0,0) -- led显示红色
<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">-- led显示蓝色</span> led(0,0,50) -- led显示蓝色
</pre></div>
</code></pre>
<h4 id="_283"><a name="user-content-_283" href="#_283" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_289"><a name="user-content-_289" href="#_289" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#pw_setduty">pwm.setduty()</a></p> <p><strong>-</strong> <a href="#pw_setduty">pwm.setduty()</a></p>
<h1 id="net"><a name="user-content-net" href="#net" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net 模块</h1> <h1 id="net"><a name="user-content-net" href="#net" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net 模块</h1>
<h2 id="_284"><a name="user-content-_284" href="#_284" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2> <h2 id="_290"><a name="user-content-_290" href="#_290" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2>
<p>net.TCP, net.UDP</p> <p>net.TCP, net.UDP</p>
<p><a id="nt_createServer"></a></p> <p><a id="nt_createServer"></a></p>
<h2 id="netcreateserver"><a name="user-content-netcreateserver" href="#netcreateserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createServer()</h2> <h2 id="netcreateserver"><a name="user-content-netcreateserver" href="#netcreateserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createServer()</h2>
<h4 id="_285"><a name="user-content-_285" href="#_285" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_291"><a name="user-content-_291" href="#_291" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>创建一个server。</p> <p>创建一个server。</p>
<h4 id="_286"><a name="user-content-_286" href="#_286" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_292"><a name="user-content-_292" href="#_292" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>net.createServer(type, secure)</p> <p>net.createServer(type, secure)</p>
<h4 id="_287"><a name="user-content-_287" href="#_287" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_293"><a name="user-content-_293" href="#_293" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>type: 取值为:net.TCP 或者 net.UDP<br /><br /> <p>type: 取值为:net.TCP 或者 net.UDP<br /><br />
secure: 设置为true或者false, true代表安全连接,false代表普通连接。</p> secure: 设置为true或者false, true代表安全连接,false代表普通连接。</p>
<h4 id="_288"><a name="user-content-_288" href="#_288" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_294"><a name="user-content-_294" href="#_294" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>net.server子模块</p> <p>net.server子模块</p>
<h4 id="_289"><a name="user-content-_289" href="#_289" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_295"><a name="user-content-_295" href="#_295" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> net.createServer(net.TCP, true)
</pre></div> </code></pre>
<h4 id="_290"><a name="user-content-_290" href="#_290" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_296"><a name="user-content-_296" href="#_296" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createConnection">net.createConnection()</a></p> <p><strong>-</strong> <a href="#nt_createConnection">net.createConnection()</a></p>
<p><a id="nt_createConnection"></a></p> <p><a id="nt_createConnection"></a></p>
<h2 id="netcreateconnection"><a name="user-content-netcreateconnection" href="#netcreateconnection" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createConnection()</h2> <h2 id="netcreateconnection"><a name="user-content-netcreateconnection" href="#netcreateconnection" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createConnection()</h2>
<h4 id="_291"><a name="user-content-_291" href="#_291" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_297"><a name="user-content-_297" href="#_297" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>创建一个client。</p> <p>创建一个client。</p>
<h4 id="_292"><a name="user-content-_292" href="#_292" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_298"><a name="user-content-_298" href="#_298" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>net.createConnection(type, secure)</p> <p>net.createConnection(type, secure)</p>
<h4 id="_293"><a name="user-content-_293" href="#_293" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_299"><a name="user-content-_299" href="#_299" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>type: 取值为:net.TCP 或者 net.UDP<br /><br /> <p>type: 取值为:net.TCP 或者 net.UDP<br /><br />
secure: 设置为true或者false, true代表安全连接,false代表普通连接。</p> secure: 设置为true或者false, true代表安全连接,false代表普通连接。</p>
<h4 id="_294"><a name="user-content-_294" href="#_294" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_300"><a name="user-content-_300" href="#_300" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>net.server子模块</p> <p>net.server子模块</p>
<h4 id="_295"><a name="user-content-_295" href="#_295" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_301"><a name="user-content-_301" href="#_301" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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><code class="lua"> net.createConnection(net.UDP, false)
</pre></div> </code></pre>
<h4 id="_296"><a name="user-content-_296" href="#_296" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_302"><a name="user-content-_302" href="#_302" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="netserver"><a name="user-content-netserver" href="#netserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.server 子模块</h1> <h1 id="netserver"><a name="user-content-netserver" href="#netserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.server 子模块</h1>
<p><a id="ns_listen"></a></p> <p><a id="ns_listen"></a></p>
<h2 id="listen"><a name="user-content-listen" href="#listen" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>listen()</h2> <h2 id="listen"><a name="user-content-listen" href="#listen" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>listen()</h2>
<h4 id="_297"><a name="user-content-_297" href="#_297" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_303"><a name="user-content-_303" href="#_303" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>侦听指定ip地址的端口。</p> <p>侦听指定ip地址的端口。</p>
<h4 id="_298"><a name="user-content-_298" href="#_298" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_304"><a name="user-content-_304" href="#_304" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>net.server.listen(port,[ip],function(net.socket))</p> <p>net.server.listen(port,[ip],function(net.socket))</p>
<h4 id="_299"><a name="user-content-_299" href="#_299" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_305"><a name="user-content-_305" href="#_305" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>port: 端口号<br /><br /> <p>port: 端口号<br /><br />
ip:ip地址字符串,可以省略<br /><br /> ip:ip地址字符串,可以省略<br /><br />
function(net.socket): 连接创建成功的回调函数,可以作为参数传给调用函数。</p> function(net.socket): 连接创建成功的回调函数,可以作为参数传给调用函数。</p>
<h4 id="_300"><a name="user-content-_300" href="#_300" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_306"><a name="user-content-_306" href="#_306" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_301"><a name="user-content-_301" href="#_301" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_307"><a name="user-content-_307" href="#_307" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 创建一个server</span> <pre><code class="lua"> -- 创建一个server
<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> sv=net.createServer(net.TCP, false)
<span class="c1">-- server侦听端口80,如果收到数据将数据打印至控制台,并向远端发送‘hello world’</span> -- server侦听端口80,如果收到数据将数据打印至控制台,并向远端发送‘hello world’
<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> sv:listen(80,function(c)
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> c:on(&quot;receive&quot;, function(sck, pl) print(pl) end)
<span class="n">c</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> c:send(&quot;hello world&quot;)
<span class="k">end</span><span class="p">)</span> end)
</pre></div> </code></pre>
<h4 id="_302"><a name="user-content-_302" href="#_302" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_308"><a name="user-content-_308" href="#_308" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="ns_close"></a></p> <p><a id="ns_close"></a></p>
<h2 id="close"><a name="user-content-close" href="#close" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2> <h2 id="close"><a name="user-content-close" href="#close" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2>
<h4 id="_303"><a name="user-content-_303" href="#_303" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_309"><a name="user-content-_309" href="#_309" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>关闭server</p> <p>关闭server</p>
<h4 id="_304"><a name="user-content-_304" href="#_304" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_310"><a name="user-content-_310" href="#_310" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>net.server.close()</p> <p>net.server.close()</p>
<h4 id="_305"><a name="user-content-_305" href="#_305" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_311"><a name="user-content-_311" href="#_311" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil</p> <p>nil</p>
<h4 id="_306"><a name="user-content-_306" href="#_306" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_312"><a name="user-content-_312" href="#_312" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_307"><a name="user-content-_307" href="#_307" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_313"><a name="user-content-_313" href="#_313" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="c1">-- 创建server</span> <pre><code class="lua"> -- 创建server
<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> sv=net.createServer(net.TCP, false)
<span class="c1">-- 关闭server</span> -- 关闭server
<span class="n">sv</span><span class="p">:</span><span class="n">close</span><span class="p">()</span> sv:close()
</pre></div> </code></pre>
<h4 id="_314"><a name="user-content-_314" href="#_314" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<h4 id="_308"><a name="user-content-_308" href="#_308" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="netsocket"><a name="user-content-netsocket" href="#netsocket" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.socket 子模块</h1> <h1 id="netsocket"><a name="user-content-netsocket" href="#netsocket" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.socket 子模块</h1>
<p><a id="nk_connect"></a></p> <p><a id="nk_connect"></a></p>
<h2 id="connect"><a name="user-content-connect" href="#connect" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>connect()</h2> <h2 id="connect"><a name="user-content-connect" href="#connect" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>connect()</h2>
<h4 id="_309"><a name="user-content-_309" href="#_309" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_315"><a name="user-content-_315" href="#_315" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>连接至远端。</p> <p>连接至远端。</p>
<h4 id="_310"><a name="user-content-_310" href="#_310" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_316"><a name="user-content-_316" href="#_316" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>connect(port, ip)</p> <p>connect(port, ip)</p>
<h4 id="_311"><a name="user-content-_311" href="#_311" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_317"><a name="user-content-_317" href="#_317" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>port: 端口号<br /><br /> <p>port: 端口号<br /><br />
ip: ip地址字符串</p> ip: ip地址字符串</p>
<h4 id="_312"><a name="user-content-_312" href="#_312" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_318"><a name="user-content-_318" href="#_318" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_313"><a name="user-content-_313" href="#_313" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_319"><a name="user-content-_319" href="#_319" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p> <p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p>
<p><a id="nk_send"></a></p> <p><a id="nk_send"></a></p>
<h2 id="send"><a name="user-content-send" href="#send" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>send()</h2> <h2 id="send"><a name="user-content-send" href="#send" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>send()</h2>
<h4 id="_314"><a name="user-content-_314" href="#_314" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_320"><a name="user-content-_320" href="#_320" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>通过连接向远端发送数据。</p> <p>通过连接向远端发送数据。</p>
<h4 id="_315"><a name="user-content-_315" href="#_315" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_321"><a name="user-content-_321" href="#_321" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>send(string, function(sent))</p> <p>send(string, function(sent))</p>
<h4 id="_316"><a name="user-content-_316" href="#_316" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_322"><a name="user-content-_322" href="#_322" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>string: 待发送的字符串<br /><br /> <p>string: 待发送的字符串<br /><br />
function(sent): 发送字符串后的回调函数。</p> function(sent): 发送字符串后的回调函数。</p>
<h4 id="_317"><a name="user-content-_317" href="#_317" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_323"><a name="user-content-_323" href="#_323" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_318"><a name="user-content-_318" href="#_318" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_324"><a name="user-content-_324" href="#_324" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p> <p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p>
<p><a id="nk_on"></a></p> <p><a id="nk_on"></a></p>
<h2 id="on"><a name="user-content-on" href="#on" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>on()</h2> <h2 id="on"><a name="user-content-on" href="#on" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>on()</h2>
<h4 id="_319"><a name="user-content-_319" href="#_319" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_325"><a name="user-content-_325" href="#_325" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>向事件注册回调函数。</p> <p>向事件注册回调函数。</p>
<h4 id="_320"><a name="user-content-_320" href="#_320" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_326"><a name="user-content-_326" href="#_326" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>on(event, function cb())</p> <p>on(event, function cb())</p>
<h4 id="_321"><a name="user-content-_321" href="#_321" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_327"><a name="user-content-_327" href="#_327" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>event: 字符串,取值为: &ldquo;connection&rdquo;, &ldquo;reconnection&rdquo;, &ldquo;disconnection&rdquo;, &ldquo;receive&rdquo;, &ldquo;sent&rdquo;<br /><br /> <p>event: 字符串,取值为: &ldquo;connection&rdquo;, &ldquo;reconnection&rdquo;, &ldquo;disconnection&rdquo;, &ldquo;receive&rdquo;, &ldquo;sent&rdquo;<br /><br />
function cb(net.socket, [string]): 回调函数。第一个参数是socket.<br /><br /> function cb(net.socket, [string]): 回调函数。第一个参数是socket.<br /><br />
如果事件是&rdquo;receive&rdquo;, 第二个参数则为接收到的字符串。</p> 如果事件是&rdquo;receive&rdquo;, 第二个参数则为接收到的字符串。</p>
<h4 id="_322"><a name="user-content-_322" href="#_322" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_328"><a name="user-content-_328" href="#_328" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_323"><a name="user-content-_323" href="#_323" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_329"><a name="user-content-_329" href="#_329" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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> <pre><code class="lua"> sk=net.createConnection(net.TCP, false)
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> sk:on(&quot;receive&quot;, function(sck, c) print(c) end )
<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">&quot;</span><span class="s">192.168.0.66&quot;</span><span class="p">)</span> sk:connect(80,&quot;192.168.0.66&quot;)
<span class="n">sk</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</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">&quot;</span><span class="p">)</span> sk:send(&quot;GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n&quot;)
</pre></div> </code></pre>
<h4 id="_330"><a name="user-content-_330" href="#_330" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<h4 id="_324"><a name="user-content-_324" href="#_324" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="nk_close"></a></p> <p><a id="nk_close"></a></p>
<h2 id="close_1"><a name="user-content-close_1" href="#close_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2> <h2 id="close_1"><a name="user-content-close_1" href="#close_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2>
<h4 id="_325"><a name="user-content-_325" href="#_325" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_331"><a name="user-content-_331" href="#_331" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>关闭socket。</p> <p>关闭socket。</p>
<h4 id="_326"><a name="user-content-_326" href="#_326" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_332"><a name="user-content-_332" href="#_332" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>close()</p> <p>close()</p>
<h4 id="_327"><a name="user-content-_327" href="#_327" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_333"><a name="user-content-_333" href="#_333" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>nil</p> <p>nil</p>
<h4 id="_328"><a name="user-content-_328" href="#_328" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_334"><a name="user-content-_334" href="#_334" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_329"><a name="user-content-_329" href="#_329" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_335"><a name="user-content-_335" href="#_335" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="nk_dns"></a></p> <p><a id="nk_dns"></a></p>
<h2 id="dns"><a name="user-content-dns" href="#dns" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>dns()</h2> <h2 id="dns"><a name="user-content-dns" href="#dns" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>dns()</h2>
<h4 id="_330"><a name="user-content-_330" href="#_330" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_336"><a name="user-content-_336" href="#_336" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>获取当前域的ip</p> <p>获取当前域的ip</p>
<h4 id="_331"><a name="user-content-_331" href="#_331" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_337"><a name="user-content-_337" href="#_337" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>dns(domain, function(net.socket, ip))</p> <p>dns(domain, function(net.socket, ip))</p>
<h4 id="_332"><a name="user-content-_332" href="#_332" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_338"><a name="user-content-_338" href="#_338" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>domain: 当前域的名称<br /><br /> <p>domain: 当前域的名称<br /><br />
function (net.socket, ip): 回调函数。第一个参数是socket,第二个参数是当前域的ip字符串。</p> function (net.socket, ip): 回调函数。第一个参数是socket,第二个参数是当前域的ip字符串。</p>
<h4 id="_333"><a name="user-content-_333" href="#_333" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_339"><a name="user-content-_339" href="#_339" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_334"><a name="user-content-_334" href="#_334" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_340"><a name="user-content-_340" href="#_340" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="i2c"><a name="user-content-i2c" href="#i2c" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c模块</h1> <h1 id="i2c"><a name="user-content-i2c" href="#i2c" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c模块</h1>
<h2 id="_335"><a name="user-content-_335" href="#_335" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2> <h2 id="_341"><a name="user-content-_341" href="#_341" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2>
<p>i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)模式目前不支持。</p> <p>i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)模式目前不支持。</p>
<p><a id="ic_setup"></a></p> <p><a id="ic_setup"></a></p>
<h2 id="i2csetup"><a name="user-content-i2csetup" href="#i2csetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.setup()</h2> <h2 id="i2csetup"><a name="user-content-i2csetup" href="#i2csetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.setup()</h2>
<h4 id="_336"><a name="user-content-_336" href="#_336" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_342"><a name="user-content-_342" href="#_342" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>初始化i2c。</p> <p>初始化i2c。</p>
<h4 id="_337"><a name="user-content-_337" href="#_337" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_343"><a name="user-content-_343" href="#_343" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.setup(id, pinSDA, pinSCL, speed)</p> <p>i2c.setup(id, pinSDA, pinSCL, speed)</p>
<h4 id="_338"><a name="user-content-_338" href="#_338" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_344"><a name="user-content-_344" href="#_344" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id = 0<br /><br /> <p>id = 0<br /><br />
pinSDA: 0~11, IO编号<br /><br /> pinSDA: 0~11, IO编号<br /><br />
pinSCL: 0~11, IO编号<br /><br /> pinSCL: 0~11, IO编号<br /><br />
speed: i2c.SLOW</p> speed: i2c.SLOW</p>
<h4 id="_339"><a name="user-content-_339" href="#_339" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_345"><a name="user-content-_345" href="#_345" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_340"><a name="user-content-_340" href="#_340" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_346"><a name="user-content-_346" href="#_346" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_start"></a></p> <p><a id="ic_start"></a></p>
<h2 id="i2cstart"><a name="user-content-i2cstart" href="#i2cstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.start()</h2> <h2 id="i2cstart"><a name="user-content-i2cstart" href="#i2cstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.start()</h2>
<h4 id="_341"><a name="user-content-_341" href="#_341" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_347"><a name="user-content-_347" href="#_347" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>启动i2c传输。</p> <p>启动i2c传输。</p>
<h4 id="_342"><a name="user-content-_342" href="#_342" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_348"><a name="user-content-_348" href="#_348" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.start(id)</p> <p>i2c.start(id)</p>
<h4 id="_343"><a name="user-content-_343" href="#_343" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_349"><a name="user-content-_349" href="#_349" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id = 0</p> <p>id = 0</p>
<h4 id="_344"><a name="user-content-_344" href="#_344" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_350"><a name="user-content-_350" href="#_350" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_345"><a name="user-content-_345" href="#_345" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_351"><a name="user-content-_351" href="#_351" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_stop"></a></p> <p><a id="ic_stop"></a></p>
<h2 id="i2cstop"><a name="user-content-i2cstop" href="#i2cstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.stop()</h2> <h2 id="i2cstop"><a name="user-content-i2cstop" href="#i2cstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.stop()</h2>
<h4 id="_346"><a name="user-content-_346" href="#_346" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_352"><a name="user-content-_352" href="#_352" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>停止i2c传输。</p> <p>停止i2c传输。</p>
<h4 id="_347"><a name="user-content-_347" href="#_347" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_353"><a name="user-content-_353" href="#_353" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.stop(id)</p> <p>i2c.stop(id)</p>
<h4 id="_348"><a name="user-content-_348" href="#_348" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_354"><a name="user-content-_354" href="#_354" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id = 0</p> <p>id = 0</p>
<h4 id="_349"><a name="user-content-_349" href="#_349" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_355"><a name="user-content-_355" href="#_355" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_350"><a name="user-content-_350" href="#_350" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_356"><a name="user-content-_356" href="#_356" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_address"></a></p> <p><a id="ic_address"></a></p>
<h2 id="i2caddress"><a name="user-content-i2caddress" href="#i2caddress" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.address()</h2> <h2 id="i2caddress"><a name="user-content-i2caddress" href="#i2caddress" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.address()</h2>
<h4 id="_351"><a name="user-content-_351" href="#_351" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_357"><a name="user-content-_357" href="#_357" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>设置i2c地址以及读写模式。</p> <p>设置i2c地址以及读写模式。</p>
<h4 id="_352"><a name="user-content-_352" href="#_352" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_358"><a name="user-content-_358" href="#_358" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.address(id, device_addr, direction)</p> <p>i2c.address(id, device_addr, direction)</p>
<h4 id="_353"><a name="user-content-_353" href="#_353" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_359"><a name="user-content-_359" href="#_359" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
device_addr: 设备地址。<br /><br /> device_addr: 设备地址。<br /><br />
direction: i2c.TRANSMITTER:写模式;i2c. RECEIVER:读模式。</p> direction: i2c.TRANSMITTER:写模式;i2c. RECEIVER:读模式。</p>
<h4 id="_354"><a name="user-content-_354" href="#_354" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_360"><a name="user-content-_360" href="#_360" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_355"><a name="user-content-_355" href="#_355" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_361"><a name="user-content-_361" href="#_361" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_write"></a></p> <p><a id="ic_write"></a></p>
<h2 id="i2cwrite"><a name="user-content-i2cwrite" href="#i2cwrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.write()</h2> <h2 id="i2cwrite"><a name="user-content-i2cwrite" href="#i2cwrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.write()</h2>
<h4 id="_356"><a name="user-content-_356" href="#_356" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_362"><a name="user-content-_362" href="#_362" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>向i2c写数据。数据可以是多个数字, 字符串或者lua table。</p> <p>向i2c写数据。数据可以是多个数字, 字符串或者lua table。</p>
<h4 id="_357"><a name="user-content-_357" href="#_357" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_363"><a name="user-content-_363" href="#_363" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.write(id, data1, data2,&hellip;)</p> <p>i2c.write(id, data1, data2,&hellip;)</p>
<h4 id="_358"><a name="user-content-_358" href="#_358" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_364"><a name="user-content-_364" href="#_364" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
data: 数据可以是多个数字, 字符串或者lua table。</p> data: 数据可以是多个数字, 字符串或者lua table。</p>
<h4 id="_359"><a name="user-content-_359" href="#_359" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_365"><a name="user-content-_365" href="#_365" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>nil</p> <p>nil</p>
<h4 id="_360"><a name="user-content-_360" href="#_360" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_366"><a name="user-content-_366" href="#_366" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<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">&quot;</span><span class="s">hello&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">world&quot;</span><span class="p">)</span> <pre><code class="lua"> i2c.write(0, &quot;hello&quot;, &quot;world&quot;)
</pre></div> </code></pre>
<h4 id="_361"><a name="user-content-_361" href="#_361" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_367"><a name="user-content-_367" href="#_367" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_read"></a></p> <p><a id="ic_read"></a></p>
<h2 id="i2cread"><a name="user-content-i2cread" href="#i2cread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.read()</h2> <h2 id="i2cread"><a name="user-content-i2cread" href="#i2cread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.read()</h2>
<h4 id="_362"><a name="user-content-_362" href="#_362" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4> <h4 id="_368"><a name="user-content-_368" href="#_368" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>读取len个字节的数据。</p> <p>读取len个字节的数据。</p>
<h4 id="_363"><a name="user-content-_363" href="#_363" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4> <h4 id="_369"><a name="user-content-_369" href="#_369" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>i2c.read(id, len)</p> <p>i2c.read(id, len)</p>
<h4 id="_364"><a name="user-content-_364" href="#_364" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4> <h4 id="_370"><a name="user-content-_370" href="#_370" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
len: 数据长度。</p> len: 数据长度。</p>
<h4 id="_365"><a name="user-content-_365" href="#_365" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4> <h4 id="_371"><a name="user-content-_371" href="#_371" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>string:接收到的数据。</p> <p>string:接收到的数据。</p>
<h4 id="_366"><a name="user-content-_366" href="#_366" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4> <h4 id="_372"><a name="user-content-_372" href="#_372" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>示例</h4>
<div class="codehilite"><pre> <span class="n">id</span><span class="o">=</span><span class="mi">0</span> <pre><code class="lua"> id=0
<span class="n">sda</span><span class="o">=</span><span class="mi">1</span> sda=1
<span class="n">scl</span><span class="o">=</span><span class="mi">0</span> scl=0
<span class="c1">-- 初始化i2c, 将pin1设置为sda, 将pin0设置为scl</span> -- 初始化i2c, 将pin1设置为sda, 将pin0设置为scl
<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> i2c.setup(id,sda,scl,i2c.SLOW)
<span class="c1">-- 用户定义函数:读取地址dev_addr的寄存器reg_addr中的内容。</span> -- 用户定义函数:读取地址dev_addr的寄存器reg_addr中的内容。
<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> function read_reg(dev_addr, reg_addr)
<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> i2c.start(id)
<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> i2c.address(id, dev_addr ,i2c.TRANSMITTER)
<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> i2c.write(id,reg_addr)
<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> i2c.stop(id)
<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> i2c.start(id)
<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> i2c.address(id, dev_addr,i2c.RECEIVER)
<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> c=i2c.read(id,1)
<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> i2c.stop(id)
<span class="k">return</span> <span class="n">c</span> return c
<span class="k">end</span> end
<span class="c1">-- 读取0x77的寄存器0xAA中的内容。</span> -- 读取0x77的寄存器0xAA中的内容。
<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> reg = read_reg(0x77, 0xAA)
<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> pirnt(string.byte(reg))
</pre></div>
</code></pre>
<h4 id="_367"><a name="user-content-_367" href="#_367" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4> <h4 id="_373"><a name="user-content-_373" href="#_373" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href="#ic_write">i2c.write()</a></p></article></body></html> <p><strong>-</strong> <a href="#ic_write">i2c.write()</a></p>
\ No newline at end of file <h1 id="adc"><a name="user-content-adc" href="#adc" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>adc 模块</h1>
<h2 id="_374"><a name="user-content-_374" href="#_374" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>常量</h2>
<p></p>
<p><a id="adc_read"></a></p>
<h2 id="adcread"><a name="user-content-adcread" href="#adcread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>adc.read()</h2>
<h4 id="_375"><a name="user-content-_375" href="#_375" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>描述</h4>
<p>读取adc的值,esp8266只有一个10bit adc,id为0,最大值1024</p>
<h4 id="_376"><a name="user-content-_376" href="#_376" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>语法</h4>
<p>adc.read(id)</p>
<h4 id="_377"><a name="user-content-_377" href="#_377" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参数</h4>
<p>id = 0<br /></p>
<h4 id="_378"><a name="user-content-_378" href="#_378" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>返回值</h4>
<p>adc 值 10bit,最大1024.</p>
<h4 id="_379"><a name="user-content-_379" href="#_379" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>参见</h4>
<p><strong>-</strong> <a href=""></a></p></article></body></html>
\ No newline at end of file
# **nodeMcu API说明** # # **nodeMcu API说明** #
[English Version](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en) [English Version](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en)
###版本 0.9.2 build 2014-11-18 ###版本 0.9.2 build 2014-11-19
<a id="change_log"></a> <a id="change_log"></a>
###变更日志: ###变更日志:
2014-11-19<br />
增加adc模块,adc.read(0)读取adc的值。<br />
wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。
2014-11-18<br /> 2014-11-18<br />
修正tcp服务器不能使用:close()函数关闭tcp连接的问题。<br /> 修正tcp服务器不能使用:close()函数关闭tcp连接的问题。<br />
tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)<br /> tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)<br />
...@@ -807,6 +811,36 @@ mac地址字符串,如:"18-33-44-FE-55-BB" ...@@ -807,6 +811,36 @@ mac地址字符串,如:"18-33-44-FE-55-BB"
####参见 ####参见
**-** [wifi.sta.getip()](#ws_getip) **-** [wifi.sta.getip()](#ws_getip)
<a id="ws_getap"></a>
## wifi.sta.getap()
####描述
扫描并列出ap,结果以一个lua table为参数传递给回调函数。
####语法
wifi.sta.getap(function(table))
####参数
function(table): 当扫描结束时,调用此回调函数<br />
扫描结果是一个lua table,key为ap的ssid,value为其他信息,格式:authmode,rssi,bssid,channel
####返回值
nil
####示例
```lua
-- print ap list
function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
end
end
wifi.sta.getap(listap)
```
####参见
**-** [wifi.sta.getip()](#ws_getip)
#wifi.ap 子模块 #wifi.ap 子模块
...@@ -1708,3 +1742,24 @@ string:接收到的数据。 ...@@ -1708,3 +1742,24 @@ string:接收到的数据。
####参见 ####参见
**-** [i2c.write()](#ic_write) **-** [i2c.write()](#ic_write)
#adc 模块
##常量
<a id="adc_read"></a>
## adc.read()
####描述
读取adc的值,esp8266只有一个10bit adc,id为0,最大值1024
####语法
adc.read(id)
####参数
id = 0<br />
####返回值
adc 值 10bit,最大1024.
####参见
**-** []()
...@@ -1014,76 +1014,14 @@ body .markdown-body ...@@ -1014,76 +1014,14 @@ body .markdown-body
page-break-after: avoid; page-break-after: avoid;
} }
} }
</style><style>.codehilite pre .hll { background-color: #f8eec7 } </style><title>nodemcu_api_en</title></head><body><article class="markdown-body"><h1 id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
.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> <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> <h3 id="version-092-build-2014-11-19"><a name="user-content-version-092-build-2014-11-19" href="#version-092-build-2014-11-19" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>version 0.9.2 build 2014-11-19</h3>
<p><a id="change_log"></a></p> <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> <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>
<p>2014-11-19<br /><br />
add adc module, use adc.read(0) to read adc value, no tests made.<br /><br />
add wifi.sta.getap() api to wifi.sta module, to get ap list.</p>
<p>2014-11-18<br /><br /> <p>2014-11-18<br /><br />
bug fixed: net.socket:connect() has no effect.</p> bug fixed: net.socket:connect() has no effect.</p>
<p>2014-11-18<br /><br /> <p>2014-11-18<br /><br />
...@@ -1162,9 +1100,8 @@ key is triged only when key is released<br /></p> ...@@ -1162,9 +1100,8 @@ 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> <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> <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> <h4 id="example"><a name="user-content-example" href="#example" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
<div class="codehilite"><pre> <span class="n">node</span><span class="p">.</span><span class="n">restart</span><span class="p">();</span> <pre><code class="lua"> node.restart();
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1180,9 +1117,8 @@ key is triged only when key is released<br /></p> ...@@ -1180,9 +1117,8 @@ 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> <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> <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> <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>
<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><code class="lua"> node.dsleep(us);
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1197,9 +1133,8 @@ key is triged only when key is released<br /></p> ...@@ -1197,9 +1133,8 @@ 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> <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> <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> <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>
<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><code class="lua"> id = node.chipid();
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1214,9 +1149,8 @@ key is triged only when key is released<br /></p> ...@@ -1214,9 +1149,8 @@ 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> <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> <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> <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>
<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><code class="lua"> heap_size = node.heap();
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1233,9 +1167,8 @@ Default function: long: change LED blinking rate, short: reset chip</p> ...@@ -1233,9 +1167,8 @@ 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> <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> <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> <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>
<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">&quot;</span><span class="s">long&quot;</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">&#39;</span><span class="s">hello world&#39;</span><span class="p">)})</span> <pre><code class="lua"> node.key(&quot;long&quot;, function(){print('hello world')})
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1251,10 +1184,9 @@ High: LED off time. Unit: milliseconds, time resolution: 80~100ms</p> ...@@ -1251,10 +1184,9 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- turn led on forever.</span> <pre><code class="lua"> -- turn led on forever.
<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> node.led(0);
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1270,10 +1202,9 @@ same as pcall(loadstring(str)) but support multi seperated line.</p> ...@@ -1270,10 +1202,9 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- never use node.input() in console. no effect.</span> <pre><code class="lua"> -- never use node.input() in console. no effect.
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> sk:on(&quot;receive&quot;, function(conn, payload) node.input(payload) end)
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1289,35 +1220,33 @@ serial_debug: 1 output also show in serial. 0: no serial output.</p> ...@@ -1289,35 +1220,33 @@ 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> <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> <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> <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>
<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> <pre><code class="lua"> function tonet(str)
<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> sk:send(str)
<span class="c1">-- print(str) WRONG!!! never ever print something in this function</span> -- print(str) WRONG!!! never ever print something in this function
<span class="c1">-- because this will cause a recursive function call!!!</span> -- because this will cause a recursive function call!!!
<span class="k">end</span> end
<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> node.ouput(tonet, 1) -- serial also get the lua output.
</pre></div> </code></pre>
<pre><code class="lua"> -- a simple telnet server
<div class="codehilite"><pre> <span class="c1">-- a simple telnet server</span> s=net.createServer(net.TCP)
<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> s:listen(2323,function(c)
<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> con_std = c
<span class="n">con_std</span> <span class="o">=</span> <span class="n">c</span> function s_output(str)
<span class="k">function</span> <span class="nf">s_output</span><span class="p">(</span><span class="n">str</span><span class="p">)</span> if(con_std~=nil)
<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> then con_std:send(str)
<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> end
<span class="k">end</span> end
<span class="k">end</span> node.output(s_output, 0) -- re-direct output to function s_ouput.
<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> c:on(&quot;receive&quot;,function(c,l)
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
<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> end)
<span class="k">end</span><span class="p">)</span> c:on(&quot;disconnection&quot;,function(c)
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">disconnection&quot;</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> con_std = nil
<span class="n">con_std</span> <span class="o">=</span> <span class="kc">nil</span> node.output(nil) -- un-regist the redirect output function, output goes to serial
<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> end)
<span class="k">end</span><span class="p">)</span> end)
<span class="k">end</span><span class="p">)</span> </code></pre>
</pre></div>
<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> <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> <p><strong>-</strong> <a href=""></a></p>
...@@ -1333,10 +1262,9 @@ serial_debug: 1 output also show in serial. 0: no serial output.</p> ...@@ -1333,10 +1262,9 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- remove &quot;foo.lua&quot; from file system.</span> <pre><code class="lua"> -- remove &quot;foo.lua&quot; from file system.
<span class="n">file</span><span class="p">.</span><span class="n">remove</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">foo.lua&quot;</span><span class="p">)</span> file.remove(&quot;foo.lua&quot;)
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1359,12 +1287,11 @@ mode:<br /><br /> ...@@ -1359,12 +1287,11 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39;, print the first line.</span> <pre><code class="lua"> -- open 'init.lua', print the first line.
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_close">file.close()</a><br /><br />
...@@ -1380,12 +1307,11 @@ mode:<br /><br /> ...@@ -1380,12 +1307,11 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39;, print the first line.</span> <pre><code class="lua"> -- open 'init.lua', print the first line.
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1402,12 +1328,11 @@ mode:<br /><br /> ...@@ -1402,12 +1328,11 @@ mode:<br /><br />
<p>file content in string, line by line, include EOL(&lsquo;\n&rsquo;)<br /><br /> <p>file content in string, line by line, include EOL(&lsquo;\n&rsquo;)<br /><br />
return nil when EOF.</p> 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> <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>
<div class="codehilite"><pre> <span class="c1">-- print the first line of &#39;init.lua&#39;</span> <pre><code class="lua"> -- print the first line of 'init.lua'
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">r&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;r&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1424,13 +1349,12 @@ return nil when EOF.</p> ...@@ -1424,13 +1349,12 @@ return nil when EOF.</p>
<p>true: write ok.<br /> <p>true: write ok.<br />
nil: there is error</p> 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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39; in &#39;a+&#39; mode</span> <pre><code class="lua"> -- open 'init.lua' in 'a+' mode
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- write &#39;foo bar&#39; to the end of the file</span> -- write 'foo bar' to the end of the file
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.writeline('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1447,13 +1371,12 @@ nil: there is error</p> ...@@ -1447,13 +1371,12 @@ nil: there is error</p>
<p>true: write ok.<br /> <p>true: write ok.<br />
nil: there is error</p> 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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39; in &#39;a+&#39; mode</span> <pre><code class="lua"> -- open 'init.lua' in 'a+' mode
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- write &#39;foo bar&#39; to the end of the file</span> -- write 'foo bar' to the end of the file
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.write('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1469,14 +1392,13 @@ nil: there is error</p> ...@@ -1469,14 +1392,13 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39; in &#39;a+&#39; mode</span> <pre><code class="lua"> -- open 'init.lua' in 'a+' mode
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- write &#39;foo bar&#39; to the end of the file</span> -- write 'foo bar' to the end of the file
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.write('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span> file.flush()
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1497,16 +1419,15 @@ offset: default 0</p> ...@@ -1497,16 +1419,15 @@ offset: default 0</p>
<p>success: returns the final file position<br /><br /> <p>success: returns the final file position<br /><br />
fail: returns nil</p> 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> <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>
<div class="codehilite"><pre> <span class="c1">-- open &#39;init.lua&#39; in &#39;a+&#39; mode</span> <pre><code class="lua"> -- open 'init.lua' in 'a+' mode
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">init.lua&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">a+&quot;</span><span class="p">)</span> file.open(&quot;init.lua&quot;, &quot;a+&quot;)
<span class="c1">-- write &#39;foo bar&#39; to the end of the file</span> -- write 'foo bar' to the end of the file
<span class="n">file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="s">foo bar&#39;</span><span class="p">)</span> file.write('foo bar')
<span class="n">file</span><span class="p">.</span><span class="n">flush</span><span class="p">()</span> file.flush()
<span class="n">file</span><span class="p">.</span><span class="n">seek</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">set&quot;</span><span class="p">)</span> file.seek(&quot;set&quot;)
<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> print(file.readline())
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span> file.close()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#fl_open">file.open()</a><br /><br />
...@@ -1522,12 +1443,11 @@ fail: returns nil</p> ...@@ -1522,12 +1443,11 @@ 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> <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> <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> <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>
<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> <pre><code class="lua"> l = file.list();
<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> for k,v in l do
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">name:&quot;</span><span class="o">..</span><span class="n">k</span><span class="o">..</span><span class="s2">&quot;</span><span class="s">, size:&quot;</span><span class="o">..</span><span class="n">v</span><span class="p">)</span> print(&quot;name:&quot;..k..&quot;, size:&quot;..v)
<span class="k">end</span> end
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#fl_remove">file.remove()</a></p>
...@@ -1545,9 +1465,8 @@ fail: returns nil</p> ...@@ -1545,9 +1465,8 @@ 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> <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> <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> <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>
<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><code class="lua"> wifi.setmode(wifi.STATION)
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#wf_getmode">wifi.getmode()</a></p>
...@@ -1562,9 +1481,8 @@ fail: returns nil</p> ...@@ -1562,9 +1481,8 @@ 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> <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> <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> <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>
<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><code class="lua"> print(wifi.getmode())
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#wf_setmode">wifi.setmode()</a></p>
...@@ -1580,9 +1498,8 @@ succeed_callback: callback function called after configuration, which is called ...@@ -1580,9 +1498,8 @@ 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> <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> <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> <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>
<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><code class="lua"> wifi.startsmart(6, cb())
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#wf_stopsmart">wifi.stopsmart()</a></p>
...@@ -1597,9 +1514,8 @@ succeed_callback: callback function called after configuration, which is called ...@@ -1597,9 +1514,8 @@ 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="n">wifi</span><span class="p">.</span><span class="n">stopsmart</span><span class="p">()</span> <pre><code class="lua"> wifi.stopsmart()
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#wf_startsmart">wifi.startsmart()</a></p>
...@@ -1616,9 +1532,8 @@ password: string which is less than 64 bytes.</p> ...@@ -1616,9 +1532,8 @@ 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> <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> <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> <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>
<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">&quot;</span><span class="s">myssid&quot;</span><span class="p">,</span><span class="s2">&quot;</span><span class="s">mypassword&quot;</span><span class="p">)</span> <pre><code class="lua"> wifi.sta.config(&quot;myssid&quot;,&quot;mypassword&quot;)
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#ws_connect">wifi.sta.connect()</a><br /><br />
...@@ -1634,9 +1549,8 @@ password: string which is less than 64 bytes.</p> ...@@ -1634,9 +1549,8 @@ 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> <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> <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> <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>
<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><code class="lua"> wifi.sta.connect()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#ws_disconnect">wifi.sta.disconnect()</a><br /><br />
...@@ -1652,9 +1566,8 @@ password: string which is less than 64 bytes.</p> ...@@ -1652,9 +1566,8 @@ 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> <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> <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> <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>
<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><code class="lua"> wifi.sta.disconnect()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
...@@ -1670,9 +1583,8 @@ password: string which is less than 64 bytes.</p> ...@@ -1670,9 +1583,8 @@ 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> <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> <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> <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>
<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><code class="lua"> wifi.sta.autoconnect()
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#ws_config">wifi.sta.config()</a><br /><br />
...@@ -1689,10 +1601,9 @@ password: string which is less than 64 bytes.</p> ...@@ -1689,10 +1601,9 @@ 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> <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:&rdquo;192.168.0.111&rdquo;</p> <p>ip address in string, for example:&rdquo;192.168.0.111&rdquo;</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> <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>
<div class="codehilite"><pre> <span class="c1">-- print current ip</span> <pre><code class="lua"> -- print current ip
<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> print(wifi.sta.getip())
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#ws_getmac">wifi.sta.getmac()</a></p>
...@@ -1707,674 +1618,688 @@ password: string which is less than 64 bytes.</p> ...@@ -1707,674 +1618,688 @@ 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> <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:&rdquo;18-33-44-FE-55-BB&rdquo;</p> <p>mac address in string, for example:&rdquo;18-33-44-FE-55-BB&rdquo;</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> <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>
<div class="codehilite"><pre> <span class="c1">-- print current mac address</span> <pre><code class="lua"> -- print current mac address
<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> print(wifi.sta.getmac())
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#ws_getip">wifi.sta.getip()</a></p>
<p><a id="ws_getap"></a></p>
<h2 id="wifistagetap"><a name="user-content-wifistagetap" href="#wifistagetap" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.sta.getap()</h2>
<h4 id="description_27"><a name="user-content-description_27" href="#description_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>scan and get ap list as a lua table into callback function.</p>
<h4 id="syntax_27"><a name="user-content-syntax_27" href="#syntax_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>wifi.sta.getap(function(table))</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>function(table): a callback function to receive ap table when scan is done<br /><br />
this function receive a table, the key is the ssid, value is other info in format: authmode,rssi,bssid,channel</p>
<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_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"> -- print ap list
function listap(t)
for k,v in pairs(t) do
print(k..&quot; : &quot;..v)
end
end
wifi.sta.getap(listap)
</code></pre>
<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="#ws_getip">wifi.sta.getip()</a></p>
<h1 id="wifiap-module"><a name="user-content-wifiap-module" href="#wifiap-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap module</h1> <h1 id="wifiap-module"><a name="user-content-wifiap-module" href="#wifiap-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap module</h1>
<p><a id="wa_config"></a></p> <p><a id="wa_config"></a></p>
<h2 id="wifiapconfig"><a name="user-content-wifiapconfig" href="#wifiapconfig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.config()</h2> <h2 id="wifiapconfig"><a name="user-content-wifiapconfig" href="#wifiapconfig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.config()</h2>
<h4 id="description_27"><a name="user-content-description_27" href="#description_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_28"><a name="user-content-description_28" href="#description_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set ssid and password in ap mode.</p> <p>set ssid and password in ap mode.</p>
<h4 id="syntax_27"><a name="user-content-syntax_27" href="#syntax_27" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_28"><a name="user-content-syntax_28" href="#syntax_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>wifi.ap.config(cfg)</p> <p>wifi.ap.config(cfg)</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> <h4 id="parameters_28"><a name="user-content-parameters_28" href="#parameters_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>cfg: lua table to setup ap.</p> <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> <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>
<div class="codehilite"><pre> <span class="n">cfg</span><span class="o">=</span><span class="p">{}</span> <pre><code class="lua"> cfg={}
<span class="n">cfg</span><span class="p">.</span><span class="n">ssid</span><span class="o">=</span><span class="s2">&quot;</span><span class="s">myssid&quot;</span> cfg.ssid=&quot;myssid&quot;
<span class="n">cfg</span><span class="p">.</span><span class="n">pwd</span><span class="o">=</span><span class="s2">&quot;</span><span class="s">mypwd&quot;</span> cfg.pwd=&quot;mypwd&quot;
<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> wifi.ap.setconfig(cfg)
</pre></div> </code></pre>
<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> <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>nil</p> <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> <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>
<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">&#39;</span><span class="s">password&#39;</span><span class="p">)</span> <pre><code class="lua"> wifi.ap.config(ssid, 'password')
</pre></div> </code></pre>
<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> <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=""></a></p> <p><strong>-</strong> <a href=""></a></p>
<p><a id="wa_getip"></a></p> <p><a id="wa_getip"></a></p>
<h2 id="wifiapgetip"><a name="user-content-wifiapgetip" href="#wifiapgetip" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getip()</h2> <h2 id="wifiapgetip"><a name="user-content-wifiapgetip" href="#wifiapgetip" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getip()</h2>
<h4 id="description_28"><a name="user-content-description_28" href="#description_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_29"><a name="user-content-description_29" href="#description_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>get ip in ap mode.</p> <p>get ip in ap mode.</p>
<h4 id="syntax_28"><a name="user-content-syntax_28" href="#syntax_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_29"><a name="user-content-syntax_29" href="#syntax_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>wifi.ap.getip()</p> <p>wifi.ap.getip()</p>
<h4 id="parameters_28"><a name="user-content-parameters_28" href="#parameters_28" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_29"><a name="user-content-parameters_29" href="#parameters_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil</p> <p>nil</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> <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>ip address in string, for example:&rdquo;192.168.0.111&rdquo;</p> <p>ip address in string, for example:&rdquo;192.168.0.111&rdquo;</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> <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>
<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><code class="lua"> wifi.ap.getip()
</pre></div> </code></pre>
<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> <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_getmac">wifi.ap.getmac()</a></p> <p><strong>-</strong> <a href="#wa_getmac">wifi.ap.getmac()</a></p>
<p><a id="wa_getmac"></a></p> <p><a id="wa_getmac"></a></p>
<h2 id="wifiapgetmac"><a name="user-content-wifiapgetmac" href="#wifiapgetmac" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getmac()</h2> <h2 id="wifiapgetmac"><a name="user-content-wifiapgetmac" href="#wifiapgetmac" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>wifi.ap.getmac()</h2>
<h4 id="description_29"><a name="user-content-description_29" href="#description_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_30"><a name="user-content-description_30" href="#description_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>get mac address in ap mode.</p> <p>get mac address in ap mode.</p>
<h4 id="syntax_29"><a name="user-content-syntax_29" href="#syntax_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_30"><a name="user-content-syntax_30" href="#syntax_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>wifi.ap.getmac()</p> <p>wifi.ap.getmac()</p>
<h4 id="parameters_29"><a name="user-content-parameters_29" href="#parameters_29" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_30"><a name="user-content-parameters_30" href="#parameters_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil</p> <p>nil</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> <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>mac address in string, for example:&rdquo;1A-33-44-FE-55-BB&rdquo;</p> <p>mac address in string, for example:&rdquo;1A-33-44-FE-55-BB&rdquo;</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> <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>
<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><code class="lua"> wifi.ap.getmac()
</pre></div> </code></pre>
<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> <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="#wa_getip">wifi.ap.getip()</a></p> <p><strong>-</strong> <a href="#wa_getip">wifi.ap.getip()</a></p>
<h1 id="timer-module"><a name="user-content-timer-module" href="#timer-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>timer module</h1> <h1 id="timer-module"><a name="user-content-timer-module" href="#timer-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>timer module</h1>
<p><a id="tm_delay"></a></p> <p><a id="tm_delay"></a></p>
<h2 id="tmrdelay"><a name="user-content-tmrdelay" href="#tmrdelay" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.delay()</h2> <h2 id="tmrdelay"><a name="user-content-tmrdelay" href="#tmrdelay" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.delay()</h2>
<h4 id="description_30"><a name="user-content-description_30" href="#description_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_31"><a name="user-content-description_31" href="#description_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>delay us micro seconds.</p> <p>delay us micro seconds.</p>
<h4 id="syntax_30"><a name="user-content-syntax_30" href="#syntax_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_31"><a name="user-content-syntax_31" href="#syntax_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>tmr.dealy(us)</p> <p>tmr.dealy(us)</p>
<h4 id="parameters_30"><a name="user-content-parameters_30" href="#parameters_30" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_31"><a name="user-content-parameters_31" href="#parameters_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>us: delay time in micro second</p> <p>us: delay time in micro second</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> <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>nil</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- delay 100us</span> <pre><code class="lua"> -- delay 100us
<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> tmr.delay(100)
</pre></div> </code></pre>
<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> <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_now">tmr.now()</a></p> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<p><a id="tm_now"></a></p> <p><a id="tm_now"></a></p>
<h2 id="tmrnow"><a name="user-content-tmrnow" href="#tmrnow" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.now()</h2> <h2 id="tmrnow"><a name="user-content-tmrnow" href="#tmrnow" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.now()</h2>
<h4 id="description_31"><a name="user-content-description_31" href="#description_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_32"><a name="user-content-description_32" href="#description_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>return the current value of system counter: uint32, us.</p> <p>return the current value of system counter: uint32, us.</p>
<h4 id="syntax_31"><a name="user-content-syntax_31" href="#syntax_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_32"><a name="user-content-syntax_32" href="#syntax_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>tmr.now()</p> <p>tmr.now()</p>
<h4 id="parameters_31"><a name="user-content-parameters_31" href="#parameters_31" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_32"><a name="user-content-parameters_32" href="#parameters_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil</p> <p>nil</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> <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>uint32: value of counter</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- print current value of counter</span> <pre><code class="lua"> -- print current value of counter
<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> print(tmr.now())
</pre></div> </code></pre>
<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> <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_delay">tmr.delay()</a></p> <p><strong>-</strong> <a href="#tm_delay">tmr.delay()</a></p>
<p><a id="tm_alarm"></a></p> <p><a id="tm_alarm"></a></p>
<h2 id="tmralarm"><a name="user-content-tmralarm" href="#tmralarm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.alarm()</h2> <h2 id="tmralarm"><a name="user-content-tmralarm" href="#tmralarm" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.alarm()</h2>
<h4 id="description_32"><a name="user-content-description_32" href="#description_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_33"><a name="user-content-description_33" href="#description_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>alarm time.</p> <p>alarm time.</p>
<h4 id="syntax_32"><a name="user-content-syntax_32" href="#syntax_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_33"><a name="user-content-syntax_33" href="#syntax_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>tmr.alarm(interval, repeat, function do())</p> <p>tmr.alarm(interval, repeat, function do())</p>
<h4 id="parameters_32"><a name="user-content-parameters_32" href="#parameters_32" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_33"><a name="user-content-parameters_33" href="#parameters_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>Interval: alarm time, unit: millisecond<br /><br /> <p>Interval: alarm time, unit: millisecond<br /><br />
repeat: 0 - one time alarm, 1 - repeat<br /><br /> repeat: 0 - one time alarm, 1 - repeat<br /><br />
function do(): callback function for alarm timed out</p> 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- print &quot;hello world&quot; every 1000ms</span> <pre><code class="lua"> -- print &quot;hello world&quot; every 1000ms
<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">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span> tmr.alarm(1000, 1, function() print(&quot;hello world&quot;) end )
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<p><a id="tm_stop"></a></p> <p><a id="tm_stop"></a></p>
<h2 id="tmrstop"><a name="user-content-tmrstop" href="#tmrstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.stop()</h2> <h2 id="tmrstop"><a name="user-content-tmrstop" href="#tmrstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>tmr.stop()</h2>
<h4 id="description_33"><a name="user-content-description_33" href="#description_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_34"><a name="user-content-description_34" href="#description_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>stop alarm.<br /><br /> <p>stop alarm.<br /><br />
<strong>-Note:</strong> only one alarm is allowed, the previous one would be replaced if tmr.alarm() called again before tmr.stop().</p> <strong>-Note:</strong> only one alarm is allowed, the previous one would be replaced if tmr.alarm() called again before tmr.stop().</p>
<h4 id="syntax_33"><a name="user-content-syntax_33" href="#syntax_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_34"><a name="user-content-syntax_34" href="#syntax_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>tmr.stop()</p> <p>tmr.stop()</p>
<h4 id="parameters_33"><a name="user-content-parameters_33" href="#parameters_33" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_34"><a name="user-content-parameters_34" href="#parameters_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil.</p> <p>nil.</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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- print &quot;hello world&quot; every 1000ms</span> <pre><code class="lua"> -- print &quot;hello world&quot; every 1000ms
<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">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span> tmr.alarm(1000, 1, function() print(&quot;hello world&quot;) end )
<span class="c1">-- something else</span>
<span class="c1">-- stop alarm</span> -- something else
<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> <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="#tm_now">tmr.now()</a></p> <p><strong>-</strong> <a href="#tm_now">tmr.now()</a></p>
<h1 id="gpio-module"><a name="user-content-gpio-module" href="#gpio-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>GPIO module</h1> <h1 id="gpio-module"><a name="user-content-gpio-module" href="#gpio-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>GPIO module</h1>
<h2 id="constant_1"><a name="user-content-constant_1" href="#constant_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2> <h2 id="constant_1"><a name="user-content-constant_1" href="#constant_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2>
<p>gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW</p> <p>gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW</p>
<p><a id="io_mode"></a></p> <p><a id="io_mode"></a></p>
<h2 id="gpiomode"><a name="user-content-gpiomode" href="#gpiomode" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.mode()</h2> <h2 id="gpiomode"><a name="user-content-gpiomode" href="#gpiomode" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.mode()</h2>
<h4 id="description_34"><a name="user-content-description_34" href="#description_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_35"><a name="user-content-description_35" href="#description_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>initialize pin to GPIO mode, set the pin in/out mode.</p> <p>initialize pin to GPIO mode, set the pin in/out mode.</p>
<h4 id="syntax_34"><a name="user-content-syntax_34" href="#syntax_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_35"><a name="user-content-syntax_35" href="#syntax_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>gpio.mode(pin, mode)</p> <p>gpio.mode(pin, mode)</p>
<h4 id="parameters_34"><a name="user-content-parameters_34" href="#parameters_34" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_35"><a name="user-content-parameters_35" href="#parameters_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index<br /><br /> <p>pin: 0~11, IO index<br /><br />
mode: gpio.OUTPUT or gpio.INPUT, or gpio.INT(interrupt mode)</p> 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> <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>nil</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- set gpio 0 as output.</span> <pre><code class="lua"> -- set gpio 0 as output.
<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> gpio.mode(0, gpio.OUTPUT)
</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> <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_read">gpio.read()</a></p> <p><strong>-</strong> <a href="#io_read">gpio.read()</a></p>
<p><a id="io_read"></a></p> <p><a id="io_read"></a></p>
<h2 id="gpioread"><a name="user-content-gpioread" href="#gpioread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.read()</h2> <h2 id="gpioread"><a name="user-content-gpioread" href="#gpioread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.read()</h2>
<h4 id="description_35"><a name="user-content-description_35" href="#description_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_36"><a name="user-content-description_36" href="#description_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>read pin value.</p> <p>read pin value.</p>
<h4 id="syntax_35"><a name="user-content-syntax_35" href="#syntax_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_36"><a name="user-content-syntax_36" href="#syntax_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>gpio.read(pin)</p> <p>gpio.read(pin)</p>
<h4 id="parameters_35"><a name="user-content-parameters_35" href="#parameters_35" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_36"><a name="user-content-parameters_36" href="#parameters_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index</p> <p>pin: 0~11, IO index</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> <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>number:0 - low, 1 - high</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- read value of gpio 0.</span> <pre><code class="lua"> -- read value of gpio 0.
<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> gpio.read(0)
</pre></div> </code></pre>
<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> <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></p> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a></p>
<p><a id="io_write"></a></p> <p><a id="io_write"></a></p>
<h2 id="gpiowrite"><a name="user-content-gpiowrite" href="#gpiowrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.write()</h2> <h2 id="gpiowrite"><a name="user-content-gpiowrite" href="#gpiowrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.write()</h2>
<h4 id="description_36"><a name="user-content-description_36" href="#description_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_37"><a name="user-content-description_37" href="#description_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set pin value.</p> <p>set pin value.</p>
<h4 id="syntax_36"><a name="user-content-syntax_36" href="#syntax_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_37"><a name="user-content-syntax_37" href="#syntax_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>gpio.write(pin)</p> <p>gpio.write(pin)</p>
<h4 id="parameters_36"><a name="user-content-parameters_36" href="#parameters_36" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_37"><a name="user-content-parameters_37" href="#parameters_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index<br /><br /> <p>pin: 0~11, IO index<br /><br />
level: gpio.HIGH or gpio.LOW</p> 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- set pin index 1 to GPIO mode, and set the pin to high.</span> <pre><code class="lua"> -- set pin index 1 to GPIO mode, and set the pin to high.
<span class="n">pin</span><span class="o">=</span><span class="mi">1</span> pin=1
<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> gpio.mode(pin, gpio.OUTPUT)
<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> gpio.write(pin, gpio.HIGH)
</pre></div> </code></pre>
<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> <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 /> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
<strong>-</strong> <a href="#io_read">gpio.read()</a></p> <strong>-</strong> <a href="#io_read">gpio.read()</a></p>
<p><a id="io_trig"></a></p> <p><a id="io_trig"></a></p>
<h2 id="gpiotrig"><a name="user-content-gpiotrig" href="#gpiotrig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.trig()</h2> <h2 id="gpiotrig"><a name="user-content-gpiotrig" href="#gpiotrig" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>gpio.trig()</h2>
<h4 id="description_37"><a name="user-content-description_37" href="#description_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_38"><a name="user-content-description_38" href="#description_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set the interrupt callback function for pin.</p> <p>set the interrupt callback function for pin.</p>
<h4 id="syntax_37"><a name="user-content-syntax_37" href="#syntax_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_38"><a name="user-content-syntax_38" href="#syntax_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>gpio.trig(pin, type, function(level))</p> <p>gpio.trig(pin, type, function(level))</p>
<h4 id="parameters_37"><a name="user-content-parameters_37" href="#parameters_37" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_38"><a name="user-content-parameters_38" href="#parameters_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index<br /><br /> <p>pin: 0~11, IO index<br /><br />
type: &ldquo;up&rdquo;, &ldquo;down&rdquo;, &ldquo;both&rdquo;, &ldquo;low&rdquo;, &ldquo;high&rdquo;, which represent rising edge, falling edge, both edge, low level, high level trig mode separately.<br /><br /> type: &ldquo;up&rdquo;, &ldquo;down&rdquo;, &ldquo;both&rdquo;, &ldquo;low&rdquo;, &ldquo;high&rdquo;, which represent rising edge, falling edge, both edge, low level, high level trig mode separately.<br /><br />
function(level): callback function when triggered. The gpio level is the param. Use previous callback function if undefined here.</p> function(level): callback function when triggered. The gpio level is the param. Use previous callback function if undefined here.</p>
<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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- use pin 0 as the input pulse width counter</span> <pre><code class="lua"> -- use pin 0 as the input pulse width counter
<span class="n">pulse0</span> <span class="o">=</span> <span class="mi">0</span> pulse0 = 0
<span class="n">du</span> <span class="o">=</span> <span class="mi">0</span> du = 0
<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> gpio.mode(0,gpio.INT)
<span class="k">function</span> <span class="nf">pin0cb</span><span class="p">(</span><span class="n">level</span><span class="p">)</span> function pin0cb(level)
<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> du = tmr.now() – pulse0
<span class="nb">print</span><span class="p">(</span><span class="n">du</span><span class="p">)</span> print(du)
<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> pulse0 = tmr.now()
<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">&quot;</span><span class="s">down &quot;</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">&quot;</span><span class="s">up &quot;</span><span class="p">)</span> <span class="k">end</span> if level == 1 then gpio.trig(0, &quot;down &quot;) else gpio.trig(0, &quot;up &quot;) end
<span class="k">end</span> end
<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">&quot;</span><span class="s">down &quot;</span><span class="p">,</span><span class="n">pin0cb</span><span class="p">)</span> gpio.trig(0, &quot;down &quot;,pin0cb)
</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> <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="#io_mode">gpio.mode()</a><br /><br /> <p><strong>-</strong> <a href="#io_mode">gpio.mode()</a><br /><br />
<strong>-</strong> <a href="#io_write">gpio.write()</a></p> <strong>-</strong> <a href="#io_write">gpio.write()</a></p>
<h1 id="pwm-module"><a name="user-content-pwm-module" href="#pwm-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>PWM module</h1> <h1 id="pwm-module"><a name="user-content-pwm-module" href="#pwm-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>PWM module</h1>
<p><a id="pw_setup"></a></p> <p><a id="pw_setup"></a></p>
<h2 id="pwmsetup"><a name="user-content-pwmsetup" href="#pwmsetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setup()</h2> <h2 id="pwmsetup"><a name="user-content-pwmsetup" href="#pwmsetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setup()</h2>
<h4 id="description_38"><a name="user-content-description_38" href="#description_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_39"><a name="user-content-description_39" href="#description_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.</p> <p>set pin to PWM mode. Only 3 pins can be set to PWM mode at the most.</p>
<h4 id="syntax_38"><a name="user-content-syntax_38" href="#syntax_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_39"><a name="user-content-syntax_39" href="#syntax_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.setup(pin, clock, duty)</p> <p>pwm.setup(pin, clock, duty)</p>
<h4 id="parameters_38"><a name="user-content-parameters_38" href="#parameters_38" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_39"><a name="user-content-parameters_39" href="#parameters_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index<br /><br /> <p>pin: 0~11, IO index<br /><br />
clock: 1~500, pwm frequency<br /><br /> clock: 1~500, pwm frequency<br /><br />
duty: 0~100, pwm duty cycle in percentage</p> 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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.</span> <pre><code class="lua"> -- set pin index 0 as pwm output, frequency is 100Hz, duty cycle is 50-50.
<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> pwm.setup(0, 100, 50)
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_close"></a></p> <p><a id="pw_close"></a></p>
<h2 id="pwmclose"><a name="user-content-pwmclose" href="#pwmclose" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.close()</h2> <h2 id="pwmclose"><a name="user-content-pwmclose" href="#pwmclose" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.close()</h2>
<h4 id="description_39"><a name="user-content-description_39" href="#description_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_40"><a name="user-content-description_40" href="#description_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>quit PWM mode for specified pin.</p> <p>quit PWM mode for specified pin.</p>
<h4 id="syntax_39"><a name="user-content-syntax_39" href="#syntax_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_40"><a name="user-content-syntax_40" href="#syntax_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.close(pin)</p> <p>pwm.close(pin)</p>
<h4 id="parameters_39"><a name="user-content-parameters_39" href="#parameters_39" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_40"><a name="user-content-parameters_40" href="#parameters_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index</p> <p>pin: 0~11, IO index</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> <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> <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> <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>
<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><code class="lua"> pwm.close(0)
</pre></div> </code></pre>
<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> <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_start">pwm.start()</a></p> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_start"></a></p> <p><a id="pw_start"></a></p>
<h2 id="pwmstart"><a name="user-content-pwmstart" href="#pwmstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.start()</h2> <h2 id="pwmstart"><a name="user-content-pwmstart" href="#pwmstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.start()</h2>
<h4 id="description_40"><a name="user-content-description_40" href="#description_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_41"><a name="user-content-description_41" href="#description_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>pwm starts, you can detect the waveform on the gpio.</p> <p>pwm starts, you can detect the waveform on the gpio.</p>
<h4 id="syntax_40"><a name="user-content-syntax_40" href="#syntax_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_41"><a name="user-content-syntax_41" href="#syntax_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.start(pin)</p> <p>pwm.start(pin)</p>
<h4 id="parameters_40"><a name="user-content-parameters_40" href="#parameters_40" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_41"><a name="user-content-parameters_41" href="#parameters_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index</p> <p>pin: 0~11, IO index</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> <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> <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> <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>
<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><code class="lua"> pwm.start(0)
</pre></div> </code></pre>
<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> <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_stop">pwm.stop()</a></p> <p><strong>-</strong> <a href="#pw_stop">pwm.stop()</a></p>
<p><a id="pw_stop"></a></p> <p><a id="pw_stop"></a></p>
<h2 id="pwmstop"><a name="user-content-pwmstop" href="#pwmstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.stop()</h2> <h2 id="pwmstop"><a name="user-content-pwmstop" href="#pwmstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.stop()</h2>
<h4 id="description_41"><a name="user-content-description_41" href="#description_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_42"><a name="user-content-description_42" href="#description_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>pause the output of PWM waveform.</p> <p>pause the output of PWM waveform.</p>
<h4 id="syntax_41"><a name="user-content-syntax_41" href="#syntax_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_42"><a name="user-content-syntax_42" href="#syntax_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.stop(pin)</p> <p>pwm.stop(pin)</p>
<h4 id="parameters_41"><a name="user-content-parameters_41" href="#parameters_41" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_42"><a name="user-content-parameters_42" href="#parameters_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index</p> <p>pin: 0~11, IO index</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> <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> <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> <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>
<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><code class="lua"> pwm.stop(0)
</pre></div> </code></pre>
<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> <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_start">pwm.start()</a></p> <p><strong>-</strong> <a href="#pw_start">pwm.start()</a></p>
<p><a id="pw_setclock"></a></p> <p><a id="pw_setclock"></a></p>
<h2 id="pwmsetclock"><a name="user-content-pwmsetclock" href="#pwmsetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setclock()</h2> <h2 id="pwmsetclock"><a name="user-content-pwmsetclock" href="#pwmsetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setclock()</h2>
<h4 id="description_42"><a name="user-content-description_42" href="#description_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_43"><a name="user-content-description_43" href="#description_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set pwm frequency for pin.<br /><br /> <p>set pwm frequency for pin.<br /><br />
<strong>-Note:</strong> setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.</p> <strong>-Note:</strong> setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.</p>
<h4 id="syntax_42"><a name="user-content-syntax_42" href="#syntax_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_43"><a name="user-content-syntax_43" href="#syntax_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.setclock(pin, clock)</p> <p>pwm.setclock(pin, clock)</p>
<h4 id="parameters_42"><a name="user-content-parameters_42" href="#parameters_42" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_43"><a name="user-content-parameters_43" href="#parameters_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index.<br /><br /> <p>pin: 0~11, IO index.<br /><br />
clock: 1~500, pwm frequency.</p> 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> <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>nil</p> <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> <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>
<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><code class="lua"> pwm.setclock(0, 100)
</pre></div> </code></pre>
<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> <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_getclock">pwm.getclock()</a></p> <p><strong>-</strong> <a href="#pw_getclock">pwm.getclock()</a></p>
<p><a id="pw_getclock"></a></p> <p><a id="pw_getclock"></a></p>
<h2 id="pwmgetclock"><a name="user-content-pwmgetclock" href="#pwmgetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getclock()</h2> <h2 id="pwmgetclock"><a name="user-content-pwmgetclock" href="#pwmgetclock" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getclock()</h2>
<h4 id="description_43"><a name="user-content-description_43" href="#description_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_44"><a name="user-content-description_44" href="#description_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>get pwm frequency of pin.</p> <p>get pwm frequency of pin.</p>
<h4 id="syntax_43"><a name="user-content-syntax_43" href="#syntax_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_44"><a name="user-content-syntax_44" href="#syntax_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.getclock(pin)</p> <p>pwm.getclock(pin)</p>
<h4 id="parameters_43"><a name="user-content-parameters_43" href="#parameters_43" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_44"><a name="user-content-parameters_44" href="#parameters_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index.</p> <p>pin: 0~11, IO index.</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> <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>number:pwm frequency of pin</p> <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> <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>
<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><code class="lua"> print(pwm.getclock(0))
</pre></div> </code></pre>
<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> <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_setclock">pwm.setclock()</a></p> <p><strong>-</strong> <a href="#pw_setclock">pwm.setclock()</a></p>
<p><a id="pw_setduty"></a></p> <p><a id="pw_setduty"></a></p>
<h2 id="pwmsetduty"><a name="user-content-pwmsetduty" href="#pwmsetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setduty()</h2> <h2 id="pwmsetduty"><a name="user-content-pwmsetduty" href="#pwmsetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.setduty()</h2>
<h4 id="description_44"><a name="user-content-description_44" href="#description_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_45"><a name="user-content-description_45" href="#description_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>set duty clycle for pin.</p> <p>set duty clycle for pin.</p>
<h4 id="syntax_44"><a name="user-content-syntax_44" href="#syntax_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_45"><a name="user-content-syntax_45" href="#syntax_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.setduty(pin, duty)</p> <p>pwm.setduty(pin, duty)</p>
<h4 id="parameters_44"><a name="user-content-parameters_44" href="#parameters_44" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_45"><a name="user-content-parameters_45" href="#parameters_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index<br /><br /> <p>pin: 0~11, IO index<br /><br />
duty: 0~100, pwm duty cycle in percentage</p> 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> <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> <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> <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>
<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><code class="lua"> pwm.setduty(0, 50)
</pre></div> </code></pre>
<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> <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_getduty">pwm.getduty()</a></p> <p><strong>-</strong> <a href="#pw_getduty">pwm.getduty()</a></p>
<p><a id="pw_getduty"></a></p> <p><a id="pw_getduty"></a></p>
<h2 id="pwmgetduty"><a name="user-content-pwmgetduty" href="#pwmgetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getduty()</h2> <h2 id="pwmgetduty"><a name="user-content-pwmgetduty" href="#pwmgetduty" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>pwm.getduty()</h2>
<h4 id="description_45"><a name="user-content-description_45" href="#description_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_46"><a name="user-content-description_46" href="#description_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>get duty clycle for pin.</p> <p>get duty clycle for pin.</p>
<h4 id="syntax_45"><a name="user-content-syntax_45" href="#syntax_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_46"><a name="user-content-syntax_46" href="#syntax_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>pwm.getduty(pin)</p> <p>pwm.getduty(pin)</p>
<h4 id="parameters_45"><a name="user-content-parameters_45" href="#parameters_45" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_46"><a name="user-content-parameters_46" href="#parameters_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>pin: 0~11, IO index</p> <p>pin: 0~11, IO index</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> <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>nil</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- D0 is connected to green led</span> <pre><code class="lua"> -- D0 is connected to green led
<span class="c1">-- D1 is connected to blue led</span> -- D1 is connected to blue led
<span class="c1">-- D2 is connected to red led</span> -- D2 is connected to red led
<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> pwm.setup(0,500,50)
<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> pwm.setup(1,500,50)
<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> pwm.setup(2,500,50)
<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> pwm.start(0)
<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> pwm.start(1)
<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> pwm.start(2)
<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> function led(r,g,b)
<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> pwm.setduty(0,g)
<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> pwm.setduty(1,b)
<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> pwm.setduty(2,r)
<span class="k">end</span> end
<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> led(50,0,0) -- set led to red
<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> led(0,0,50) -- set led to blue.
</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> <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="#pw_setduty">pwm.setduty()</a></p> <p><strong>-</strong> <a href="#pw_setduty">pwm.setduty()</a></p>
<h1 id="net-module"><a name="user-content-net-module" href="#net-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net module</h1> <h1 id="net-module"><a name="user-content-net-module" href="#net-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net module</h1>
<h2 id="constant_2"><a name="user-content-constant_2" href="#constant_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2> <h2 id="constant_2"><a name="user-content-constant_2" href="#constant_2" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2>
<p>net.TCP, net.UDP</p> <p>net.TCP, net.UDP</p>
<p><a id="nt_createServer"></a></p> <p><a id="nt_createServer"></a></p>
<h2 id="netcreateserver"><a name="user-content-netcreateserver" href="#netcreateserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createServer()</h2> <h2 id="netcreateserver"><a name="user-content-netcreateserver" href="#netcreateserver" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createServer()</h2>
<h4 id="description_46"><a name="user-content-description_46" href="#description_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_47"><a name="user-content-description_47" href="#description_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>create a server.</p> <p>create a server.</p>
<h4 id="syntax_46"><a name="user-content-syntax_46" href="#syntax_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_47"><a name="user-content-syntax_47" href="#syntax_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>net.createServer(type, secure)</p> <p>net.createServer(type, secure)</p>
<h4 id="parameters_46"><a name="user-content-parameters_46" href="#parameters_46" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_47"><a name="user-content-parameters_47" href="#parameters_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>type: net.TCP or net.UDP<br /><br /> <p>type: net.TCP or net.UDP<br /><br />
secure: true or false, true for safe link, false for ordinary link</p> 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> <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> <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> <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>
<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><code class="lua"> net.createServer(net.TCP, true)
</pre></div> </code></pre>
<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> <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_createConnection">net.createConnection()</a></p> <p><strong>-</strong> <a href="#nt_createConnection">net.createConnection()</a></p>
<p><a id="nt_createConnection"></a></p> <p><a id="nt_createConnection"></a></p>
<h2 id="netcreateconnection"><a name="user-content-netcreateconnection" href="#netcreateconnection" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createConnection()</h2> <h2 id="netcreateconnection"><a name="user-content-netcreateconnection" href="#netcreateconnection" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.createConnection()</h2>
<h4 id="description_47"><a name="user-content-description_47" href="#description_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_48"><a name="user-content-description_48" href="#description_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>create a client.</p> <p>create a client.</p>
<h4 id="syntax_47"><a name="user-content-syntax_47" href="#syntax_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_48"><a name="user-content-syntax_48" href="#syntax_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>net.createConnection(type, secure)</p> <p>net.createConnection(type, secure)</p>
<h4 id="parameters_47"><a name="user-content-parameters_47" href="#parameters_47" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_48"><a name="user-content-parameters_48" href="#parameters_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>type: net.TCP or net.UDP<br /><br /> <p>type: net.TCP or net.UDP<br /><br />
secure: true or false, true for safe link, false for ordinary link</p> 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> <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>net.server sub module</p> <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> <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>
<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><code class="lua"> net.createConnection(net.UDP, false)
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="netserver-module"><a name="user-content-netserver-module" href="#netserver-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.server module</h1> <h1 id="netserver-module"><a name="user-content-netserver-module" href="#netserver-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.server module</h1>
<p><a id="ns_listen"></a></p> <p><a id="ns_listen"></a></p>
<h2 id="listen"><a name="user-content-listen" href="#listen" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>listen()</h2> <h2 id="listen"><a name="user-content-listen" href="#listen" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>listen()</h2>
<h4 id="description_48"><a name="user-content-description_48" href="#description_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_49"><a name="user-content-description_49" href="#description_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>listen on port from [ip] address.</p> <p>listen on port from [ip] address.</p>
<h4 id="syntax_48"><a name="user-content-syntax_48" href="#syntax_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_49"><a name="user-content-syntax_49" href="#syntax_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>net.server.listen(port,[ip],function(net.socket))</p> <p>net.server.listen(port,[ip],function(net.socket))</p>
<h4 id="parameters_48"><a name="user-content-parameters_48" href="#parameters_48" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_49"><a name="user-content-parameters_49" href="#parameters_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>port: port number<br /><br /> <p>port: port number<br /><br />
ip:ip address string, can be omitted<br /><br /> ip:ip address string, can be omitted<br /><br />
function(net.socket): callback function, pass to Caller function as param if a connection is created successfully</p> function(net.socket): callback function, pass to Caller function as param if a connection is created successfully</p>
<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> <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> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- create a server</span> <pre><code class="lua"> -- create a server
<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> sv=net.createServer(net.TCP, false)
<span class="c1">-- server listen on 80, if data received, print data to console, and send &quot;hello world&quot; to remote.</span> -- server listen on 80, if data received, print data to console, and send &quot;hello world&quot; to remote.
<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> sv:listen(80,function(c)
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> c:on(&quot;receive&quot;, function(sck, pl) print(pl) end)
<span class="n">c</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">hello world&quot;</span><span class="p">)</span> c:send(&quot;hello world&quot;)
<span class="k">end</span><span class="p">)</span> end)
</pre></div> </code></pre>
<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> <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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="ns_close"></a></p> <p><a id="ns_close"></a></p>
<h2 id="close"><a name="user-content-close" href="#close" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2> <h2 id="close"><a name="user-content-close" href="#close" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2>
<h4 id="description_49"><a name="user-content-description_49" href="#description_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_50"><a name="user-content-description_50" href="#description_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>close server.</p> <p>close server.</p>
<h4 id="syntax_49"><a name="user-content-syntax_49" href="#syntax_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_50"><a name="user-content-syntax_50" href="#syntax_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>net.server.close()</p> <p>net.server.close()</p>
<h4 id="parameters_49"><a name="user-content-parameters_49" href="#parameters_49" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_50"><a name="user-content-parameters_50" href="#parameters_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil</p> <p>nil</p>
<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> <h4 id="returns_50"><a name="user-content-returns_50" href="#returns_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <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> <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>
<div class="codehilite"><pre> <span class="c1">-- create a server</span> <pre><code class="lua"> -- create a server
<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> sv=net.createServer(net.TCP, false)
<span class="c1">-- close server</span> -- close server
<span class="n">sv</span><span class="p">:</span><span class="n">close</span><span class="p">()</span> sv:close()
</pre></div> </code></pre>
<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> <h4 id="see-also_50"><a name="user-content-see-also_50" href="#see-also_50" 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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="netsocket-module"><a name="user-content-netsocket-module" href="#netsocket-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.socket module</h1> <h1 id="netsocket-module"><a name="user-content-netsocket-module" href="#netsocket-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>net.socket module</h1>
<p><a id="nk_connect"></a></p> <p><a id="nk_connect"></a></p>
<h2 id="connect"><a name="user-content-connect" href="#connect" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>connect()</h2> <h2 id="connect"><a name="user-content-connect" href="#connect" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>connect()</h2>
<h4 id="description_50"><a name="user-content-description_50" href="#description_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_51"><a name="user-content-description_51" href="#description_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>connect to remote.</p> <p>connect to remote.</p>
<h4 id="syntax_50"><a name="user-content-syntax_50" href="#syntax_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_51"><a name="user-content-syntax_51" href="#syntax_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>connect(port, ip)</p> <p>connect(port, ip)</p>
<h4 id="parameters_50"><a name="user-content-parameters_50" href="#parameters_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_51"><a name="user-content-parameters_51" href="#parameters_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>port: port number<br /><br /> <p>port: port number<br /><br />
ip: ip address in string</p> ip: ip address in string</p>
<h4 id="returns_50"><a name="user-content-returns_50" href="#returns_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_51"><a name="user-content-returns_51" href="#returns_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_50"><a name="user-content-see-also_50" href="#see-also_50" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_51"><a name="user-content-see-also_51" href="#see-also_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
<p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p> <p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p>
<p><a id="nk_send"></a></p> <p><a id="nk_send"></a></p>
<h2 id="send"><a name="user-content-send" href="#send" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>send()</h2> <h2 id="send"><a name="user-content-send" href="#send" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>send()</h2>
<h4 id="description_51"><a name="user-content-description_51" href="#description_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_52"><a name="user-content-description_52" href="#description_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>send data to remote via connection.</p> <p>send data to remote via connection.</p>
<h4 id="syntax_51"><a name="user-content-syntax_51" href="#syntax_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_52"><a name="user-content-syntax_52" href="#syntax_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>send(string, function(sent))</p> <p>send(string, function(sent))</p>
<h4 id="parameters_51"><a name="user-content-parameters_51" href="#parameters_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_52"><a name="user-content-parameters_52" href="#parameters_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>string: data in string which will be sent to remote<br /><br /> <p>string: data in string which will be sent to remote<br /><br />
function(sent): callback function for sending string</p> function(sent): callback function for sending string</p>
<h4 id="returns_51"><a name="user-content-returns_51" href="#returns_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <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> <p>nil</p>
<h4 id="see-also_51"><a name="user-content-see-also_51" href="#see-also_51" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <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="#nk_on">net.socket:on()</a></p> <p><strong>-</strong> <a href="#nk_on">net.socket:on()</a></p>
<p><a id="nk_on"></a></p> <p><a id="nk_on"></a></p>
<h2 id="on"><a name="user-content-on" href="#on" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>on()</h2> <h2 id="on"><a name="user-content-on" href="#on" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>on()</h2>
<h4 id="description_52"><a name="user-content-description_52" href="#description_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_53"><a name="user-content-description_53" href="#description_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>register callback function for event.</p> <p>register callback function for event.</p>
<h4 id="syntax_52"><a name="user-content-syntax_52" href="#syntax_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_53"><a name="user-content-syntax_53" href="#syntax_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>on(event, function cb())</p> <p>on(event, function cb())</p>
<h4 id="parameters_52"><a name="user-content-parameters_52" href="#parameters_52" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_53"><a name="user-content-parameters_53" href="#parameters_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>event: string, which can be: &ldquo;connection&rdquo;, &ldquo;reconnection&rdquo;, &ldquo;disconnection&rdquo;, &ldquo;receive&rdquo;, &ldquo;sent&rdquo;<br /><br /> <p>event: string, which can be: &ldquo;connection&rdquo;, &ldquo;reconnection&rdquo;, &ldquo;disconnection&rdquo;, &ldquo;receive&rdquo;, &ldquo;sent&rdquo;<br /><br />
function cb(net.socket, [string]): callback function. The first param is the socket.<br /><br /> function cb(net.socket, [string]): callback function. The first param is the socket.<br /><br />
If event is&rdquo;receive&rdquo;, the second param is received data in string.</p> If event is&rdquo;receive&rdquo;, the second param is received data in string.</p>
<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> <h4 id="returns_53"><a name="user-content-returns_53" href="#returns_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <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> <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>
<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> <pre><code class="lua"> sk=net.createConnection(net.TCP, false)
<span class="n">sk</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">&quot;</span><span class="s">receive&quot;</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> sk:on(&quot;receive&quot;, function(sck, c) print(c) end )
<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">&quot;</span><span class="s">192.168.0.66&quot;</span><span class="p">)</span> sk:connect(80,&quot;192.168.0.66&quot;)
<span class="n">sk</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</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">&quot;</span><span class="p">)</span> sk:send(&quot;GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n&quot;)
</pre></div> </code></pre>
<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> <h4 id="see-also_53"><a name="user-content-see-also_53" href="#see-also_53" 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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="nk_close"></a></p> <p><a id="nk_close"></a></p>
<h2 id="close_1"><a name="user-content-close_1" href="#close_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2> <h2 id="close_1"><a name="user-content-close_1" href="#close_1" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>close()</h2>
<h4 id="description_53"><a name="user-content-description_53" href="#description_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_54"><a name="user-content-description_54" href="#description_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>close socket.</p> <p>close socket.</p>
<h4 id="syntax_53"><a name="user-content-syntax_53" href="#syntax_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_54"><a name="user-content-syntax_54" href="#syntax_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>close()</p> <p>close()</p>
<h4 id="parameters_53"><a name="user-content-parameters_53" href="#parameters_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_54"><a name="user-content-parameters_54" href="#parameters_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>nil</p> <p>nil</p>
<h4 id="returns_53"><a name="user-content-returns_53" href="#returns_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_54"><a name="user-content-returns_54" href="#returns_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_53"><a name="user-content-see-also_53" href="#see-also_53" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_54"><a name="user-content-see-also_54" href="#see-also_54" 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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<p><a id="nk_dns"></a></p> <p><a id="nk_dns"></a></p>
<h2 id="dns"><a name="user-content-dns" href="#dns" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>dns()</h2> <h2 id="dns"><a name="user-content-dns" href="#dns" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>dns()</h2>
<h4 id="description_54"><a name="user-content-description_54" href="#description_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_55"><a name="user-content-description_55" href="#description_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>get domain ip</p> <p>get domain ip</p>
<h4 id="syntax_54"><a name="user-content-syntax_54" href="#syntax_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_55"><a name="user-content-syntax_55" href="#syntax_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>dns(domain, function(net.socket, ip))</p> <p>dns(domain, function(net.socket, ip))</p>
<h4 id="parameters_54"><a name="user-content-parameters_54" href="#parameters_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_55"><a name="user-content-parameters_55" href="#parameters_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>domain: domain name.<br /><br /> <p>domain: domain name.<br /><br />
function (net.socket, ip): callback function. The first param is the socket, the second param is the ip address in string.</p> function (net.socket, ip): callback function. The first param is the socket, the second param is the ip address in string.</p>
<h4 id="returns_54"><a name="user-content-returns_54" href="#returns_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_55"><a name="user-content-returns_55" href="#returns_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_54"><a name="user-content-see-also_54" href="#see-also_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_55"><a name="user-content-see-also_55" href="#see-also_55" 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> <p><strong>-</strong> <a href="#nt_createServer">net.createServer()</a></p>
<h1 id="i2c-module"><a name="user-content-i2c-module" href="#i2c-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c module</h1> <h1 id="i2c-module"><a name="user-content-i2c-module" href="#i2c-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c module</h1>
<h2 id="constant_3"><a name="user-content-constant_3" href="#constant_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2> <h2 id="constant_3"><a name="user-content-constant_3" href="#constant_3" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2>
<p>i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.</p> <p>i2c.SLOW, i2c.TRANSMITTER, i2c. RECEIVER. FAST(400k)is not supported for now.</p>
<p><a id="ic_setup"></a></p> <p><a id="ic_setup"></a></p>
<h2 id="i2csetup"><a name="user-content-i2csetup" href="#i2csetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.setup()</h2> <h2 id="i2csetup"><a name="user-content-i2csetup" href="#i2csetup" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.setup()</h2>
<h4 id="description_55"><a name="user-content-description_55" href="#description_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_56"><a name="user-content-description_56" href="#description_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>initialize i2c.</p> <p>initialize i2c.</p>
<h4 id="syntax_55"><a name="user-content-syntax_55" href="#syntax_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_56"><a name="user-content-syntax_56" href="#syntax_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.setup(id, pinSDA, pinSCL, speed)</p> <p>i2c.setup(id, pinSDA, pinSCL, speed)</p>
<h4 id="parameters_55"><a name="user-content-parameters_55" href="#parameters_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_56"><a name="user-content-parameters_56" href="#parameters_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id = 0<br /><br /> <p>id = 0<br /><br />
pinSDA: 0~11, IO index<br /><br /> pinSDA: 0~11, IO index<br /><br />
pinSCL: 0~11, IO index<br /><br /> pinSCL: 0~11, IO index<br /><br />
speed: i2c.SLOW</p> speed: i2c.SLOW</p>
<h4 id="returns_55"><a name="user-content-returns_55" href="#returns_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_56"><a name="user-content-returns_56" href="#returns_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_55"><a name="user-content-see-also_55" href="#see-also_55" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_56"><a name="user-content-see-also_56" href="#see-also_56" 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> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_start"></a></p> <p><a id="ic_start"></a></p>
<h2 id="i2cstart"><a name="user-content-i2cstart" href="#i2cstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.start()</h2> <h2 id="i2cstart"><a name="user-content-i2cstart" href="#i2cstart" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.start()</h2>
<h4 id="description_56"><a name="user-content-description_56" href="#description_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_57"><a name="user-content-description_57" href="#description_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>start i2c transporting.</p> <p>start i2c transporting.</p>
<h4 id="syntax_56"><a name="user-content-syntax_56" href="#syntax_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_57"><a name="user-content-syntax_57" href="#syntax_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.start(id)</p> <p>i2c.start(id)</p>
<h4 id="parameters_56"><a name="user-content-parameters_56" href="#parameters_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_57"><a name="user-content-parameters_57" href="#parameters_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id = 0</p> <p>id = 0</p>
<h4 id="returns_56"><a name="user-content-returns_56" href="#returns_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_57"><a name="user-content-returns_57" href="#returns_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_56"><a name="user-content-see-also_56" href="#see-also_56" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_57"><a name="user-content-see-also_57" href="#see-also_57" 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> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_stop"></a></p> <p><a id="ic_stop"></a></p>
<h2 id="i2cstop"><a name="user-content-i2cstop" href="#i2cstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.stop()</h2> <h2 id="i2cstop"><a name="user-content-i2cstop" href="#i2cstop" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.stop()</h2>
<h4 id="description_57"><a name="user-content-description_57" href="#description_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_58"><a name="user-content-description_58" href="#description_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>stop i2c transporting.</p> <p>stop i2c transporting.</p>
<h4 id="syntax_57"><a name="user-content-syntax_57" href="#syntax_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_58"><a name="user-content-syntax_58" href="#syntax_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.stop(id)</p> <p>i2c.stop(id)</p>
<h4 id="parameters_57"><a name="user-content-parameters_57" href="#parameters_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_58"><a name="user-content-parameters_58" href="#parameters_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id = 0</p> <p>id = 0</p>
<h4 id="returns_57"><a name="user-content-returns_57" href="#returns_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <h4 id="returns_58"><a name="user-content-returns_58" href="#returns_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>nil</p> <p>nil</p>
<h4 id="see-also_57"><a name="user-content-see-also_57" href="#see-also_57" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <h4 id="see-also_58"><a name="user-content-see-also_58" href="#see-also_58" 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> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_address"></a></p> <p><a id="ic_address"></a></p>
<h2 id="i2caddress"><a name="user-content-i2caddress" href="#i2caddress" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.address()</h2> <h2 id="i2caddress"><a name="user-content-i2caddress" href="#i2caddress" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.address()</h2>
<h4 id="description_58"><a name="user-content-description_58" href="#description_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_59"><a name="user-content-description_59" href="#description_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>setup i2c address and read/write mode.</p> <p>setup i2c address and read/write mode.</p>
<h4 id="syntax_58"><a name="user-content-syntax_58" href="#syntax_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_59"><a name="user-content-syntax_59" href="#syntax_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.address(id, device_addr, direction)</p> <p>i2c.address(id, device_addr, direction)</p>
<h4 id="parameters_58"><a name="user-content-parameters_58" href="#parameters_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_59"><a name="user-content-parameters_59" href="#parameters_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
device_addr: device address.<br /><br /> device_addr: device address.<br /><br />
direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode</p> direction: i2c.TRANSMITTER for writing mode , i2c. RECEIVER for reading mode</p>
<h4 id="returns_58"><a name="user-content-returns_58" href="#returns_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4> <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> <p>nil</p>
<h4 id="see-also_58"><a name="user-content-see-also_58" href="#see-also_58" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4> <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> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_write"></a></p> <p><a id="ic_write"></a></p>
<h2 id="i2cwrite"><a name="user-content-i2cwrite" href="#i2cwrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.write()</h2> <h2 id="i2cwrite"><a name="user-content-i2cwrite" href="#i2cwrite" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.write()</h2>
<h4 id="description_59"><a name="user-content-description_59" href="#description_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_60"><a name="user-content-description_60" href="#description_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>write data to i2c, data can be multi numbers, string or lua table.</p> <p>write data to i2c, data can be multi numbers, string or lua table.</p>
<h4 id="syntax_59"><a name="user-content-syntax_59" href="#syntax_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_60"><a name="user-content-syntax_60" href="#syntax_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.write(id, data1, data2,&hellip;)</p> <p>i2c.write(id, data1, data2,&hellip;)</p>
<h4 id="parameters_59"><a name="user-content-parameters_59" href="#parameters_59" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_60"><a name="user-content-parameters_60" href="#parameters_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
data: data can be numbers, string or lua table.</p> 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> <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>nil</p> <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> <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>
<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">&quot;</span><span class="s">hello&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="s">world&quot;</span><span class="p">)</span> <pre><code class="lua"> i2c.write(0, &quot;hello&quot;, &quot;world&quot;)
</pre></div> </code></pre>
<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> <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_read">i2c.read()</a></p> <p><strong>-</strong> <a href="#ic_read">i2c.read()</a></p>
<p><a id="ic_read"></a></p> <p><a id="ic_read"></a></p>
<h2 id="i2cread"><a name="user-content-i2cread" href="#i2cread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.read()</h2> <h2 id="i2cread"><a name="user-content-i2cread" href="#i2cread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>i2c.read()</h2>
<h4 id="description_60"><a name="user-content-description_60" href="#description_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4> <h4 id="description_61"><a name="user-content-description_61" href="#description_61" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>read data for len bytes.</p> <p>read data for len bytes.</p>
<h4 id="syntax_60"><a name="user-content-syntax_60" href="#syntax_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4> <h4 id="syntax_61"><a name="user-content-syntax_61" href="#syntax_61" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>i2c.read(id, len)</p> <p>i2c.read(id, len)</p>
<h4 id="parameters_60"><a name="user-content-parameters_60" href="#parameters_60" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4> <h4 id="parameters_61"><a name="user-content-parameters_61" href="#parameters_61" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id=0<br /><br /> <p>id=0<br /><br />
len: data length</p> 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> <h4 id="returns_61"><a name="user-content-returns_61" href="#returns_61" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>string:data received.</p> <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> <h4 id="example_54"><a name="user-content-example_54" href="#example_54" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Example</h4>
<div class="codehilite"><pre> <span class="n">id</span><span class="o">=</span><span class="mi">0</span> <pre><code class="lua"> id=0
<span class="n">sda</span><span class="o">=</span><span class="mi">1</span> sda=1
<span class="n">scl</span><span class="o">=</span><span class="mi">0</span> scl=0
<span class="c1">-- initialize i2c, set pin1 as sda, set pin0 as scl</span> -- initialize i2c, set pin1 as sda, set pin0 as scl
<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> i2c.setup(id,sda,scl,i2c.SLOW)
<span class="c1">-- user defined function: read from reg_addr content of dev_addr</span> -- user defined function: read from reg_addr content of dev_addr
<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> function read_reg(dev_addr, reg_addr)
<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> i2c.start(id)
<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> i2c.address(id, dev_addr ,i2c.TRANSMITTER)
<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> i2c.write(id,reg_addr)
<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> i2c.stop(id)
<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> i2c.start(id)
<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> i2c.address(id, dev_addr,i2c.RECEIVER)
<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> c=i2c.read(id,1)
<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> i2c.stop(id)
<span class="k">return</span> <span class="n">c</span> return c
<span class="k">end</span> end
<span class="c1">-- get content of register 0xAA of device 0x77</span> -- get content of register 0xAA of device 0x77
<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> reg = read_reg(0x77, 0xAA)
<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> pirnt(string.byte(reg))
</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> <h4 id="see-also_61"><a name="user-content-see-also_61" href="#see-also_61" 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> <p><strong>-</strong> <a href="#ic_write">i2c.write()</a></p>
\ No newline at end of file <h1 id="adc-module"><a name="user-content-adc-module" href="#adc-module" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>adc module</h1>
<h2 id="constant_4"><a name="user-content-constant_4" href="#constant_4" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>CONSTANT</h2>
<p>none</p>
<p><a id="adc_read"></a></p>
<h2 id="adcread"><a name="user-content-adcread" href="#adcread" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>adc.read()</h2>
<h4 id="description_62"><a name="user-content-description_62" href="#description_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Description</h4>
<p>read adc value of id, esp8266 has only one 10bit adc, id=0</p>
<h4 id="syntax_62"><a name="user-content-syntax_62" href="#syntax_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Syntax</h4>
<p>adc.read(id)</p>
<h4 id="parameters_62"><a name="user-content-parameters_62" href="#parameters_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Parameters</h4>
<p>id = 0<br /></p>
<h4 id="returns_62"><a name="user-content-returns_62" href="#returns_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Returns</h4>
<p>adc value</p>
<h4 id="see-also_62"><a name="user-content-see-also_62" href="#see-also_62" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>See also</h4>
<p><strong>-</strong> <a href=""></a></p></article></body></html>
\ No newline at end of file
# **nodeMcu API Instruction** # # **nodeMcu API Instruction** #
[中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn) [中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn)
###version 0.9.2 build 2014-11-18 ###version 0.9.2 build 2014-11-19
<a id="change_log"></a> <a id="change_log"></a>
###change log: ###change log:
2014-11-19<br />
add adc module, use adc.read(0) to read adc value, no tests made.<br />
add wifi.sta.getap() api to wifi.sta module, to get ap list.
2014-11-18<br /> 2014-11-18<br />
bug fixed: net.socket:connect() has no effect. bug fixed: net.socket:connect() has no effect.
...@@ -824,6 +828,36 @@ mac address in string, for example:"18-33-44-FE-55-BB" ...@@ -824,6 +828,36 @@ mac address in string, for example:"18-33-44-FE-55-BB"
####See also ####See also
**-** [wifi.sta.getip()](#ws_getip) **-** [wifi.sta.getip()](#ws_getip)
<a id="ws_getap"></a>
## wifi.sta.getap()
####Description
scan and get ap list as a lua table into callback function.
####Syntax
wifi.sta.getap(function(table))
####Parameters
function(table): a callback function to receive ap table when scan is done<br />
this function receive a table, the key is the ssid, value is other info in format: authmode,rssi,bssid,channel
####Returns
nil
####Example
```lua
-- print ap list
function listap(t)
for k,v in pairs(t) do
print(k.." : "..v)
end
end
wifi.sta.getap(listap)
```
####See also
**-** [wifi.sta.getip()](#ws_getip)
#wifi.ap module #wifi.ap module
...@@ -1728,3 +1762,23 @@ string:data received. ...@@ -1728,3 +1762,23 @@ string:data received.
####See also ####See also
**-** [i2c.write()](#ic_write) **-** [i2c.write()](#ic_write)
#adc module
##CONSTANT
none
<a id="adc_read"></a>
## adc.read()
####Description
read adc value of id, esp8266 has only one 10bit adc, id=0
####Syntax
adc.read(id)
####Parameters
id = 0<br />
####Returns
adc value
####See also
**-** []()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment