NodeMCU入門(5):Docker Image 構建固件,開啟SmartConfig


准備工作

1.NodeMCU模塊

2.ESP8266Flasher.exe

3.EspTouch.apk

3.docker toolbox(win7系統) 或 docker(win10以上),本教程是在win7系統上開發,Win7安裝Docker

選擇構建固件方式

NodeMCU入門(2):在線構建、刷入固件,上傳代碼 中提到固件編譯有三種方式,官方說明,當時我們選擇了Cloud Build Service。

Tools

Cloud Build Service

NodeMCU "application developers" just need a ready-made firmware. There's a cloud build servicewith a nice UI and configuration options for them.

Docker Image

Occasional NodeMCU firmware hackers don't need full control over the complete tool chain. They might not want to setup a Linux VM with the build environment. Docker to the rescue. Give Docker NodeMCU build a try.

Linux Build Environment

NodeMCU firmware developers commit or contribute to the project on GitHub and might want to build their own full fledged build environment with the complete tool chain. There is a post in the esp8266.com Wiki that describes this.

做完NodeMCU入門(4):搭建Web服務器,配置網絡連接之后想實現SmartConfig時,需要執行wifi.startsmart()方法。

wifi.setmode(wifi.STATION)
wifi.startsmart(0,
    function(ssid, password)
        print(string.format("Success. SSID:%s ; PASSWORD:%s", ssid, password))
    end
) 

執行報錯:

NodeMCU custom build by frightanic.com
branch: master
commit: c8ac5cfb912ff206b03dd7c60ffbb2dafb83fe5e
SSL: true
modules: crypto,file,gpio,http,mqtt,net,node,pwm,sjson,tmr,uart,wifi,tls
build built on: 2017-06-10 01:42
powered by Lua 5.1.4 on SDK 2.1.0(116b762)
lua: init.lua:2: attempt to call field 'startsmart' (a nil value)
stack traceback:
init.lua:2: in main chunk
[C]: ?

這問題真的郁悶了半天,構建固件時選擇了wifi模塊為什么不能調用startsmart?!仔細看文檔、仔細看文檔、仔細看文檔。。。

默認沒有開啟,這坑貨啊,這么常用的功能竟然沒開啟,無奈之下智能自己動手豐衣足食了。

剛開始是想采用第三種方式Linux Build Environment,因為看到過有大神封裝了一個visualbox的虛機提供下載(現在找不到鏈接了),也找到了中文的教程nodemcu固件編譯方法(不是很懂),post in the esp8266.com Wiki  一大片英文字母(感覺有難度)。以前接觸過docker,所以就選擇Docker Image 方式吧。

構建固件

1. 安裝Docker

win7系統參考Win7安裝Docker,其它系統參考 https://docs.docker.com/ → 'Get Started' 

 2.獲取NodeMCU固件代碼

 git clone https://github.com/nodemcu/nodemcu-firmware.git

   也可以在瀏覽器中打開 https://github.com/nodemcu/nodemcu-firmware.git,下載壓縮包,然后解壓到C:\Users\zhaobaolong(替換成你的賬號名字)\nodemcu-firmware目錄下。

  

3.運行nodemcu-build,編譯固件

 運行docker輸入如下命令:

docker run --rm -it -v "//C/Users/zhaobaolong/nodemcu-firmware":/opt/nodemcu-firmware marcelstoer/nodemcu-build

 然后開始編譯,這個過程要等很久,我這大約半個多小時。

 

最后在C:\Users\zhaobaolong\nodemcu-firmware\bin目錄下生成了固件文件

 

 刷入固件到NodeMCU模塊

沒有了保護的模塊信息以及版本信息,看着不爽哈,外國小朋友也提出來了,http://stackoverflow.com/questions/41102558/general-questions-about-docker-nodemcu-build

問題

Some general questions about the docker nodemcu-build process:

  1. Is there a way to specify which modules are included in the build? (similar to the way the cloud build service works)

  2. Is there a way to include a description that will appear when the resultant firmware is run?

  3. Is SSL enabled?

  4. The size of the bin file created by the docker nodemcu-build process (from dev branch source) is 405k. A recent build using the cloud service resulted in a bin file of size 444k. The cloud service build only included the following modules: cjson, file, gpio, http, net, node, tmr, uart, wifi, ssl. Why is the docker build bin file, that contains all modules(?), smaller than the cloud build bin file that only contains 10 modules? (i am concerned that my local docker build version is missing something - even though the build process was error free).

答案:

  1. You specify the modules to be built by uncommenting them in the /app/include/user_modules.hfile in the source tree. The default build from the source tree is relatively minimal - not an "all modules" build.

  2. The banner at connection is the "Version" field. The nodemcu-build.com builds change this out for custom text. It is defined in /app/include/user_version.h as the USER_VERSION define. You'll need to embed "\n" newlines in the string to get separate lines.

  3. Yes, the Net module can include limited SSL support (TLS 1.1 only) (TLS 1.2 in dev per Marcel's comment below). You need to enable it in /app/include/user_config.h by defining CLIENT_SSL_ENABLE.

  4. The default module and config setup in user_modules.h / user_config.h is different than the defaults on nodemcu-build.com, so the builds are not likely to be the same out of the box.

 

修改固件重新編譯,刷固件 

1.修改\app\include\user_modules.h文件,把 crypto file gpio http mqtt net node pwm sjson tmr uart wifi都放開。有的默認就開了,沒有放開的就把前面的注釋去掉。

2.修改\app\include\user_config.h文件,把 //#define WIFI_SMART_ENABLE開頭的注釋去掉,//#define CLIENT_SSL_ENABLE 開頭的注釋也去掉

3.修改\app\include\user_version.h文件,修改 #define __USER_VERSION_H__ "NodeMCU custom build by zeroes QQ305744659"

4. 保存文件后重新編譯,20多分鍾完成

docker run --rm -it -v "//C/Users/zhaobaolong/nodemcu-firmware":/opt/nodemcu-firmware marcelstoer/nodemcu-build

5.刷固件,重啟模塊,沒有把預期的模塊信息顯示出來有點小失望。

wifi.setmode(wifi.STATION)
wifi.startsmart(0,
    function(ssid, password)
        print(string.format("Success. SSID:%s ; PASSWORD:%s", ssid, password))
    end
)

 上傳代碼,通過手機上的EspTouch測試SmartConfig功能。

完美,准備睡覺已經到兩點半了。。。。。

 

參考鏈接 

http://espressif.com/zh-hans/support/explore/get-started/esp8266/getting-started-guide  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM