<h3id="a-lua-based-firmware-for-wifi-soc-esp8266"><aname="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"><spanclass="headeranchor"></span></a>A lua based firmware for wifi-soc esp8266</h3>
<h3id="a-lua-based-firmware-for-wifi-soc-esp8266"><aname="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"><spanclass="headeranchor"></span></a>A lua based firmware for wifi-soc esp8266</h3>
<h4id="connect-to-your-ap"><aname="user-content-connect-to-your-ap"href="#connect-to-your-ap"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Connect to your ap</h4>
<h4id="connect-to-your-ap"><aname="user-content-connect-to-your-ap"href="#connect-to-your-ap"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Connect to your ap</h4>
<h4id="manipulate-hardware-like-a-arduino"><aname="user-content-manipulate-hardware-like-a-arduino"href="#manipulate-hardware-like-a-arduino"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Manipulate hardware like a arduino</h4>
<h4id="manipulate-hardware-like-a-arduino"><aname="user-content-manipulate-hardware-like-a-arduino"href="#manipulate-hardware-like-a-arduino"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Manipulate hardware like a arduino</h4>
<h4id="or-a-simple-http-server"><aname="user-content-or-a-simple-http-server"href="#or-a-simple-http-server"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Or a simple http server</h4>
<h4id="or-a-simple-http-server"><aname="user-content-or-a-simple-http-server"href="#or-a-simple-http-server"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Or a simple http server</h4>
<divclass="codehilite"><pre><spanclass="c1">-- A simple http server</span>
<h4id="if-you-want-to-run-something-when-system-started"><aname="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"><spanclass="headeranchor"></span></a>If you want to run something when system started</h4>
<h4id="if-you-want-to-run-something-when-system-started"><aname="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"><spanclass="headeranchor"></span></a>If you want to run something when system started</h4>
<divclass="codehilite"><pre><spanclass="c1">--init.lua will be excuted</span>
<spanclass="n">file</span><spanclass="p">.</span><spanclass="n">writeline</span><spanclass="p">(</span><spanclass="s">[[print("Hello, do this at the beginning.")]]</span><spanclass="p">)</span>
file.writeline([[print("Hello, do this at the beginning.")]])
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">restart</span><spanclass="p">()</span><spanclass="c1">-- this will restart the module.</span>
node.restart() -- this will restart the module.
</pre></div>
</code></pre>
<h4id="with-below-code-you-can-telnet-to-your-esp8266-now"><aname="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"><spanclass="headeranchor"></span></a>With below code, you can telnet to your esp8266 now</h4>
<h4id="with-below-code-you-can-telnet-to-your-esp8266-now"><aname="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"><spanclass="headeranchor"></span></a>With below code, you can telnet to your esp8266 now</h4>
<divclass="codehilite"><pre><spanclass="c1">-- a simple telnet server</span>
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">output</span><spanclass="p">(</span><spanclass="n">s_output</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">)</span><spanclass="c1">-- re-direct output to function s_ouput.</span>
node.output(s_output, 0) -- re-direct output to function s_ouput.
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">input</span><spanclass="p">(</span><spanclass="n">l</span><spanclass="p">)</span><spanclass="c1">-- works like pcall(loadstring(l)) but support multiple separate line</span>
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">output</span><spanclass="p">(</span><spanclass="kc">nil</span><spanclass="p">)</span><spanclass="c1">-- un-regist the redirect output function, output goes to serial</span>
node.output(nil) -- un-regist the redirect output function, output goes to serial
<spanclass="k">end</span><spanclass="p">)</span>
end)
<spanclass="k">end</span><spanclass="p">)</span>
end)
</pre></div>
</code></pre>
<h1id="check-this-out"><aname="user-content-check-this-out"href="#check-this-out"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Check this out</h1>
<h1id="check-this-out"><aname="user-content-check-this-out"href="#check-this-out"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Check this out</h1>
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">ouput</span><spanclass="p">(</span><spanclass="n">tonet</span><spanclass="p">,</span><spanclass="mi">1</span><spanclass="p">)</span><spanclass="c1">-- serial also get the lua output.</span>
node.ouput(tonet, 1) -- serial also get the lua output.
</style><title>nodemcu_api_en</title></head><body><articleclass="markdown-body"><h1id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
.codehilitepre.il{color:#945277}/* Literal.Number.Integer.Long */</style><title>nodemcu_api_en</title></head><body><articleclass="markdown-body"><h1id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
<spanclass="c1">-- print(str) WRONG!!! never ever print something in this function</span>
-- print(str) WRONG!!! never ever print something in this function
<spanclass="c1">-- because this will cause a recursive function call!!!</span>
-- because this will cause a recursive function call!!!
<spanclass="k">end</span>
end
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">ouput</span><spanclass="p">(</span><spanclass="n">tonet</span><spanclass="p">,</span><spanclass="mi">1</span><spanclass="p">)</span><spanclass="c1">-- serial also get the lua output.</span>
node.ouput(tonet, 1) -- serial also get the lua output.
</pre></div>
</code></pre>
<pre><codeclass="lua"> -- a simple telnet server
<divclass="codehilite"><pre><spanclass="c1">-- a simple telnet server</span>
node.output(s_output, 0) -- re-direct output to function s_ouput.
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">output</span><spanclass="p">(</span><spanclass="n">s_output</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">)</span><spanclass="c1">-- re-direct output to function s_ouput.</span>
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">input</span><spanclass="p">(</span><spanclass="n">l</span><spanclass="p">)</span><spanclass="c1">-- works like pcall(loadstring(l)) but support multiple separate line</span>
node.output(nil) -- un-regist the redirect output function, output goes to serial
<spanclass="n">node</span><spanclass="p">.</span><spanclass="n">output</span><spanclass="p">(</span><spanclass="kc">nil</span><spanclass="p">)</span><spanclass="c1">-- un-regist the redirect output function, output goes to serial</span>
<strong>-Note:</strong> setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.</p>
<strong>-Note:</strong> setup pwm frequency will synchronously change others if there are any. Only one PWM frequency can be allowed for the system.</p>
<spanclass="n">led</span><spanclass="p">(</span><spanclass="mi">50</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">)</span><spanclass="c1">-- set led to red</span>
led(50,0,0) -- set led to red
<spanclass="n">led</span><spanclass="p">(</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">,</span><spanclass="mi">50</span><spanclass="p">)</span><spanclass="c1">-- set led to blue.</span>
<p>event: string, which can be: “connection”, “reconnection”, “disconnection”, “receive”, “sent”<br/><br/>
<p>event: string, which can be: “connection”, “reconnection”, “disconnection”, “receive”, “sent”<br/><br/>
function cb(net.socket, [string]): callback function. The first param is the socket.<br/><br/>
function cb(net.socket, [string]): callback function. The first param is the socket.<br/><br/>
If event is”receive”, the second param is received data in string.</p>
If event is”receive”, the second param is received data in string.</p>