<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>
.codehilitepre.il{color:#009999}/* Literal.Number.Integer.Long */</style><title>README</title></head><body><articleclass="markdown-body"><h1id="nodemcu-api-instruction"><strong>nodeMcu API Instruction</strong></h1>
<h1id="flash-the-firmware"><aname="user-content-flash-the-firmware"href="#flash-the-firmware"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Flash the firmware</h1>
for most esp8266 modules, just pull GPIO0 down and restart.</p>
eagle.app.v6.irom0text.bin: 0x10000<br/><br/>
<h1id="connect-the-hardware-in-serial"><aname="user-content-connect-the-hardware-in-serial"href="#connect-the-hardware-in-serial"class="headeranchor-link"aria-hidden="true"><spanclass="headeranchor"></span></a>Connect the hardware in serial</h1>
<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="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="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>
<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>
<p>type: type is either string “long” or “short”. long: press the key for 3 seconds, short: press shortly(less than 3 seconds)<br/><br/>
\ No newline at end of file
function(): user defined function which is called when key is pressed. If nil, cancling the user defined function.<br/><br/>
Default function: long: change LED blinking rate, short: reset chip</p>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua', print the first line.</span>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua', print the first line.</span>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua' in 'a+' mode</span>
<spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">write</span><spanclass="w"></span><spanclass="c1">'foo bar' to the end of the file</span>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua' in 'a+' mode</span>
<spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">write</span><spanclass="w"></span><spanclass="c1">'foo bar' to the end of the file</span>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua' in 'a+' mode</span>
<spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">write</span><spanclass="w"></span><spanclass="c1">'foo bar' to the end of the file</span>
<p>Sets and gets the file position, measured from the beginning of the file, to the position given by offset plus a base specified by the string whence.</p>
<divclass="codehilite"><pre><spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">open</span><spanclass="w"></span><spanclass="c1">'init.lua' in 'a+' mode</span>
<spanclass="w"></span><spanclass="o">--</span><spanclass="w"></span><spanclass="vg">write</span><spanclass="w"></span><spanclass="c1">'foo bar' to the end of the file</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>
<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/>
If event is”receive”, the second param is received data in string.</p>