ESP-WROOM-32を使ってみる

# ESP-WROOM-32を使ってみる
以前購入して放置していたESP-WROOM-32の開発環境の整備をして、GitHubにあったESP32用のOPC UA Serverがインストールできないか試してみる。

## 開発環境
### Arduino IDE ARDUNO 1.8.10
https://www.arduino.cc/en/Main/Software

Windowsは、赤枠のInstaller付きのものをダウンロード
![arduino-ide.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/28184/0f58c43b-e3e6-91fc-7914-3ecc6e46c8ae.png)


### Arduino-esp32
https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md
下の赤枠のURLをコピーします。
![arduino-ide.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/28184/b272bc1f-3749-deb0-f6c9-f9f55d2c5e5a.png)

```
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
```

ファイルの環境設定を開き、上記でコピーしたURLを赤枠で囲んだ「追加のボードマネージャーのURL」のところへペーストします。
![arduino-ide2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/28184/c7d76de1-ae38-da33-8c29-81df10248474.png)

ツールのボードからボードマネージャを開き、赤枠のテキストボックスところへESP32を入力すると、「esp32 by Espressif Systems」が検索されますので、インストール釦を押下します。
![arduino-ide2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/28184/f86021f4-9b5e-cdac-b793-ea28363884f0.png)

再度ツールからボードを選ぶと「ESP32 Dev Module」が追加されているので選択します。

### ドライバ
PCとESP-WROOM-32の接続が上手くいかなかったら以下のURLからドライバを入手してインストールします。
https://jp.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers


Arduino IDEのツールのシリアルポートから接続が認識できればOKです。

### Lチカ
ファイルのスケッチ例から01.BasicsのBlinkを使ってLEDを点滅させます。

BlinkのサンプルコードのLED_BUILTINを13に変更します。

```c

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
```

今回はGPIO13(画像の5)とGND(画像の6)にLEDをそのまま挿してチカチカさせました。
![IMG_4910.JPG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/28184/5e51e74f-76c1-163f-0348-73ae0759d6d9.jpeg)

## OPC UA
放置していたESP-WROOM-32の動作確認もできたので、GitHubにあったESP32用のOPC UAサーバを使ってみようかと思います。
https://github.com/cmbahadir/opcua-esp32

同じところにOPC UAのパブリッシャーもあります。
https://github.com/cmbahadir/opcua-pubsub-esp32

同じくOPC UAクライアントも！
https://github.com/cmbahadir/opcua-esp32-client

### 使用スタック
Open62541
https://github.com/open62541/open62541

### 開発環境
ESP-IDF　V3.2
https://docs.espressif.com/projects/esp-idf/en/latest/get-started/

#### 環境設定
ESP-IDFと環境変数の設定

##### ツールチェインのダウンロード
以下のURLからツールチェインをダウンロードしてc:\に展開します。
https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain-20180110.zip

#### ESP-IDFをGitHubから取得
c:\msys32\の中にあるmingw32.exeを起動して以下のコマンドを入力します。

```
$ mkdir -p esp
$ cd esp
$ git clone --recursive https://github.com/espressif/esp-idf.git
```
#### ESP-IDFの環境変数を設定
C:\msys32\etc\profile.dフォルダにexport_idf_path.shというファイルを作り以下のように記述しておきます。


```bash:export_idf_path.sh
export IDF_PATH="C:/msys32/home/<ユーザー名>/esp/esp-idf"
```

#### OPC UA サーバをGitHubから取得

```
$ mkdir esp/examples
$ cd esp/examples
$ git clone https://github.com/cmbahadir/opcua-esp32.git
```

#### OPC UA サーバのビルド
とりあえずmakeコマンドを実行したところ

```
The following Python requirements are not satisfied:
click>=5.0
pyelftools>=0.22
esp-windows-curses; sys_platform == 'win32'
The recommended way to install a packages is via "pacman". Please run "pacman -Ss <package_name>" for searching the package database and if found then "pacman -S mingw-w64-i686-python2-<package_name>" for installing it.
NOTE: You may need to run "pacman -Syu" if your package database is older and run twice if the previous run updated "pacman" itself.
Please read https://github.com/msys2/msys2/wiki/Using-packages for further information about using "pacman"
make: *** 'all' に必要なターゲット 'check_python_dependencies' を make するルールがありません.  中止.
```

というエラーが出たので、色々と検索したところ
https://www.mgo-tec.com/esp32-idf-howto-01
にPythonのパッケージが足りていないようなので以下のコマンドを入力しては？という書き込みがあったので、以下のコマンドを実行。

