2020年6月5日 星期五

從 esp-open-sdk 的原始碼自行編譯, 並建立 esp8266 開發環境

參考資料: https://github.com/cesanta/esp-open-sdk
1. 先安裝編譯工具
sudo apt-get install make unrar-free autoconf automake libtool gcc g++ gperf   flex  bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial  sed git unzip bash help2man wget bzip2  libtool-bin

2. 建立工作目錄, 下載 esp-open-sdk 原始碼
cd  &&  mkdir  esp8266
cd  esp8266
git  clone  --recursive  https://github.com/pfalcon/esp-open-sdk.git
cd  esp-open-sdk
make
 cd  ..

3.  到 github 找一個範例來練習,  Wifi Repeater 就是一個很實用的案例, 透過它可以延伸 Wifi 通訊的有效距離, 上官網https://github.com/martin-ger/esp_wifi_repeater 下載原始碼並解壓縮至工作目錄 esp_wifi_repeater-master, 接著在 linux 開發環境設定好環境變數 PATH 加入已編譯好的 cross compiler 所在路徑:
cd  esp8266
wget  https://github.com/martin-ger/esp_wifi_repeater/archive/master.zip
unzip  master.zip
PATH=~/esp8266/esp-open-sdk/xtensa-lx106-elf/bin:$PATH

4. 修改檔案內容 esp_wifi_repeater-master/user/user_config.h, 改連家裡的 Wifi
    #define        WIFI_SSID         "ssid"
    #define        WIFI_PASSWORD     "password"
    #define        REMOTE_MONITORING   0

5. 修改檔案內容 esp_wifi_repeater-master/user/user_main.c,  找到 4301 行的定義
     int i;
將上述行從 #if ACLS ... #endif 搬出來

6. 修改完存檔, 切到 esp_wifi_repeater-master 目錄, 開始編譯
cd  esp8266/esp_wifi_repeater-master
make

7. 將 esp8266 的開發板接上 USB, 將上述編譯完的程式寫入
make flash

Note: 若無法寫入可能是 /dev/ttyUSB0 權限沒開, 將 linux 使用者 mint 加入 dialout 群組再重新開機
sudo  usermod -a  -G  dialout  mint

8.把 esp8266 開發板重新開機, 用手機掃描上述設定的 ssid, 得到 ip 應該是 192.168.4.x, 再用瀏覽器打開網頁連上 http://192.168.4.1, 如有需要可以將它修改存檔, 這個 wifi repeater 一開始不會問密碼? 那是因為密碼設定為 none, 因此可以透過網頁將他改設為 WPA2  後再存檔就能解決, 不用的時候也最好把電源關掉,避免被侵入手機透過家裡的 Wifi 連上網際網路.一切順利的話, 恭喜完成超便宜的 Wifi repeater.



2020年6月4日 星期四

使用 esp8266 開發板, 設定 freeRTOS 開發環境

參考資料:https://github.com/espressif/ESP8266_RTOS_SDK
1. 下載 xtensa toolchain, 設定環境變數  PATH
cd  &&  mkdir  toolchain
cd toolchain
wget  https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz
tar -xvf xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz
PATH=~/toolchain/xtensa-lx106-elf/bin:$PATH
cd ..

2. 下載支援 esp8266 版本的 RTOS SDK, 設定環境變數  IDF_PATH
cd toolchain
git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git
export  IDF_PATH=~/toolchain/ESP8266_RTOS_SDK

3. 安裝 python 工具
sudo   apt-get   install   python-pip   python-setuptools
pip install wheel
python -m pip install --user -r $IDF_PATH/requirements.txt

4. 複製範例
cp -r  $IDF_PATH/examples/get-started/hello_world .
cd  hello_world
make menuconfig
make

p.s. 安裝好 toolchain 後, 只要將下列環境變數的設定加入 .bashrc 後面, 下次開啟終端機時就能直接 compile 程式了
PATH=~/toolchain/xtensa-lx106-elf/bin:$PATH
export IDF_PATH=~/toolchain/ESP8266_RTOS_SDK








簡單 c 程式碼, 根據五行八卦相生相剋推斷吉凶

#include "stdio.h" // 五行: //               木2 //      水1           火3 //         金0     土4 // // 先天八卦 vs 五行 //                    ...