准備工作
1.NodeMCU模塊
2.ESP8266Flasher.exe
3.ESPlorer v0.2.0-rc6
構建固件
Building the firmware提供了三種構建你自己固件的方式。
這里推薦使用簡單的雲構建服務NodeMCU custom builds來定制自己的固件,只需要在該網站選擇你需要的庫,留下郵箱,不一會就能收到編譯好的固件。
我選擇了這些庫:cjson,crypto,file,gpio,http,mqtt,net,node,pwm,tmr,uart,wifi,
You selected the following 12 modules:
crypto
file
gpio
http
mqtt
net
node
pwm
sjson
tmr
uart
wifi
.並勾選了
TLS/SSL support provided by mbed TLS: TLS 1.0 / 1.1 / 1.2 and most common cipher suites including DH/ECDH (ECDSA-based disabled by default).
幾分鍾后就可以在郵箱中收到固件下載地址了,分為float和integer兩個版本,請在24小時內下載。
刷入固件
下載nodemcu-flasher的Release版本,注意操作系統位數。
連接NodeMCU到電腦,運行flasher。
在Config選項卡下,配置好自己固件的路徑,我選的是float版本。
然后回到Operation下,點擊Flash(F),稍等片刻即可。寫入過程中藍色小燈閃爍。
上傳代碼
Uploading code同樣提供了多種工具來上傳代碼與文件到NodeMCU。
推薦使用ESPlorer,需要Java環境。下載ESPlorer.zip。
解壓后,運行ESPlorer.bat。
在ESPlorer窗口右上部,設置端口號。
點擊Open,按下NodeMCU上的RST按鈕重啟。
創建一個init.lua文件,這些代碼會使NodeMCU連接到一個AP(Access Point),通過修改第四行代碼來配置SSID和密碼。對於開放網絡,使用空文本作為密碼。
-- init.lua print('Setting up WIFI...') wifi.setmode(wifi.STATION) wifi.sta.config('WX401901', 'smyh1234') wifi.sta.connect() tmr.alarm(1, 1000, tmr.ALARM_AUTO, function() if wifi.sta.getip() == nil then print('Waiting for IP ...') else print('IP is ' .. wifi.sta.getip()) tmr.stop(1) end end)
保存后,點擊ESPlorer窗口左下區域的Upload ...來上傳。
上傳完畢后重啟NodeMCU。如果一切正常,你將看到NodeMCU成功連入你的AP。
相關資源
你也可以在NodeMCU-Tutorial下載到本文的相關資源和代碼。
本文是在 NodeMCU之旅(一):構建、刷入固件,上傳代碼 基礎之上的學習過程,感謝原作者。