```
$ python -m pip install --user -r $IDF_PATH/requirements.txt
Processing //${idf_path}/toolskconfig_new/esp-windows-curses
Exception:
Traceback (most recent call last):
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/download.py", line 809, in unpack_url
    unpack_file_url(link, location, download_dir, hashes=hashes)
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/download.py", line 715, in unpack_file_url
    unpack_file(from_path, location, content_type, link)
  File "C:/msys32/mingw32/lib/python2.7/site-packages/pip/utils/__init__.py", line 602, in unpack_file
    tarfile.is_tarfile(filename) or
  File "C:/msys32/mingw32/lib/python2.7/tarfile.py", line 2624, in is_tarfile
    t = open(name)
  File "C:/msys32/mingw32/lib/python2.7/tarfile.py", line 1675, in open
    return func(name, "r", fileobj, **kwargs)
  File "C:/msys32/mingw32/lib/python2.7/tarfile.py", line 1740, in gzopen
    fileobj = gzip.GzipFile(name, mode, compresslevel, fileobj)
  File "C:/msys32/mingw32/lib/python2.7/gzip.py", line 94, in __init__
    fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
IOError: [Errno 2] No such file or directory: u'\\\\${IDF_PATH}\\toolskconfig_new\\esp-windows-curses'
You are using pip version 18.0, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
```

今度は、'python -m pip install --upgrade pip'を実行しろと出たので、その通りに実行。

```
$ python -m pip install --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting pip
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
    100% |################################| 1.4MB 468kB/s
Installing collected packages: pip
  Found existing installation: pip 18.0
    Uninstalling pip-18.0:
      Successfully uninstalled pip-18.0
Successfully installed pip-19.3.1
```

もう一度"python -m pip install --user -r $IDF_PATH/requirements.txt"を実行。

```
$ python -m pip install --user -r $IDF_PATH/requirements.txt
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Processing c:/msys32/home/toshi/esp/esp-idf/tools/kconfig_new/esp-windows-curses
Requirement already satisfied: setuptools>=21 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 4)) (40.4.3)
Collecting click>=5.0
  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
     |################################| 81kB 1.4MB/s
Requirement already satisfied: pyserial>=3.0 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 9)) (3.4)
Requirement already satisfied: future>=0.15.2 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 10)) (0.16.0)
Requirement already satisfied: cryptography>=2.1.4 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (2.3.1)
Requirement already satisfied: pyparsing<2.4.0,>=2.0.3 in c:/msys32/mingw32/lib/python2.7/site-packages (from -r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 12)) (2.2.0)
Collecting pyelftools>=0.22
  Downloading https://files.pythonhosted.org/packages/bb/2f/bf41f3c3867d6707fa9b872658bb23088a64d0e522e8979f54c694b8cbe1/pyelftools-0.26-py2.py3-none-any.whl (136kB)
     |################################| 143kB 6.5MB/s
Requirement already satisfied: idna>=2.1 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (2.7)
Requirement already satisfied: asn1crypto>=0.21.0 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (0.24.0)
Requirement already satisfied: six>=1.4.1 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (1.11.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (1.10.0)
Requirement already satisfied: enum34 in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (1.1.6)
Requirement already satisfied: ipaddress in c:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (1.0.22)
Requirement already satisfied: pycparser in c:/msys32/mingw32/lib/python2.7/site-packages (from cffi!=1.11.3,>=1.7->cryptography>=2.1.4->-r C:\msys32\home\toshi\esp\esp-idf/requirements.txt (line 11)) (2.19)
Installing collected packages: click, pyelftools, esp-windows-curses
    Running setup.py install for esp-windows-curses ... done
Successfully installed click-7.0 esp-windows-curses-0.1 pyelftools-0.26
```

と成功したようです。
ビルドする環境はこれでそろったようなので、再度makeコマンドを実行してみます。

