fix tmr.delay(), add tmr.wdclr(), fix UDP, update doc
This commit is contained in:
parent
6f9c17a29e
commit
e86b2ec53c
Binary file not shown.
233
README.html
233
README.html
|
@ -1014,9 +1014,74 @@ body .markdown-body
|
|||
page-break-after: avoid;
|
||||
}
|
||||
}
|
||||
</style><title>README</title></head><body><article class="markdown-body"><h1 id="nodemcu"><strong>NodeMcu</strong></h1>
|
||||
</style><style>.codehilite pre .hll { background-color: #f8eec7 }
|
||||
.codehilite pre { background: #ffffff; color: #333333 }
|
||||
.codehilite pre .c { color: #999988; font-style: italic } /* Comment */
|
||||
.codehilite pre .err { color: #a61717; background-color: #e3d2d2 } /* Error */
|
||||
.codehilite pre .k { font-weight: bold } /* Keyword */
|
||||
.codehilite pre .n { color: #333333 } /* Name */
|
||||
.codehilite pre .o { font-weight: bold } /* Operator */
|
||||
.codehilite pre .cm { color: #999988; font-style: italic } /* Comment.Multiline */
|
||||
.codehilite pre .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
|
||||
.codehilite pre .c1 { color: #999988; font-style: italic } /* Comment.Single */
|
||||
.codehilite pre .cs { color: #999988; font-style: italic } /* Comment.Special */
|
||||
.codehilite pre .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
|
||||
.codehilite pre .ge { font-style: italic } /* Generic.Emph */
|
||||
.codehilite pre .gr { color: #aa0000 } /* Generic.Error */
|
||||
.codehilite pre .gh { color: #999999 } /* Generic.Heading */
|
||||
.codehilite pre .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
|
||||
.codehilite pre .go { color: #888888 } /* Generic.Output */
|
||||
.codehilite pre .gp { color: #555555 } /* Generic.Prompt */
|
||||
.codehilite pre .gs { font-weight: bold } /* Generic.Strong */
|
||||
.codehilite pre .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.codehilite pre .gt { color: #aa0000 } /* Generic.Traceback */
|
||||
.codehilite pre .kc { font-weight: bold } /* Keyword.Constant */
|
||||
.codehilite pre .kd { font-weight: bold } /* Keyword.Declaration */
|
||||
.codehilite pre .kn { font-weight: bold } /* Keyword.Namespace */
|
||||
.codehilite pre .kp { font-weight: bold } /* Keyword.Pseudo */
|
||||
.codehilite pre .kr { font-weight: bold } /* Keyword.Reserved */
|
||||
.codehilite pre .kt { font-weight: bold } /* Keyword.Type */
|
||||
.codehilite pre .m { color: #945277 } /* Literal.Number */
|
||||
.codehilite pre .s { color: #df5000 } /* Literal.String */
|
||||
.codehilite pre .na { color: #008080 } /* Name.Attribute */
|
||||
.codehilite pre .nb { color: #0086b3 } /* Name.Builtin */
|
||||
.codehilite pre .nc { color: #445588; font-weight: bold } /* Name.Class */
|
||||
.codehilite pre .no { color: #094e99 } /* Name.Constant */
|
||||
.codehilite pre .nd { color: #333333 } /* Name.Decorator */
|
||||
.codehilite pre .ni { color: #800080 } /* Name.Entity */
|
||||
.codehilite pre .ne { color: #990000; font-weight: bold } /* Name.Exception */
|
||||
.codehilite pre .nf { color: #945277; font-weight: bold } /* Name.Function */
|
||||
.codehilite pre .nl { color: #333333 } /* Name.Label */
|
||||
.codehilite pre .nn { color: #555555 } /* Name.Namespace */
|
||||
.codehilite pre .nx { color: #333333 } /* Name.Other */
|
||||
.codehilite pre .py { color: #333333 } /* Name.Property */
|
||||
.codehilite pre .nt { color: #000080 } /* Name.Tag */
|
||||
.codehilite pre .nv { color: #008080 } /* Name.Variable */
|
||||
.codehilite pre .ow { font-weight: bold } /* Operator.Word */
|
||||
.codehilite pre .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
.codehilite pre .mb { color: #945277 } /* Literal.Number.Bin */
|
||||
.codehilite pre .mf { color: #945277 } /* Literal.Number.Float */
|
||||
.codehilite pre .mh { color: #945277 } /* Literal.Number.Hex */
|
||||
.codehilite pre .mi { color: #945277 } /* Literal.Number.Integer */
|
||||
.codehilite pre .mo { color: #945277 } /* Literal.Number.Oct */
|
||||
.codehilite pre .sb { color: #df5000 } /* Literal.String.Backtick */
|
||||
.codehilite pre .sc { color: #df5000 } /* Literal.String.Char */
|
||||
.codehilite pre .sd { color: #df5000 } /* Literal.String.Doc */
|
||||
.codehilite pre .s2 { color: #df5000 } /* Literal.String.Double */
|
||||
.codehilite pre .se { color: #df5000 } /* Literal.String.Escape */
|
||||
.codehilite pre .sh { color: #df5000 } /* Literal.String.Heredoc */
|
||||
.codehilite pre .si { color: #df5000 } /* Literal.String.Interpol */
|
||||
.codehilite pre .sx { color: #df5000 } /* Literal.String.Other */
|
||||
.codehilite pre .sr { color: #017936 } /* Literal.String.Regex */
|
||||
.codehilite pre .s1 { color: #df5000 } /* Literal.String.Single */
|
||||
.codehilite pre .ss { color: #8b467f } /* Literal.String.Symbol */
|
||||
.codehilite pre .bp { color: #999999 } /* Name.Builtin.Pseudo */
|
||||
.codehilite pre .vc { color: #008080 } /* Name.Variable.Class */
|
||||
.codehilite pre .vg { color: #008080 } /* Name.Variable.Global */
|
||||
.codehilite pre .vi { color: #008080 } /* Name.Variable.Instance */
|
||||
.codehilite pre .il { color: #945277 } /* Literal.Number.Integer.Long */</style><title>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-19</p>
|
||||
<p>version 0.9.2 build 2014-11-20</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>
|
||||
|
@ -1066,98 +1131,106 @@ 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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<pre><code class="lua"> pin = 1
|
||||
gpio.mode(pin,gpio.OUTPUT)
|
||||
gpio.write(pin,gpio.HIGH)
|
||||
print(gpio.read(pin))
|
||||
</code></pre>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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="mi">0</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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
|
||||
|
||||
<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-19
|
||||
version 0.9.2 build 2014-11-20
|
||||
# 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)
|
||||
|
@ -76,7 +76,7 @@ braudrate:9600
|
|||
|
||||
```lua
|
||||
-- A simple http client
|
||||
conn=net.createConnection(net.TCP, false)
|
||||
conn=net.createConnection(net.TCP, 0)
|
||||
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"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,14 @@
|
|||
# **nodeMcu API说明** #
|
||||
[English Version](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_en)
|
||||
###版本 0.9.2 build 2014-11-19
|
||||
###版本 0.9.2 build 2014-11-20
|
||||
<a id="change_log"></a>
|
||||
###变更日志:
|
||||
2014-11-20<br />
|
||||
修正tmr.delay,支持2s以上的延时,但是长延时可能会引起beacon timer out,导致与AP之间重新连接。<br />
|
||||
增加tmr.wdclr(),用来重置看门狗计数器,用在长循环中,以防芯片因看门狗重启。<br />
|
||||
修正net模块UDP无法连接问题。<br />
|
||||
createServer(net.TCP, timeout)函数增加连接超时参数设置。
|
||||
|
||||
2014-11-19<br />
|
||||
增加adc模块,adc.read(0)读取adc的值。<br />
|
||||
wifi模块增加wifi.sta.getap() 函数,用于获取ap列表。
|
||||
|
@ -1032,6 +1038,31 @@ nil
|
|||
####参见
|
||||
**-** [tmr.now()](#tm_now)
|
||||
|
||||
<a id="tm_wdclr"></a>
|
||||
## tmr.wdclr()
|
||||
####描述
|
||||
清除看门狗计数器。<br />
|
||||
|
||||
####语法
|
||||
tmr.wdclr()
|
||||
|
||||
####参数
|
||||
nil.
|
||||
|
||||
####返回值
|
||||
nil
|
||||
|
||||
####示例
|
||||
|
||||
```lua
|
||||
for i=1,10000 do
|
||||
print(i)
|
||||
tmr.wdclr() -- 一个长时间的循环或者事务,需内部调用tmr.wdclr() 清楚看门狗计数器,防止重启。
|
||||
end
|
||||
```
|
||||
|
||||
####参见
|
||||
**-** [tmr.delay()](#tm_delay)
|
||||
|
||||
#GPIO 模块
|
||||
##常量
|
||||
|
@ -1382,11 +1413,11 @@ net.TCP, net.UDP
|
|||
创建一个server。
|
||||
|
||||
####语法
|
||||
net.createServer(type, secure)
|
||||
net.createServer(type, timeout)
|
||||
|
||||
####参数
|
||||
type: 取值为:net.TCP 或者 net.UDP<br />
|
||||
secure: 设置为true或者false, true代表安全连接,false代表普通连接。
|
||||
timeout: 1~28800, 当为tcp服务器时,客户端的超时时间设置。
|
||||
|
||||
####返回值
|
||||
net.server子模块
|
||||
|
@ -1394,7 +1425,7 @@ net.server子模块
|
|||
####示例
|
||||
|
||||
```lua
|
||||
net.createServer(net.TCP, true)
|
||||
net.createServer(net.TCP, 30)
|
||||
```
|
||||
|
||||
####参见
|
||||
|
@ -1411,7 +1442,7 @@ net.createConnection(type, secure)
|
|||
|
||||
####参数
|
||||
type: 取值为:net.TCP 或者 net.UDP<br />
|
||||
secure: 设置为true或者false, true代表安全连接,false代表普通连接。
|
||||
secure: 设置为1或者0, 1代表安全连接,0代表普通连接。
|
||||
|
||||
####返回值
|
||||
net.server子模块
|
||||
|
@ -1419,7 +1450,7 @@ net.server子模块
|
|||
####示例
|
||||
|
||||
```lua
|
||||
net.createConnection(net.UDP, false)
|
||||
net.createConnection(net.UDP, 0)
|
||||
```
|
||||
|
||||
####参见
|
||||
|
@ -1447,7 +1478,7 @@ nil
|
|||
|
||||
```lua
|
||||
-- 创建一个server
|
||||
sv=net.createServer(net.TCP, false)
|
||||
sv=net.createServer(net.TCP, 30) -- 30s 超时
|
||||
-- server侦听端口80,如果收到数据将数据打印至控制台,并向远端发送‘hello world’
|
||||
sv:listen(80,function(c)
|
||||
c:on("receive", function(sck, pl) print(pl) end)
|
||||
|
@ -1477,7 +1508,7 @@ nil
|
|||
|
||||
```lua
|
||||
-- 创建server
|
||||
sv=net.createServer(net.TCP, false)
|
||||
sv=net.createServer(net.TCP, 5)
|
||||
-- 关闭server
|
||||
sv:close()
|
||||
```
|
||||
|
@ -1544,7 +1575,7 @@ nil
|
|||
####示例
|
||||
|
||||
```lua
|
||||
sk=net.createConnection(net.TCP, false)
|
||||
sk=net.createConnection(net.TCP, 0)
|
||||
sk:on("receive", function(sck, c) print(c) end )
|
||||
sk:connect(80,"192.168.0.66")
|
||||
sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
|
||||
|
@ -1750,7 +1781,7 @@ string:接收到的数据。
|
|||
<a id="adc_read"></a>
|
||||
## adc.read()
|
||||
####描述
|
||||
读取adc的值,esp8266只有一个10bit adc,id为0,最大值1024
|
||||
读取adc的值,esp8266只有一个10bit adc,id为0,引脚为TOUT,最大值1024
|
||||
|
||||
####语法
|
||||
adc.read(id)
|
||||
|
|
1042
nodemcu_api_en.html
1042
nodemcu_api_en.html
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,14 @@
|
|||
# **nodeMcu API Instruction** #
|
||||
[中文版本](https://github.com/funshine/nodemcu-firmware/wiki/nodemcu_api_cn)
|
||||
###version 0.9.2 build 2014-11-19
|
||||
###version 0.9.2 build 2014-11-20
|
||||
<a id="change_log"></a>
|
||||
###change log:
|
||||
2014-11-20<br />
|
||||
fix tmr.delay to support more than 2s delay, may cause bacon time out, lost connection to AP.<br />
|
||||
add tmr.wdclr to clear watchdog counter in chip, use in long time loop.<br />
|
||||
fix UDP part of net module.<br />
|
||||
add a timeout para to createServer(net.TCP, timeout).
|
||||
|
||||
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.
|
||||
|
@ -1051,6 +1057,32 @@ nil
|
|||
**-** [tmr.now()](#tm_now)
|
||||
|
||||
|
||||
<a id="tm_wdclr"></a>
|
||||
## tmr.wdclr()
|
||||
####Description
|
||||
clear system watchdog counter.<br />
|
||||
|
||||
####Syntax
|
||||
tmr.wdclr()
|
||||
|
||||
####Parameters
|
||||
nil.
|
||||
|
||||
####Returns
|
||||
nil
|
||||
|
||||
####Example
|
||||
|
||||
```lua
|
||||
for i=1,10000 do
|
||||
print(i)
|
||||
tmr.wdclr() -- should call tmr.wdclr() in a long loop to avoid hardware reset caused by watchdog.
|
||||
end
|
||||
```
|
||||
|
||||
####See also
|
||||
**-** [tmr.delay()](#tm_delay)
|
||||
|
||||
#GPIO module
|
||||
##CONSTANT
|
||||
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
|
||||
|
@ -1401,11 +1433,11 @@ net.TCP, net.UDP
|
|||
create a server.
|
||||
|
||||
####Syntax
|
||||
net.createServer(type, secure)
|
||||
net.createServer(type, timeout)
|
||||
|
||||
####Parameters
|
||||
type: net.TCP or net.UDP<br />
|
||||
secure: true or false, true for safe link, false for ordinary link
|
||||
timeout: for a TCP server, timeout is 1~28800 seconds, for a inactive client to disconnected.
|
||||
|
||||
####Returns
|
||||
net.server sub module
|
||||
|
@ -1413,7 +1445,7 @@ net.server sub module
|
|||
####Example
|
||||
|
||||
```lua
|
||||
net.createServer(net.TCP, true)
|
||||
net.createServer(net.TCP, 30) -- 30s timeout
|
||||
```
|
||||
|
||||
####See also
|
||||
|
@ -1430,7 +1462,7 @@ net.createConnection(type, secure)
|
|||
|
||||
####Parameters
|
||||
type: net.TCP or net.UDP<br />
|
||||
secure: true or false, true for safe link, false for ordinary link
|
||||
secure: 1 or 0, 1 for ssl link, 0 for normal link
|
||||
|
||||
####Returns
|
||||
net.server sub module
|
||||
|
@ -1438,7 +1470,7 @@ net.server sub module
|
|||
####Example
|
||||
|
||||
```lua
|
||||
net.createConnection(net.UDP, false)
|
||||
net.createConnection(net.UDP, 0)
|
||||
```
|
||||
|
||||
####See also
|
||||
|
@ -1466,7 +1498,7 @@ nil
|
|||
|
||||
```lua
|
||||
-- create a server
|
||||
sv=net.createServer(net.TCP, false)
|
||||
sv=net.createServer(net.TCP, 30) -- 30s time out for a inactive client
|
||||
-- server listen on 80, if data received, print data to console, and send "hello world" to remote.
|
||||
sv:listen(80,function(c)
|
||||
c:on("receive", function(sck, pl) print(pl) end)
|
||||
|
@ -1496,7 +1528,7 @@ nil
|
|||
|
||||
```lua
|
||||
-- create a server
|
||||
sv=net.createServer(net.TCP, false)
|
||||
sv=net.createServer(net.TCP, 30)
|
||||
-- close server
|
||||
sv:close()
|
||||
```
|
||||
|
@ -1563,7 +1595,7 @@ nil
|
|||
####Example
|
||||
|
||||
```lua
|
||||
sk=net.createConnection(net.TCP, false)
|
||||
sk=net.createConnection(net.TCP, 0)
|
||||
sk:on("receive", function(sck, c) print(c) end )
|
||||
sk:connect(80,"192.168.0.66")
|
||||
sk:send("GET / HTTP/1.1\r\nHost: 192.168.0.66\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
|
||||
|
@ -1769,7 +1801,7 @@ none
|
|||
<a id="adc_read"></a>
|
||||
## adc.read()
|
||||
####Description
|
||||
read adc value of id, esp8266 has only one 10bit adc, id=0
|
||||
read adc value of id, esp8266 has only one 10bit adc, id=0, pin TOUT
|
||||
|
||||
####Syntax
|
||||
adc.read(id)
|
||||
|
|
Loading…
Reference in New Issue