add adc module, wifi.sta.getap() api, update doc
This commit is contained in:
parent
c49d438c8e
commit
6f9c17a29e
Binary file not shown.
233
README.html
233
README.html
|
@ -1014,74 +1014,9 @@ body .markdown-body
|
|||
page-break-after: avoid;
|
||||
}
|
||||
}
|
||||
</style><style>.codehilite pre .hll { background-color: #f8eec7 }
|
||||
.codehilite pre { background: #ffffff; color: #333333 }
|
||||
.codehilite pre .c { color: #999988; font-style: italic } /* Comment */
|
||||
.codehilite pre .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
||||
.codehilite pre .k { font-weight: bold } /* Keyword */
|
||||
.codehilite pre .n { color: #333333 } /* Name */
|
||||
.codehilite pre .o { font-weight: bold } /* Operator */
|
||||
.codehilite pre .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
||||
.codehilite pre .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
|
||||
.codehilite pre .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
||||
.codehilite pre .cs { color: #999988; font-style: italic } /* Comment.Special */
|
||||
.codehilite pre .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
||||
.codehilite pre .ge { font-style: italic } /* Generic.Emph */
|
||||
.codehilite pre .gr { color: #aa0000 } /* Generic.Error */
|
||||
.codehilite pre .gh { color: #999999 } /* Generic.Heading */
|
||||
.codehilite pre .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
||||
.codehilite pre .go { color: #888888 } /* Generic.Output */
|
||||
.codehilite pre .gp { color: #555555 } /* Generic.Prompt */
|
||||
.codehilite pre .gs { font-weight: bold } /* Generic.Strong */
|
||||
.codehilite pre .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.codehilite pre .gt { color: #aa0000 } /* Generic.Traceback */
|
||||
.codehilite pre .kc { font-weight: bold } /* Keyword.Constant */
|
||||
.codehilite pre .kd { font-weight: bold } /* Keyword.Declaration */
|
||||
.codehilite pre .kn { font-weight: bold } /* Keyword.Namespace */
|
||||
.codehilite pre .kp { font-weight: bold } /* Keyword.Pseudo */
|
||||
.codehilite pre .kr { font-weight: bold } /* Keyword.Reserved */
|
||||
.codehilite pre .kt { font-weight: bold } /* Keyword.Type */
|
||||
.codehilite pre .m { color: #945277 } /* Literal.Number */
|
||||
.codehilite pre .s { color: #df5000 } /* Literal.String */
|
||||
.codehilite pre .na { color: #008080 } /* Name.Attribute */
|
||||
.codehilite pre .nb { color: #0086b3 } /* Name.Builtin */
|
||||
.codehilite pre .nc { color: #445588; font-weight: bold } /* Name.Class */
|
||||
.codehilite pre .no { color: #094e99 } /* Name.Constant */
|
||||
.codehilite pre .nd { color: #333333 } /* Name.Decorator */
|
||||
.codehilite pre .ni { color: #800080 } /* Name.Entity */
|
||||
.codehilite pre .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
||||
.codehilite pre .nf { color: #945277; font-weight: bold } /* Name.Function */
|
||||
.codehilite pre .nl { color: #333333 } /* Name.Label */
|
||||
.codehilite pre .nn { color: #555555 } /* Name.Namespace */
|
||||
.codehilite pre .nx { color: #333333 } /* Name.Other */
|
||||
.codehilite pre .py { color: #333333 } /* Name.Property */
|
||||
.codehilite pre .nt { color: #000080 } /* Name.Tag */
|
||||
.codehilite pre .nv { color: #008080 } /* Name.Variable */
|
||||
.codehilite pre .ow { font-weight: bold } /* Operator.Word */
|
||||
.codehilite pre .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
.codehilite pre .mb { color: #945277 } /* Literal.Number.Bin */
|
||||
.codehilite pre .mf { color: #945277 } /* Literal.Number.Float */
|
||||
.codehilite pre .mh { color: #945277 } /* Literal.Number.Hex */
|
||||
.codehilite pre .mi { color: #945277 } /* Literal.Number.Integer */
|
||||
.codehilite pre .mo { color: #945277 } /* Literal.Number.Oct */
|
||||
.codehilite pre .sb { color: #df5000 } /* Literal.String.Backtick */
|
||||
.codehilite pre .sc { color: #df5000 } /* Literal.String.Char */
|
||||
.codehilite pre .sd { color: #df5000 } /* Literal.String.Doc */
|
||||
.codehilite pre .s2 { color: #df5000 } /* Literal.String.Double */
|
||||
.codehilite pre .se { color: #df5000 } /* Literal.String.Escape */
|
||||
.codehilite pre .sh { color: #df5000 } /* Literal.String.Heredoc */
|
||||
.codehilite pre .si { color: #df5000 } /* Literal.String.Interpol */
|
||||
.codehilite pre .sx { color: #df5000 } /* Literal.String.Other */
|
||||
.codehilite pre .sr { color: #017936 } /* Literal.String.Regex */
|
||||
.codehilite pre .s1 { color: #df5000 } /* Literal.String.Single */
|
||||
.codehilite pre .ss { color: #8b467f } /* Literal.String.Symbol */
|
||||
.codehilite pre .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
||||
.codehilite pre .vc { color: #008080 } /* Name.Variable.Class */
|
||||
.codehilite pre .vg { color: #008080 } /* Name.Variable.Global */
|
||||
.codehilite pre .vi { color: #008080 } /* Name.Variable.Instance */
|
||||
.codehilite pre .il { color: #945277 } /* Literal.Number.Integer.Long */</style><title>README</title></head><body><article class="markdown-body"><h1 id="nodemcu"><strong>NodeMcu</strong></h1>
|
||||
</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>
|
||||
<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>
|
||||
<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>
|
||||
|
@ -1131,106 +1066,98 @@ for most esp8266 modules, just pull GPIO0 down and restart.</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>
|
||||
<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>
|
||||
<span class="c1">--0.0.0.0</span>
|
||||
<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>
|
||||
<span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">config</span><span class="p">(</span><span class="s2">"</span><span class="s">SSID"</span><span class="p">,</span><span class="s2">"</span><span class="s">password"</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">wifi</span><span class="p">.</span><span class="n">sta</span><span class="p">.</span><span class="n">getip</span><span class="p">())</span>
|
||||
<span class="c1">--192.168.18.110</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> print(wifi.sta.getip())
|
||||
--0.0.0.0
|
||||
wifi.setmode(wifi.STATION)
|
||||
wifi.sta.config("SSID","password")
|
||||
print(wifi.sta.getip())
|
||||
--192.168.18.110
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="n">pin</span> <span class="o">=</span> <span class="mi">1</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">mode</span><span class="p">(</span><span class="n">pin</span><span class="p">,</span><span class="n">gpio</span><span class="p">.</span><span class="n">OUTPUT</span><span class="p">)</span>
|
||||
<span class="n">gpio</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">pin</span><span class="p">,</span><span class="n">gpio</span><span class="p">.</span><span class="n">HIGH</span><span class="p">)</span>
|
||||
<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>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> pin = 1
|
||||
gpio.mode(pin,gpio.OUTPUT)
|
||||
gpio.write(pin,gpio.HIGH)
|
||||
print(gpio.read(pin))
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="c1">-- A simple http client</span>
|
||||
<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>
|
||||
<span class="n">conn</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span> <span class="k">function</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span> <span class="n">payload</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">end</span> <span class="p">)</span>
|
||||
<span class="n">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">"</span><span class="s">115.239.210.27"</span><span class="p">)</span>
|
||||
<span class="n">conn</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">"</span><span class="s">GET / HTTP/1.1</span><span class="se">\r\n</span><span class="s">Host: www.baidu.com</span><span class="se">\r\n</span><span class="s">"</span>
|
||||
<span class="o">..</span><span class="s2">"</span><span class="s">Connection: keep-alive</span><span class="se">\r\n</span><span class="s">Accept: */*</span><span class="se">\r\n\r\n</span><span class="s">"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> -- A simple http client
|
||||
conn=net.createConnection(net.TCP, false)
|
||||
conn:on("receive", function(conn, payload) print(c) end )
|
||||
conn:connect(80,"115.239.210.27")
|
||||
conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"
|
||||
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="c1">-- A simple http server</span>
|
||||
<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>
|
||||
<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>
|
||||
<span class="n">conn</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">conn</span><span class="p">,</span><span class="n">payload</span><span class="p">)</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span>
|
||||
<span class="n">conn</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="s2">"</span><span class="s"><h1> Hello, NodeMcu.</h1>"</span><span class="p">)</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> -- A simple http server
|
||||
srv=net.createServer(net.TCP)
|
||||
srv:listen(80,function(conn)
|
||||
conn:on("receive",function(conn,payload)
|
||||
print(payload)
|
||||
conn:send("<h1> Hello, NodeMcu.</h1>")
|
||||
end)
|
||||
end)
|
||||
</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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<span class="k">end</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">setup</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">500</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
||||
<span class="n">pwm</span><span class="p">.</span><span class="n">start</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
|
||||
<span class="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>
|
||||
<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>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> function led(r,g,b)
|
||||
pwm.setduty(0,r)
|
||||
pwm.setduty(1,g)
|
||||
pwm.setduty(2,b)
|
||||
end
|
||||
pwm.setup(0,500,50)
|
||||
pwm.setup(1,500,50)
|
||||
pwm.setup(2,500,50)
|
||||
pwm.start(0)
|
||||
pwm.start(1)
|
||||
pwm.start(2)
|
||||
led(50,0,0) -- red
|
||||
led(0,0,50) -- blue
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="n">lighton</span><span class="o">=</span><span class="mi">0</span>
|
||||
<span class="n">tmr</span><span class="p">.</span><span class="n">alarm</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="k">function</span><span class="p">()</span>
|
||||
<span class="k">if</span> <span class="n">lighton</span><span class="o">==</span><span class="mi">0</span> <span class="k">then</span>
|
||||
<span class="n">lighton</span><span class="o">=</span><span class="mi">1</span>
|
||||
<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>
|
||||
<span class="k">else</span>
|
||||
<span class="n">lighton</span><span class="o">=</span><span class="mi">0</span>
|
||||
<span class="n">led</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> lighton=0
|
||||
tmr.alarm(1000,1,function()
|
||||
if lighton==0 then
|
||||
lighton=1
|
||||
led(50,50,50)
|
||||
else
|
||||
lighton=0
|
||||
led(0,0,0)
|
||||
end
|
||||
end)
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="c1">--init.lua will be excuted</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"</span><span class="s">init.lua"</span><span class="p">,</span><span class="s2">"</span><span class="s">w"</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">writeline</span><span class="p">(</span><span class="s">[[print("Hello, do this at the beginning.")]]</span><span class="p">)</span>
|
||||
<span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
|
||||
<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>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> --init.lua will be excuted
|
||||
file.open("init.lua","w")
|
||||
file.writeline([[print("Hello, do this at the beginning.")]])
|
||||
file.close()
|
||||
node.restart() -- this will restart the module.
|
||||
</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>
|
||||
<div class="codehilite"><pre> <span class="c1">-- a simple telnet server</span>
|
||||
<span class="n">s</span><span class="o">=</span><span class="n">net</span><span class="p">.</span><span class="n">createServer</span><span class="p">(</span><span class="n">net</span><span class="p">.</span><span class="n">TCP</span><span class="p">)</span>
|
||||
<span class="n">s</span><span class="p">:</span><span class="n">listen</span><span class="p">(</span><span class="mi">2323</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
|
||||
<span class="n">con_std</span> <span class="o">=</span> <span class="n">c</span>
|
||||
<span class="k">function</span> <span class="nf">s_output</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="n">con_std</span><span class="o">~=</span><span class="kc">nil</span><span class="p">)</span>
|
||||
<span class="k">then</span> <span class="n">con_std</span><span class="p">:</span><span class="n">send</span><span class="p">(</span><span class="n">str</span><span class="p">)</span>
|
||||
<span class="k">end</span>
|
||||
<span class="k">end</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">output</span><span class="p">(</span><span class="n">s_output</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="c1">-- re-direct output to function s_ouput.</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">receive"</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">,</span><span class="n">l</span><span class="p">)</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">input</span><span class="p">(</span><span class="n">l</span><span class="p">)</span> <span class="c1">-- works like pcall(loadstring(l)) but support multiple separate line</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
<span class="n">c</span><span class="p">:</span><span class="n">on</span><span class="p">(</span><span class="s2">"</span><span class="s">disconnection"</span><span class="p">,</span><span class="k">function</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
|
||||
<span class="n">con_std</span> <span class="o">=</span> <span class="kc">nil</span>
|
||||
<span class="n">node</span><span class="p">.</span><span class="n">output</span><span class="p">(</span><span class="kc">nil</span><span class="p">)</span> <span class="c1">-- un-regist the redirect output function, output goes to serial</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
<span class="k">end</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
<pre><code class="lua"> -- a simple telnet server
|
||||
s=net.createServer(net.TCP)
|
||||
s:listen(2323,function(c)
|
||||
con_std = c
|
||||
function s_output(str)
|
||||
if(con_std~=nil)
|
||||
then con_std:send(str)
|
||||
end
|
||||
end
|
||||
node.output(s_output, 0) -- re-direct output to function s_ouput.
|
||||
c:on("receive",function(c,l)
|
||||
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
|
||||
end)
|
||||
c:on("disconnection",function(c)
|
||||
con_std = nil
|
||||
node.output(nil) -- un-regist the redirect output function, output goes to serial
|
||||
end)
|
||||
end)
|
||||
</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>
|
||||
<p>Tencent QQ group: 309957875<br/><br />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# **NodeMcu** #
|
||||
###A lua based firmware for wifi-soc esp8266
|
||||
version 0.9.2 build 2014-11-18
|
||||
version 0.9.2 build 2014-11-19
|
||||
# Change log
|
||||
[change log](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en#change_log)<br />
|
||||
[变更日志](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn#change_log)
|
||||
|
|
1074
nodemcu_api_cn.html
1074
nodemcu_api_cn.html
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,12 @@
|
|||
# **nodeMcu API说明** #
|
||||
[English Version](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en)
|
||||
###版本 0.9.2 build 2014-11-18
|
||||
###版本 0.9.2 build 2014-11-19
|
||||
<a id="change_log"></a>
|
||||
###变更日志:
|
||||
2014-11-19<br />
|
||||
增加adc模块,adc.read(0)读取adc的值。<br />
|
||||
wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。
|
||||
|
||||
2014-11-18<br />
|
||||
修正tcp服务器不能使用:close()函数关闭tcp连接的问题。<br />
|
||||
tcp服务器: 服务器将关闭30s内未使用的闲置的连接。(修正前为180s)<br />
|
||||
|
@ -807,6 +811,36 @@ mac地址字符串,如:"18-33-44-FE-55-BB"
|
|||
####参见
|
||||
**-** [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 子模块
|
||||
|
||||
|
@ -1708,3 +1742,24 @@ string:接收到的数据。
|
|||
|
||||
####参见
|
||||
**-** [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.
|
||||
|
||||
####参见
|
||||
**-** []()
|
||||
|
|
1143
nodemcu_api_en.html
1143
nodemcu_api_en.html
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,12 @@
|
|||
# **nodeMcu API Instruction** #
|
||||
[中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn)
|
||||
###version 0.9.2 build 2014-11-18
|
||||
###version 0.9.2 build 2014-11-19
|
||||
<a id="change_log"></a>
|
||||
###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 />
|
||||
bug fixed: net.socket:connect() has no effect.
|
||||
|
||||
|
@ -824,6 +828,36 @@ mac address in string, for example:"18-33-44-FE-55-BB"
|
|||
####See also
|
||||
**-** [wifi.sta.getip()](#ws_getip)
|
||||
|
||||
<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
|
||||
|
||||
|
@ -1728,3 +1762,23 @@ string:data received.
|
|||
####See also
|
||||
**-** [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
|
||||
**-** []()
|
||||
|
|
Loading…
Reference in New Issue