```
$ make
Python requirements from C:/msys32/home/toshi/esp/esp-idf/requirements.txt are satisfied.
GENCONFIG
C:/msys32/home/toshi/esp/examples/opcua-esp32/sdkconfig:150 CONFIG_ESP32_APPTRACE_DEST_NONE was replaced with CONFIG_APPTRACE_DEST_NONE
C:/msys32/home/toshi/esp/examples/opcua-esp32/sdkconfig:151 CONFIG_ESP32_APPTRACE_LOCK_ENABLE was replaced with CONFIG_APPTRACE_LOCK_ENABLE
C:/msys32/home/toshi/esp/examples/opcua-esp32/sdkconfig:250 CONFIG_ESP32_DEBUG_STUBS_ENABLE was replaced with CONFIG_ESP_DEBUG_STUBS_ENABLE
App "opcua_esp32" version: 771b79f-dirty
WARNING: Toolchain version is not supported: crosstool-ng-1.22.0-80-g6c4433a5
Expected to see version: esp-2019r2
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
WARNING: Compiler version is not supported: 5.2.0
Expected to see version(s): 8.2.0
Please check ESP-IDF setup instructions and update the toolchain, or proceed at your own risk.
CC build/bootloader/bootloader_support/src/bootloader_random.o
CC build/bootloader/bootloader_support/src/flash_encrypt.o
CC build/bootloader/bootloader_support/src/esp_image_format.o
CC build/bootloader/bootloader_support/src/flash_partitions.o
CC build/bootloader/bootloader_support/src/bootloader_flash_config_esp32.o
CC build/bootloader/bootloader_support/src/bootloader_clock.o
CC build/bootloader/bootloader_support/src/bootloader_common.o
CC build/bootloader/bootloader_support/src/bootloader_utility.o
CC build/bootloader/bootloader_support/src/bootloader_init.o
CC build/bootloader/bootloader_support/src/flash_qio_mode.o
CC build/bootloader/bootloader_support/src/bootloader_flash.o
CC build/bootloader/bootloader_support/src/bootloader_efuse_esp32.o
CC build/bootloader/bootloader_support/src/esp32/flash_encrypt.o
CC build/bootloader/bootloader_support/src/esp32/bootloader_esp32.o
CC build/bootloader/bootloader_support/src/esp32/bootloader_sha.o
CC build/bootloader/bootloader_support/src/esp32/secure_boot.o
CC build/bootloader/bootloader_support/src/esp32/secure_boot_signatures.o
AR build/bootloader/bootloader_support/libbootloader_support.a
CC build/bootloader/log/log_buffers.o
CC build/bootloader/log/log_noos.o
CC build/bootloader/log/log.o
AR build/bootloader/log/liblog.a
CC build/bootloader/spi_flash/esp32/spi_flash_rom_patch.o
AR build/bootloader/spi_flash/libspi_flash.a
CC build/bootloader/micro-ecc/micro-ecc/uECC.o
AR build/bootloader/micro-ecc/libmicro-ecc.a
CC build/bootloader/soc/esp32/emac_hal.o
CC build/bootloader/soc/esp32/rtc_clk.o
CC build/bootloader/soc/esp32/rtc_time.o
CC build/bootloader/soc/esp32/rtc_sleep.o
CC build/bootloader/soc/esp32/gpio_periph.o
CC build/bootloader/soc/esp32/i2s_periph.o
CC build/bootloader/soc/esp32/rtc_clk_init.o
CC build/bootloader/soc/esp32/ledc_periph.o
CC build/bootloader/soc/esp32/spi_periph.o
CC build/bootloader/soc/esp32/rtc_init.o
CC build/bootloader/soc/esp32/sdio_slave_periph.o
CC build/bootloader/soc/esp32/rtc_periph.o
CC build/bootloader/soc/esp32/uart_periph.o
CC build/bootloader/soc/esp32/rtc_wdt.o
CC build/bootloader/soc/esp32/sdmmc_periph.o
CC build/bootloader/soc/esp32/adc_periph.o
CC build/bootloader/soc/esp32/i2c_periph.o
CC build/bootloader/soc/esp32/interrupts.o
CC build/bootloader/soc/esp32/cpu_util.o
CC build/bootloader/soc/esp32/touch_sensor_periph.o
CC build/bootloader/soc/esp32/rtc_io_periph.o
CC build/bootloader/soc/esp32/touch_sensor_hal.o
CC build/bootloader/soc/esp32/rtc_pm.o
CC build/bootloader/soc/esp32/soc_memory_layout.o
CC build/bootloader/soc/esp32/dac_periph.o
CC build/bootloader/soc/src/soc_include_legacy_warn.o
CC build/bootloader/soc/src/memory_layout_utils.o
CC build/bootloader/soc/src/lldesc.o
CC build/bootloader/soc/src/hal/pcnt_hal.o
CC build/bootloader/soc/src/hal/gpio_hal.o
CC build/bootloader/soc/src/hal/spi_flash_hal_gpspi.o
CC build/bootloader/soc/src/hal/ledc_hal.o
CC build/bootloader/soc/src/hal/rmt_hal.o
CC build/bootloader/soc/src/hal/ledc_hal_iram.o
CC build/bootloader/soc/src/hal/i2s_hal.o
CC build/bootloader/soc/src/hal/sdio_slave_hal.o
CC build/bootloader/soc/src/hal/timer_hal.o
CC build/bootloader/soc/src/hal/spi_hal_iram.o
CC build/bootloader/soc/src/hal/touch_sensor_hal.o
CC build/bootloader/soc/src/hal/uart_hal.o
CC build/bootloader/soc/src/hal/sigmadelta_hal.o
CC build/bootloader/soc/src/hal/spi_flash_hal.o
CC build/bootloader/soc/src/hal/uart_hal_iram.o
CC build/bootloader/soc/src/hal/spi_flash_hal_iram.o
CC build/bootloader/soc/src/hal/adc_hal.o
CC build/bootloader/soc/src/hal/i2c_hal.o
CC build/bootloader/soc/src/hal/i2c_hal_iram.o
CC build/bootloader/soc/src/hal/rtc_io_hal.o
CC build/bootloader/soc/src/hal/spi_slave_hal.o
CC build/bootloader/soc/src/hal/can_hal.o
CC build/bootloader/soc/src/hal/mcpwm_hal.o
CC build/bootloader/soc/src/hal/dac_hal.o
CC build/bootloader/soc/src/hal/spi_slave_hal_iram.o
CC build/bootloader/soc/src/hal/spi_hal.o
AR build/bootloader/soc/libsoc.a
CC build/bootloader/main/bootloader_start.o
AR build/bootloader/main/libmain.a
CC build/bootloader/efuse/esp32/esp_efuse_table.o
CC build/bootloader/efuse/src/esp_efuse_fields.o
CC build/bootloader/efuse/src/esp_efuse_utility.o
CC build/bootloader/efuse/src/esp_efuse_api.o
CC build/bootloader/efuse/src/esp32/esp_efuse_fields.o
CC build/bootloader/efuse/src/esp32/esp_efuse_utility.o
CC build/bootloader/efuse/src/esp32/esp_efuse_api.o
AR build/bootloader/efuse/libefuse.a
LD build/bootloader/bootloader.elf
esptool.py v2.9-dev
Python requirements from C:/msys32/home/toshi/esp/esp-idf/requirements.txt are satisfied.
Building partitions from /home/toshi/esp/esp-idf/components/partition_table/partitions_singleapp.csv...

CC build/app_trace/heap_trace_tohost.o
CC build/app_trace/app_trace.o
CC build/app_trace/host_file_io.o
CC build/app_trace/app_trace_util.o
CC build/app_trace/gcov/gcov_rtio.o
AR build/app_trace/libapp_trace.a
App "opcua_esp32" version: 771b79f-dirty
CC build/app_update/esp_app_desc.o
CC build/app_update/esp_ota_ops.o
AR build/app_update/libapp_update.a
CC build/bootloader_support/src/bootloader_random.o
CC build/bootloader_support/src/flash_encrypt.o
CC build/bootloader_support/src/esp_image_format.o
CC build/bootloader_support/src/flash_partitions.o
CC build/bootloader_support/src/bootloader_flash_config_esp32.o
CC build/bootloader_support/src/bootloader_clock.o
CC build/bootloader_support/src/bootloader_common.o
CC build/bootloader_support/src/bootloader_utility.o
CC build/bootloader_support/src/flash_qio_mode.o
CC build/bootloader_support/src/bootloader_flash.o
CC build/bootloader_support/src/bootloader_efuse_esp32.o
CC build/bootloader_support/src/idf/bootloader_sha.o
CC build/bootloader_support/src/idf/secure_boot_signatures.o
AR build/bootloader_support/libbootloader_support.a
CC build/cbor/tinycbor/src/cborencoder_close_container_checked.o
CC build/cbor/tinycbor/src/cborpretty_stdio.o
CC build/cbor/tinycbor/src/cbortojson.o
CC build/cbor/tinycbor/src/cborpretty.o
CC build/cbor/tinycbor/src/cborerrorstrings.o
CC build/cbor/tinycbor/src/cborencoder.o
CC build/cbor/tinycbor/src/cborparser_dup_string.o
CC build/cbor/tinycbor/src/open_memstream.o
CC build/cbor/tinycbor/src/cborvalidation.o
CC build/cbor/tinycbor/src/cborparser.o
AR build/cbor/libcbor.a
CC build/console/linenoise/linenoise.o
CC build/console/argtable3/argtable3.o
CC build/console/commands.o
CC build/console/split_argv.o
AR build/console/libconsole.a
CXX build/cxx/cxx_exception_stubs.o
CXX build/cxx/cxx_guards.o
AR build/cxx/libcxx.a
CC build/driver/adc.o
CC build/driver/rmt.o
CC build/driver/i2c.o
CC build/driver/rtc_io.o
CC build/driver/spi_slave.o
CC build/driver/can.o
CC build/driver/sdmmc_transaction.o
CC build/driver/mcpwm.o
CC build/driver/dac.o
CC build/driver/sdmmc_host.o
CC build/driver/sdspi_crc.o
CC build/driver/pcnt.o
CC build/driver/timer.o
CC build/driver/gpio.o
CC build/driver/sdspi_host.o
CC build/driver/uart.o
CC build/driver/ledc.o
CC build/driver/periph_ctrl.o
CC build/driver/i2s.o
CC build/driver/sdio_slave.o
CC build/driver/touch_sensor_common.o
CC build/driver/sdspi_transaction.o
CC build/driver/sigmadelta.o
CC build/driver/spi_master.o
CC build/driver/rtc_module.o
CC build/driver/spi_common.o
CC build/driver/esp32/touch_sensor.o
AR build/driver/libdriver.a
CC build/efuse/esp32/esp_efuse_table.o
CC build/efuse/src/esp_efuse_fields.o
CC build/efuse/src/esp_efuse_utility.o
CC build/efuse/src/esp_efuse_api.o
CC build/efuse/src/esp32/esp_efuse_fields.o
CC build/efuse/src/esp32/esp_efuse_utility.o
CC build/efuse/src/esp32/esp_efuse_api.o
AR build/efuse/libefuse.a
CC build/esp-tls/esp_tls.o
CC build/esp-tls/esp_tls_mbedtls.o
AR build/esp-tls/libesp-tls.a
CC build/esp32/int_wdt.o
CC build/esp32/brownout.o
CC build/esp32/esp_himem.o
CC build/esp32/dport_access.o
CC build/esp32/hw_random.o
CC build/esp32/pm_esp32.o
CC build/esp32/system_api_esp32.o
CC build/esp32/intr_alloc.o
CC build/esp32/cache_err_int.o
CC build/esp32/spiram.o
CC build/esp32/clk.o
CC build/esp32/spiram_psram.o
CC build/esp32/esp_timer_esp32.o
CC build/esp32/pm_trace.o
CC build/esp32/crosscore_int.o
CC build/esp32/cache_sram_mmu.o
CC build/esp32/cpu_start.o
CC build/esp32/sleep_modes.o
CC build/esp32/task_wdt.o
CC build/esp32/reset_reason.o
CC build/esp32/panic.o
AS build/esp32/dport_panic_highint_hdl.o
AR build/esp32/libesp32.a
CC build/esp_adc_cal/esp_adc_cal.o
AR build/esp_adc_cal/libesp_adc_cal.a
CC build/esp_common/src/esp_timer.o
CC build/esp_common/src/stack_check.o
CC build/esp_common/src/esp_err_to_name.o
CC build/esp_common/src/pm_locks.o
CC build/esp_common/src/ipc.o
CC build/esp_common/src/ets_timer_legacy.o
CC build/esp_common/src/freertos_hooks.o
CC build/esp_common/src/mac_addr.o
CC build/esp_common/src/system_api.o
CC build/esp_common/src/dbg_stubs.o
AR build/esp_common/libesp_common.a
CC build/esp_eth/src/esp_eth_netif_glue.o
CC build/esp_eth/src/esp_eth_phy_dm9051.o
CC build/esp_eth/src/esp_eth_phy_dp83848.o
CC build/esp_eth/src/esp_eth_mac_dm9051.o
CC build/esp_eth/src/esp_eth.o
CC build/esp_eth/src/esp_eth_phy_rtl8201.o
CC build/esp_eth/src/esp_eth_mac_esp32.o
CC build/esp_eth/src/esp_eth_phy_ip101.o
CC build/esp_eth/src/esp_eth_phy_lan8720.o
CC build/esp_eth/src/esp_eth_phy.o
AR build/esp_eth/libesp_eth.a
CC build/esp_event/esp_event_private.o
CC build/esp_event/event_loop_legacy.o
CC build/esp_event/esp_event.o
CC build/esp_event/event_send.o
CC build/esp_event/default_event_loop.o
AR build/esp_event/libesp_event.a
CC build/esp_gdbstub/src/gdbstub.o
CC build/esp_gdbstub/src/packet.o
CC build/esp_gdbstub/esp32/gdbstub_esp32.o
CC build/esp_gdbstub/xtensa/gdbstub_xtensa.o
AR build/esp_gdbstub/libesp_gdbstub.a
CC build/esp_http_client/esp_http_client.o
CC build/esp_http_client/lib/http_utils.o
CC build/esp_http_client/lib/http_auth.o
CC build/esp_http_client/lib/http_header.o
AR build/esp_http_client/libesp_http_client.a
CC build/esp_http_server/src/httpd_sess.o
CC build/esp_http_server/src/httpd_parse.o
CC build/esp_http_server/src/httpd_uri.o
CC build/esp_http_server/src/httpd_txrx.o
CC build/esp_http_server/src/httpd_main.o
CC build/esp_http_server/src/util/ctrl_sock.o
AR build/esp_http_server/libesp_http_server.a
CC build/esp_https_ota/src/esp_https_ota.o
AR build/esp_https_ota/libesp_https_ota.a
CC build/esp_local_ctrl/src/esp_local_ctrl.o
CC build/esp_local_ctrl/src/esp_local_ctrl_handler.o
CC build/esp_local_ctrl/proto-c/esp_local_ctrl.pb-c.o
AR build/esp_local_ctrl/libesp_local_ctrl.a
CC build/esp_netif/esp_netif_handlers.o
CC build/esp_netif/esp_netif_objects.o
CC build/esp_netif/esp_netif_defaults.o
CC build/esp_netif/lwip/esp_netif_lwip_defaults.o
CC build/esp_netif/lwip/esp_netif_lwip.o
CC build/esp_netif/lwip/esp_netif_sta_list.o
CC build/esp_netif/lwip/esp_netif_lwip_ppp.o
CC build/esp_netif/loopback/esp_netif_loopback.o
AR build/esp_netif/libesp_netif.a
CC build/esp_ringbuf/ringbuf.o
AR build/esp_ringbuf/libesp_ringbuf.a
CC build/esp_rom/esp_rom.o
AR build/esp_rom/libesp_rom.a
CC build/esp_serial_slave_link/essl.o
CC build/esp_serial_slave_link/essl_sdio.o
AR build/esp_serial_slave_link/libesp_serial_slave_link.a
CC build/esp_websocket_client/esp_websocket_client.o
AR build/esp_websocket_client/libesp_websocket_client.a
CC build/esp_wifi/src/wifi_init.o
CC build/esp_wifi/src/wifi_netif.o
CC build/esp_wifi/src/coexist.o
CC build/esp_wifi/src/smartconfig_ack.o
CC build/esp_wifi/src/mesh_event.o
CC build/esp_wifi/src/phy_init.o
CC build/esp_wifi/src/wifi_default.o
CC build/esp_wifi/src/smartconfig.o
CC build/esp_wifi/src/lib_printf.o
CC build/esp_wifi/esp32/esp_adapter.o
AR build/esp_wifi/libesp_wifi.a
CC build/espcoredump/src/core_dump_elf.o
CC build/espcoredump/src/core_dump_uart.o
CC build/espcoredump/src/core_dump_common.o
CC build/espcoredump/src/core_dump_flash.o
CC build/espcoredump/src/core_dump_port.o
AR build/espcoredump/libespcoredump.a
CC build/fatfs/diskio/diskio.o
CC build/fatfs/diskio/diskio_sdmmc.o
CC build/fatfs/diskio/diskio_rawflash.o
CC build/fatfs/diskio/diskio_wl.o
CC build/fatfs/vfs/vfs_fat.o
CC build/fatfs/vfs/vfs_fat_spiflash.o
CC build/fatfs/vfs/vfs_fat_sdmmc.o
CC build/fatfs/port/freertos/ffsystem.o
CC build/fatfs/src/ffunicode.o
CC build/fatfs/src/ff.o
AR build/fatfs/libfatfs.a
CC build/freertos/xtensa_overlay_os_hook.o
CC build/freertos/FreeRTOS-openocd.o
CC build/freertos/timers.o
CC build/freertos/tasks.o
CC build/freertos/event_groups.o
CC build/freertos/port.o
CC build/freertos/xtensa_init.o
CC build/freertos/list.o
CC build/freertos/croutine.o
CC build/freertos/queue.o
CC build/freertos/xtensa_intr.o
AS build/freertos/portasm.o
AS build/freertos/xtensa_vector_defaults.o
AS build/freertos/xtensa_vectors.o
AS build/freertos/xtensa_context.o
AS build/freertos/xtensa_intr_asm.o
AR build/freertos/libfreertos.a
CC build/heap/heap_caps_init.o
In file included from C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_private.h:20:0,
                 from C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_caps_init.c:14:
C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_caps_init.c: In function 'heap_caps_add_region_with_caps':
C:/msys32/home/toshi/esp/esp-idf/components/heap/multi_heap_platform.h:32:20: error: the comparison will always evaluate as 'true' for the address of 'registered_heaps_write_lock' will never be NULL [-Werror=address]
         if((PLOCK) != NULL) {                               \
                    ^
C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_caps_init.c:230:5: note: in expansion of macro 'MULTI_HEAP_LOCK'
     MULTI_HEAP_LOCK(&registered_heaps_write_lock);
     ^
C:/msys32/home/toshi/esp/esp-idf/components/heap/multi_heap_platform.h:39:21: error: the comparison will always evaluate as 'true' for the address of 'registered_heaps_write_lock' will never be NULL [-Werror=address]
         if ((PLOCK) != NULL) {                              \
                     ^
C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_caps_init.c:232:5: note: in expansion of macro 'MULTI_HEAP_UNLOCK'
     MULTI_HEAP_UNLOCK(&registered_heaps_write_lock);
     ^
C:/msys32/home/toshi/esp/esp-idf/components/heap/heap_caps_init.c: At top level:
cc1.exe: warning: unrecognized command line option '-Wno-frame-address'
cc1.exe: some warnings being treated as errors
make[1]: *** [/home/toshi/esp/esp-idf/make/component_wrapper.mk:292: heap_caps_init.o] エラー 1
make: *** [C:\msys32\home\toshi\esp\esp-idf/make/project.mk:604: component-heap-build] エラー 2
$
```
ビルドがエラーになりました。
ぼちぼち調べよう。
Windows&Msys32よりも素直にLinuxとか使った方が良いのだろうか。

