2014-11-12 17:17:08 +01:00
|
|
|
# **NodeMcu** #
|
|
|
|
###A lua based firmware for wifi-soc esp8266
|
|
|
|
version 0.9.2 2014-11-12
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
# Summary
|
|
|
|
- Easy to access wireless router
|
2014-11-12 17:17:08 +01:00
|
|
|
- Based on Lua 5.1.4
|
|
|
|
- Event-Drive programming preferred.
|
|
|
|
- Build-in file, timer, pwm, i2c, net, gpio, wifi, and system api.
|
|
|
|
- GPIO pin re-mapped, use the index to access gpio, i2c, pwm.
|
2014-11-10 14:00:17 +01:00
|
|
|
- GPIO Map Table:
|
2014-11-07 05:59:19 +01:00
|
|
|
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th scope="col">IO index</th><th scope="col">ESP8266 pin</th><th scope="col">IO index</th><th scope="col">ESP8266 pin</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>0</td><td>GPIO12</td><td>8</td><td>GPIO0</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>1</td><td>GPIO13</td><td>9</td><td>GPIO2</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>2</td><td>GPIO14</td><td>10</td><td>GPIO4</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>3</td><td>GPIO15</td><td>11</td><td>GPIO5</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>4</td><td>GPIO3</td><td></td><td></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>5</td><td>GPIO1</td><td></td><td></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>6</td><td>GPIO9</td><td></td><td></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>7</td><td>GPIO10</td<td></td><td></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
#Flash the firmware
|
|
|
|
nodemcu_512k.bin: 0x00000<br />
|
|
|
|
for most esp8266 modules, just pull GPIO0 down and restart.
|
2014-11-11 05:31:45 +01:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
#Connect the hardware in serial
|
|
|
|
braudrate:9600
|
2014-11-11 05:31:45 +01:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
#Start play
|
2014-11-11 05:31:45 +01:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
####Connect to your ap
|
2014-10-13 14:24:52 +02:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
```lua
|
|
|
|
print(wifi.sta.getip())
|
|
|
|
--0.0.0.0
|
2014-11-07 05:59:19 +01:00
|
|
|
wifi.setmode(wifi.STATION)
|
2014-11-12 17:17:08 +01:00
|
|
|
wifi.sta.config("SSID","password")
|
2014-11-07 05:59:19 +01:00
|
|
|
print(wifi.sta.getip())
|
2014-11-12 17:17:08 +01:00
|
|
|
--192.168.18.110
|
2014-11-07 05:59:19 +01:00
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
####Manipulate hardware like a arduino
|
|
|
|
|
|
|
|
```lua
|
|
|
|
pin = 1
|
|
|
|
gpio.mode(pin,gpio.OUTPUT)
|
|
|
|
gpio.write(pin,gpio.HIGH)
|
|
|
|
print(gpio.read(pin))
|
2014-11-07 05:59:19 +01:00
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
####Write network application in nodejs style
|
|
|
|
|
|
|
|
```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")
|
2014-11-07 05:59:19 +01:00
|
|
|
```
|
2014-10-13 14:24:52 +02:00
|
|
|
|
2014-11-12 17:17:08 +01:00
|
|
|
####Or a simple http server
|
|
|
|
|
|
|
|
```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)
|
|
|
|
```
|
|
|
|
|
|
|
|
####Do something shining
|
|
|
|
```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
|
|
|
|
```
|
|
|
|
|
|
|
|
####And blink it
|
|
|
|
```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)
|
|
|
|
```
|
|
|
|
|
|
|
|
####If you want to run something when system started
|
|
|
|
```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.
|
|
|
|
```
|
|
|
|
#Check this out
|
2014-11-12 17:19:26 +01:00
|
|
|
Tencent QQ group: 309957875<br/>
|
|
|
|
[nodemcu wiki](https://github.com/funshine/nodemcu-firmware/wiki/nodeMcu:-lua-based-interactive-firmware-for-mcu)<br/>
|
2014-11-12 17:17:08 +01:00
|
|
|
[nodemcu.com](http://www.nodemcu.com) comming soon~~~
|