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

This commit is contained in:
funshine 2014-11-19 23:15:50 +08:00
parent c49d438c8e
commit 6f9c17a29e
7 changed files with 1227 additions and 1340 deletions

Binary file not shown.

View File

@ -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>
<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 />

View File

@ -1,6 +1,6 @@
# **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)

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,12 @@
# **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"
####参见 ####参见
**-** [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 tablekey为ap的ssidvalue为其他信息格式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 子模块
@ -1707,4 +1741,25 @@ string:接收到的数据。
``` ```
####参见 ####参见
**-** [i2c.write()](#ic_write) **-** [i2c.write()](#ic_write)
#adc 模块
##常量
<a id="adc_read"></a>
## adc.read()
####描述
读取adc的值esp8266只有一个10bit adcid为0最大值1024
####语法
adc.read(id)
####参数
id = 0<br />
####返回值
adc 值 10bit最大1024.
####参见
**-** []()

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,12 @@
# **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"
####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.
####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
**-** []()