ESP-IDFのVer4.xから使用するツールチェーンが変更になったらしく、バージョンが合わないとエラーが出るらしい。
https://github.com/espressif/esp-idf/issues/4601

今回は、ESP-IDFを最新でツールチェーンはVer3.x用だったので、どちらに合わせるか考えて、とりあえず実績のあるVer3.xに戻してみることにします。

```
$ git clone -b v3.3.1 --recursive https://github.com/espressif/esp-idf.git
```
ESP-IDFを入れ替えたところで、make cleanして綺麗にしてからビルドします。

```
$ make
make[1]: ディレクトリ '/home/toshi/esp/esp-idf/tools/kconfig' に入ります
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/mconf.c -o mconf.o
flex -L -Pzconf -ozconf.lex.c /home/toshi/esp/esp-idf/tools/kconfig/zconf.l
bison -t -l -p zconf -o zconf.tab.c /home/toshi/esp/esp-idf/tools/kconfig/zconf.y
sed -E "s/\\x0D$//" /home/toshi/esp/esp-idf/tools/kconfig/zconf.gperf | gperf -t --output-file zconf.hash.c -a -C -E -g -k '1,3,$' -p -t
/usr/bin/gcc -I /home/toshi/esp/esp-idf/tools/kconfig -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  zconf.tab.c -o zconf.tab.o
/home/toshi/esp/esp-idf/tools/kconfig/lxdialog/check-lxdialog.sh -check /usr/bin/gcc  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP -lncursesw -lintl
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/checklist.c -o lxdialog/checklist.o
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/util.c -o lxdialog/util.o
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/inputbox.c -o lxdialog/inputbox.o
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/textbox.c -o lxdialog/textbox.o
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/yesno.c -o lxdialog/yesno.o
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/lxdialog/menubox.c -o lxdialog/menubox.o
/usr/bin/gcc -o mconf-idf mconf.o zconf.tab.o lxdialog/checklist.o lxdialog/util.o lxdialog/inputbox.o lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o -lncursesw -lintl
/usr/bin/gcc -c  -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"  -DNCURSES_WIDECHAR=1 -DLOCALE -MMD -MP  /home/toshi/esp/esp-idf/tools/kconfig/conf.c -o conf.o
/usr/bin/gcc -o conf-idf conf.o  zconf.tab.o -lncursesw -lintl
make[1]: ディレクトリ '/home/toshi/esp/esp-idf/tools/kconfig' から出ます
GENCONFIG
App "opcua_esp32" version: 771b79f-dirty
CC build/bootloader/bootloader_support/src/bootloader_random.o
CC build/bootloader/bootloader_support/src/flash_encrypt.o
CC build/bootloader/bootloader_support/src/bootloader_sha.o
CC build/bootloader/bootloader_support/src/esp_image_format.o
CC build/bootloader/bootloader_support/src/flash_partitions.o
CC build/bootloader/bootloader_support/src/bootloader_flash_config.o
CC build/bootloader/bootloader_support/src/bootloader_clock.o
CC build/bootloader/bootloader_support/src/secure_boot.o
CC build/bootloader/bootloader_support/src/bootloader_common.o
CC build/bootloader/bootloader_support/src/bootloader_utility.o
CC build/bootloader/bootloader_support/src/bootloader_init.o
CC build/bootloader/bootloader_support/src/secure_boot_signatures.o
CC build/bootloader/bootloader_support/src/flash_qio_mode.o
CC build/bootloader/bootloader_support/src/bootloader_flash.o
AR build/bootloader/bootloader_support/libbootloader_support.a
CC build/bootloader/log/log.o
AR build/bootloader/log/liblog.a
CC build/bootloader/spi_flash/spi_flash_rom_patch.o
AR build/bootloader/spi_flash/libspi_flash.a
CC build/bootloader/micro-ecc/micro-ecc/uECC.o
AR build/bootloader/micro-ecc/libmicro-ecc.a
CC build/bootloader/soc/esp32/rtc_clk.o
CC build/bootloader/soc/esp32/rtc_time.o
CC build/bootloader/soc/esp32/rtc_sleep.o
CC build/bootloader/soc/esp32/gpio_periph.o
CC build/bootloader/soc/esp32/rtc_clk_init.o
CC build/bootloader/soc/esp32/spi_periph.o
CC build/bootloader/soc/esp32/rtc_init.o
CC build/bootloader/soc/esp32/sdio_slave_periph.o
CC build/bootloader/soc/esp32/rtc_wdt.o
CC build/bootloader/soc/esp32/sdmmc_periph.o
CC build/bootloader/soc/esp32/cpu_util.o
CC build/bootloader/soc/esp32/rtc_periph.o
CC build/bootloader/soc/esp32/rtc_pm.o
CC build/bootloader/soc/esp32/soc_memory_layout.o
CC build/bootloader/soc/src//memory_layout_utils.o
AR build/bootloader/soc/libsoc.a
CC build/bootloader/main/bootloader_start.o
AR build/bootloader/main/libmain.a
CC build/bootloader/efuse/esp32/esp_efuse_table.o
CC build/bootloader/efuse/src/esp_efuse_fields.o
CC build/bootloader/efuse/src/esp_efuse_utility.o
CC build/bootloader/efuse/src/esp_efuse_api.o
AR build/bootloader/efuse/libefuse.a
LD build/bootloader/bootloader.elf
esptool.py v2.8
Python requirements from C:/msys32/home/toshi/esp/esp-idf/requirements.txt are satisfied.
Building partitions from /home/toshi/esp/esp-idf/components/partition_table/partitions_singleapp.csv...

CC build/app_trace/app_trace.o
CC build/app_trace/host_file_io.o
CC build/app_trace/app_trace_util.o
CC build/app_trace/gcov/gcov_rtio.o
AR build/app_trace/libapp_trace.a
App "opcua_esp32" version: 771b79f-dirty
CC build/app_update/esp_app_desc.o
CC build/app_update/esp_ota_ops.o
AR build/app_update/libapp_update.a
CC build/bootloader_support/src/bootloader_random.o
CC build/bootloader_support/src/flash_encrypt.o
CC build/bootloader_support/src/bootloader_sha.o
CC build/bootloader_support/src/esp_image_format.o
CC build/bootloader_support/src/flash_partitions.o
CC build/bootloader_support/src/bootloader_flash_config.o
CC build/bootloader_support/src/bootloader_clock.o
CC build/bootloader_support/src/secure_boot.o
CC build/bootloader_support/src/bootloader_common.o
CC build/bootloader_support/src/bootloader_utility.o
CC build/bootloader_support/src/secure_boot_signatures.o
CC build/bootloader_support/src/flash_qio_mode.o
CC build/bootloader_support/src/bootloader_flash.o
AR build/bootloader_support/libbootloader_support.a
CC build/console/linenoise/linenoise.o
CC build/console/argtable3/argtable3.o
CC build/console/commands.o
CC build/console/split_argv.o
AR build/console/libconsole.a
CXX build/cxx/cxx_exception_stubs.o
CXX build/cxx/cxx_guards.o
AR build/cxx/libcxx.a
CC build/driver/rtc_module.o
CC build/driver/i2c.o
CC build/driver/sdmmc_host.o
CC build/driver/spi_slave.o
CC build/driver/can.o
CC build/driver/sdmmc_transaction.o
CC build/driver/mcpwm.o
CC build/driver/rmt.o
CC build/driver/sdspi_crc.o
CC build/driver/pcnt.o
CC build/driver/timer.o
CC build/driver/gpio.o
CC build/driver/sdspi_host.o
CC build/driver/ledc.o
CC build/driver/periph_ctrl.o
CC build/driver/i2s.o
CC build/driver/sdio_slave.o
CC build/driver/sdspi_transaction.o
CC build/driver/uart.o
CC build/driver/sigmadelta.o
CC build/driver/spi_master.o
CC build/driver/spi_common.o
AR build/driver/libdriver.a
CC build/efuse/esp32/esp_efuse_table.o
CC build/efuse/src/esp_efuse_fields.o
CC build/efuse/src/esp_efuse_utility.o
CC build/efuse/src/esp_efuse_api.o
AR build/efuse/libefuse.a
CC build/esp-tls/esp_tls.o
AR build/esp-tls/libesp-tls.a
CC build/esp32/restore.o
CC build/esp32/int_wdt.o
CC build/esp32/brownout.o
CC build/esp32/system_api.o
CC build/esp32/esp_himem.o
CC build/esp32/dport_access.o
CC build/esp32/esp_timer.o
CC build/esp32/hw_random.o
CC build/esp32/esp_err_to_name.o
CC build/esp32/pm_esp32.o
CC build/esp32/event_loop.o
CC build/esp32/pm_locks.o
CC build/esp32/fast_crypto_ops.o
CC build/esp32/coexist.o
CC build/esp32/reset_reason.o
CC build/esp32/ets_timer_legacy.o
CC build/esp32/intr_alloc.o
CC build/esp32/ipc.o
CC build/esp32/cache_err_int.o
CC build/esp32/wifi_init.o
CC build/esp32/spiram.o
CC build/esp32/freertos_hooks.o
CC build/esp32/clk.o
CC build/esp32/spiram_psram.o
CC build/esp32/esp_timer_esp32.o
CC build/esp32/lib_printf.o
CC build/esp32/pm_trace.o
CC build/esp32/phy_init.o
CC build/esp32/crosscore_int.o
CC build/esp32/gdbstub.o
CC build/esp32/cache_sram_mmu.o
CC build/esp32/cpu_start.o
CC build/esp32/dbg_stubs.o
CC build/esp32/sleep_modes.o
CC build/esp32/task_wdt.o
CC build/esp32/event_default_handlers.o
CC build/esp32/esp_adapter.o
CC build/esp32/stack_check.o
CC build/esp32/panic.o
CC build/esp32/hwcrypto/aes.o
CC build/esp32/hwcrypto/sha.o
AS build/esp32/dport_panic_highint_hdl.o
AR build/esp32/libesp32.a
CC build/esp_adc_cal/esp_adc_cal.o
AR build/esp_adc_cal/libesp_adc_cal.a
CC build/esp_event/esp_event_private.o
CC build/esp_event/esp_event.o
CC build/esp_event/default_event_loop.o
AR build/esp_event/libesp_event.a
CC build/esp_http_client/esp_http_client.o
CC build/esp_http_client/lib/http_utils.o
CC build/esp_http_client/lib/http_auth.o
CC build/esp_http_client/lib/http_header.o
AR build/esp_http_client/libesp_http_client.a
CC build/esp_http_server/src/httpd_sess.o
CC build/esp_http_server/src/httpd_parse.o
CC build/esp_http_server/src/httpd_uri.o
CC build/esp_http_server/src/httpd_txrx.o
CC build/esp_http_server/src/httpd_main.o
CC build/esp_http_server/src/util/ctrl_sock.o
AR build/esp_http_server/libesp_http_server.a
CC build/esp_https_ota/src/esp_https_ota.o
AR build/esp_https_ota/libesp_https_ota.a
CC build/esp_https_server/src/https_server.o
C:/msys32/home/toshi/esp/esp-idf/components/esp_https_server/src/https_server.c:17:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.
make[1]: *** [/home/toshi/esp/esp-idf/make/component_wrapper.mk:290: src/https_server.o] エラー 1
make: *** [C:\msys32\home\toshi\esp\esp-idf/make/project.mk:552: component-esp_https_server-build] エラー 2

$
```
今度はopensslのssl.hがないとのこと、先は長い。

___
#### OPC UA サーバのところに書いてあった手順

```
git clone --recursive https://github.com/espressif/esp-idf.git <your-esp-idf-root-path>
export IDF_PATH=<your-esp-idf-root-path>
export PATH=$PATH:<xtensa-toolchain-path>
cd <your-esp-idf-root-path>/examples/
git clone https://github.com/cmbahadir opcua-esp32
cd opcua-esp32
make flash
```

今度はheap_caps_init.cのところでエラーになりました。
先は長い...。


（つづく）