fix tmr.delay(), add tmr.wdclr(), fix UDP, update doc

This commit is contained in:
funshine 2014-11-20 15:45:21 +08:00
parent 6f9c17a29e
commit e86b2ec53c
7 changed files with 1389 additions and 970 deletions

Binary file not shown.

View File

@ -1014,9 +1014,74 @@ body .markdown-body
page-break-after: avoid; 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> <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> <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>
@ -1066,98 +1131,106 @@ 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>
<pre><code class="lua"> print(wifi.sta.getip()) <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>
--0.0.0.0 <span class="c1">--0.0.0.0</span>
wifi.setmode(wifi.STATION) <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.sta.config(&quot;SSID&quot;,&quot;password&quot;) <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>
print(wifi.sta.getip()) <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>
--192.168.18.110 <span class="c1">--192.168.18.110</span>
</code></pre> </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> <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 <div class="codehilite"><pre> <span class="n">pin</span> <span class="o">=</span> <span class="mi">1</span>
gpio.mode(pin,gpio.OUTPUT) <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.write(pin,gpio.HIGH) <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>
print(gpio.read(pin)) <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>
</code></pre> </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> <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 <div class="codehilite"><pre> <span class="c1">-- A simple http client</span>
conn=net.createConnection(net.TCP, false) <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>
conn:on(&quot;receive&quot;, function(conn, payload) print(c) end ) <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:connect(80,&quot;115.239.210.27&quot;) <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:send(&quot;GET / HTTP/1.1\r\nHost: www.baidu.com\r\n&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>
..&quot;Connection: keep-alive\r\nAccept: */*\r\n\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>
</code></pre> </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> <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 <div class="codehilite"><pre> <span class="c1">-- A simple http server</span>
srv=net.createServer(net.TCP) <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:listen(80,function(conn) <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>
conn:on(&quot;receive&quot;,function(conn,payload) <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>
print(payload) <span class="nb">print</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span>
conn:send(&quot;&lt;h1&gt; Hello, NodeMcu.&lt;/h1&gt;&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">&lt;h1&gt; Hello, NodeMcu.&lt;/h1&gt;&quot;</span><span class="p">)</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="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>
<pre><code class="lua"> function led(r,g,b) <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>
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">0</span><span class="p">,</span><span class="n">r</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">1</span><span class="p">,</span><span class="n">g</span><span class="p">)</span>
pwm.setduty(2,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">b</span><span class="p">)</span>
end <span class="k">end</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">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(1,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(2,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.start(0) <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(1) <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(2) <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>
led(50,0,0) -- red <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(0,0,50) -- blue <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>
</code></pre> </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> <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 <div class="codehilite"><pre> <span class="n">lighton</span><span class="o">=</span><span class="mi">0</span>
tmr.alarm(1000,1,function() <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>
if lighton==0 then <span class="k">if</span> <span class="n">lighton</span><span class="o">==</span><span class="mi">0</span> <span class="k">then</span>
lighton=1 <span class="n">lighton</span><span class="o">=</span><span class="mi">1</span>
led(50,50,50) <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>
else <span class="k">else</span>
lighton=0 <span class="n">lighton</span><span class="o">=</span><span class="mi">0</span>
led(0,0,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>
end <span class="k">end</span>
end) <span class="k">end</span><span class="p">)</span>
</code></pre> </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> <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 <div class="codehilite"><pre> <span class="c1">--init.lua will be excuted</span>
file.open(&quot;init.lua&quot;,&quot;w&quot;) <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.writeline([[print(&quot;Hello, do this at the beginning.&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.close() <span class="n">file</span><span class="p">.</span><span class="n">close</span><span class="p">()</span>
node.restart() -- this will restart the module. <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>
</code></pre> </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> <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 <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>
<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-19 version 0.9.2 build 2014-11-20
# 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)
@ -76,7 +76,7 @@ braudrate:9600
```lua ```lua
-- A simple http client -- 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:on("receive", function(conn, payload) print(c) end )
conn:connect(80,"115.239.210.27") conn:connect(80,"115.239.210.27")
conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n" conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,14 @@
# **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-19 ###版本 0.9.2 build 2014-11-20
<a id="change_log"></a> <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 /> 2014-11-19<br />
增加adc模块adc.read(0)读取adc的值。<br /> 增加adc模块adc.read(0)读取adc的值。<br />
wifi模块增加wifi.sta.getap() 函数用于获取ap列表。 wifi模块增加wifi.sta.getap() 函数用于获取ap列表。
@ -1032,6 +1038,31 @@ nil
####参见 ####参见
**-** [tmr.now()](#tm_now) **-** [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 模块 #GPIO 模块
##常量 ##常量
@ -1382,11 +1413,11 @@ net.TCP, net.UDP
创建一个server。 创建一个server。
####语法 ####语法
net.createServer(type, secure) net.createServer(type, timeout)
####参数 ####参数
type: 取值为net.TCP 或者 net.UDP<br /> type: 取值为net.TCP 或者 net.UDP<br />
secure: 设置为true或者false, true代表安全连接false代表普通连接 timeout: 1~28800, 当为tcp服务器时客户端的超时时间设置
####返回值 ####返回值
net.server子模块 net.server子模块
@ -1394,7 +1425,7 @@ net.server子模块
####示例 ####示例
```lua ```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 /> type: 取值为net.TCP 或者 net.UDP<br />
secure: 设置为true或者false, true代表安全连接false代表普通连接。 secure: 设置为1或者0, 1代表安全连接0代表普通连接。
####返回值 ####返回值
net.server子模块 net.server子模块
@ -1419,7 +1450,7 @@ net.server子模块
####示例 ####示例
```lua ```lua
net.createConnection(net.UDP, false) net.createConnection(net.UDP, 0)
``` ```
####参见 ####参见
@ -1447,7 +1478,7 @@ nil
```lua ```lua
-- 创建一个server -- 创建一个server
sv=net.createServer(net.TCP, false) sv=net.createServer(net.TCP, 30) -- 30s 超时
-- server侦听端口80如果收到数据将数据打印至控制台并向远端发送hello world -- server侦听端口80如果收到数据将数据打印至控制台并向远端发送hello world
sv:listen(80,function(c) sv:listen(80,function(c)
c:on("receive", function(sck, pl) print(pl) end) c:on("receive", function(sck, pl) print(pl) end)
@ -1477,7 +1508,7 @@ nil
```lua ```lua
-- 创建server -- 创建server
sv=net.createServer(net.TCP, false) sv=net.createServer(net.TCP, 5)
-- 关闭server -- 关闭server
sv:close() sv:close()
``` ```
@ -1544,7 +1575,7 @@ nil
####示例 ####示例
```lua ```lua
sk=net.createConnection(net.TCP, false) sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c) print(c) end ) sk:on("receive", function(sck, c) print(c) end )
sk:connect(80,"192.168.0.66") 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") 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> <a id="adc_read"></a>
## adc.read() ## adc.read()
####描述 ####描述
读取adc的值esp8266只有一个10bit adcid为0最大值1024 读取adc的值esp8266只有一个10bit adcid为0引脚为TOUT最大值1024
####语法 ####语法
adc.read(id) adc.read(id)

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,14 @@
# **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-19 ###version 0.9.2 build 2014-11-20
<a id="change_log"></a> <a id="change_log"></a>
###change log: ###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 /> 2014-11-19<br />
add adc module, use adc.read(0) to read adc value, no tests made.<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. add wifi.sta.getap() api to wifi.sta module, to get ap list.
@ -1051,6 +1057,32 @@ nil
**-** [tmr.now()](#tm_now) **-** [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 #GPIO module
##CONSTANT ##CONSTANT
gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW gpio.OUTPUT, gpio.INPUT, gpio.INT, gpio.HIGH, gpio.LOW
@ -1401,11 +1433,11 @@ net.TCP, net.UDP
create a server. create a server.
####Syntax ####Syntax
net.createServer(type, secure) net.createServer(type, timeout)
####Parameters ####Parameters
type: net.TCP or net.UDP<br /> 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 ####Returns
net.server sub module net.server sub module
@ -1413,7 +1445,7 @@ net.server sub module
####Example ####Example
```lua ```lua
net.createServer(net.TCP, true) net.createServer(net.TCP, 30) -- 30s timeout
``` ```
####See also ####See also
@ -1430,7 +1462,7 @@ net.createConnection(type, secure)
####Parameters ####Parameters
type: net.TCP or net.UDP<br /> 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 ####Returns
net.server sub module net.server sub module
@ -1438,7 +1470,7 @@ net.server sub module
####Example ####Example
```lua ```lua
net.createConnection(net.UDP, false) net.createConnection(net.UDP, 0)
``` ```
####See also ####See also
@ -1466,7 +1498,7 @@ nil
```lua ```lua
-- create a server -- 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. -- server listen on 80, if data received, print data to console, and send "hello world" to remote.
sv:listen(80,function(c) sv:listen(80,function(c)
c:on("receive", function(sck, pl) print(pl) end) c:on("receive", function(sck, pl) print(pl) end)
@ -1496,7 +1528,7 @@ nil
```lua ```lua
-- create a server -- create a server
sv=net.createServer(net.TCP, false) sv=net.createServer(net.TCP, 30)
-- close server -- close server
sv:close() sv:close()
``` ```
@ -1563,7 +1595,7 @@ nil
####Example ####Example
```lua ```lua
sk=net.createConnection(net.TCP, false) sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c) print(c) end ) sk:on("receive", function(sck, c) print(c) end )
sk:connect(80,"192.168.0.66") 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") 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> <a id="adc_read"></a>
## adc.read() ## adc.read()
####Description ####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 ####Syntax
adc.read(id) adc.read(id)