MacでM5stack Core2 for AWS

#0. はじめに
なんとなーく、<a href="http://switch-science.com/">スイッチサイエンス</a>を徘徊していたら、
<a href="https://www.switch-science.com/catalog/6784/">M5Stack Core2 for AWS - ESP32 IoT開発キット</a>とかいう面白そうなデバイスを発見！
AWSを使ってIoTのお勉強ができるっぽい。
〜ポチ！〜2日後に着〜

そこそこハマりどころがあるので、メモがてら投稿

例によって初心者なので間違っていたらゴメンナサイ🙏
環境はMacOS Catalina 10.15.7

#1. はじめはサラサラと
スイッチサイエンスの<a href="https://www.switch-science.com/catalog/6784/">商品ページ</a>には詳細が英語しかないように書かれていますが、
<a href="https://edukit.workshop.aws/jp/">日本語ページ</a>もあります！　やったね

というわけで、上のページを見ながら進めていきました。
<font color="red">※ドキュメントはよくできているので、以降ハマったところを書いています</font>
##1-1. <a href="https://edukit.workshop.aws/jp/getting-started/prerequisites.html#silicon-labs-usb-to-uart-ブリッジドライバのインストール">ドライバのインストール</a>
macOS 10.9+を開くとMavericks以降はすでに組み込み済みとのこと。
念のために確認！

```
% kextstat | grep usb.serial
  186    1 0xffffff7f8470d000 0x6000     0x6000     com.apple.driver.usb.serial (6.0.0) 8D86815D-64E8-39C5-A879-263C5052B11B <61 21 6 5 3 1>
```

なんか出たから大丈夫っぽい。

##1-2. <a href="https://edukit.workshop.aws/jp/getting-started/prerequisites.html#visual-studio-code-のインストール">Visual Studio Codeのインストール</a>
<a href="https://code.visualstudio.com/">ここ</a>から

##1-3. <a href="https://edukit.workshop.aws/jp/getting-started/prerequisites.html#platformio-のインストール">PlatformIO のインストール</a>
１．Visual Studio Codeを起動したら、Extensionsを開く
（左側の□が4つあるアイコンをクリックするかcommand+shift+x)
２．platformio ideを検索
３．青いinstallをクリック
![スクリーンショット 2021-02-11 17.25.28.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/605817/9e090ca9-2e0f-a31a-a5eb-2a3f7fd423f2.png)

##1-4. あとは
あとはドキュメント通り、
・スマホにESP RainMakerをインストール
・Githubからソースを持ってくる
・MacとM5StackをUSB接続
ここまでは迷うとこはないですな

#2. ESP RainMaker Agent の実行
##2-1. 第１のつまずき
ドキュメント通りに進めていって、
<a href="https://edukit.workshop.aws/jp/getting-started/run-rainmaker.html#rainmaker-agent-ファームウェアのビルドとアップロード">RainMaker Agent ファームウェアのビルドとアップロード</a>の
buildまでは普通に進みましたが、Upload & Monitorでエラー発生！
スクショ取り忘れましたが
<b>/dev/cu.SLAB_USBtoUARTなんてないよ</b>
みたいなエラーだったと。。。
というわけでterminalで

```
% ls /dev/cu.SLAB_USBtoUART
ls: /dev/cu.SLAB_USBtoUART: No such file or directory
```

たしかにない。。。
じゃあコレは？

```
% ls /dev/cu.*
/dev/cu.Bluetooth-Incoming-Port	/dev/cu.usbserial-0225F023
```
どうも<b>/dev/cu.usbserial-0225F023</b>が正解っぽい
というわけで、platformio.iniファイルのupload_portを変更

```ini:platformio.ini
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter, extra scripting
;   Upload options: custom port, speed and extra flags
;   Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html

[env:core2foraws]
platform = espressif32@2.1.0
framework = espidf
board = esp32dev
;upload_port = /dev/cu.SLAB_USBtoUART
upload_port = /dev/cu.usbserial-0225F023

monitor_speed = 115200
board_build.partitions = partitions_4MB_sec.csv

board_build.embed_txtfiles = 
  components/esp_rainmaker/server_certs/mqtt_server.crt
  components/esp_rainmaker/server_certs/claim_service_server.crt
  components/esp_rainmaker/server_certs/ota_server.crt
```

もう一回buildしてからUpload & Monitor！

```
> Executing task: pio run --target upload --target monitor --environment core2foraws <

Processing core2foraws (platform: espressif32@2.1.0; framework: espidf; board: esp32dev)
-----------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (2.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf 3.40100.200827 (4.1.0) 
 - tool-cmake 3.16.4 
 - tool-esptoolpy 1.30000.201119 (3.0.0) 
 - tool-mkspiffs 2.230.0 (2.30) 
 - tool-ninja 1.9.0 
 - toolchain-esp32ulp 1.22851.191205 (2.28.51) 
 - toolchain-xtensa32 2.80200.200827 (8.2.0)
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio/build/core2foraws/firmware.elf
Checking size .pio/build/core2foraws/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  26.8% (used 87864 bytes from 327680 bytes)
Flash: [========= ]  95.0% (used 1555753 bytes from 1638400 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Use manually specified: /dev/cu.usbserial-0225F023
Uploading .pio/build/core2foraws/firmware.bin
esptool.py v3.0
Serial port /dev/cu.usbserial-0225F023
Connecting.....
Chip is ESP32-D0WDQ6-V3 (revision 3)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 24:0a:c4:f9:9f:ac
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 16MB
Flash params set to 0x0240
Compressed 26912 bytes to 16214...
Writing at 0x00001000... (100 %)
Wrote 26912 bytes (16214 compressed) at 0x00001000 in 0.4 seconds (effective 538.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 159...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (159 compressed) at 0x00008000 in 0.0 seconds (effective 1370.5 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 31...
Writing at 0x00016000... (100 %)
Wrote 8192 bytes (31 compressed) at 0x00016000 in 0.0 seconds (effective 4094.4 kbit/s)...
Hash of data verified.
Compressed 1555872 bytes to 889938...
Writing at 0x00020000... (1 %)
Writing at 0x00024000... (3 %)
Writing at 0x00028000... (5 %)
Writing at 0x0002c000... (7 %)
Writing at 0x00030000... (9 %)
Writing at 0x00034000... (10 %)
Writing at 0x00038000... (12 %)
Writing at 0x0003c000... (14 %)
Writing at 0x00040000... (16 %)
Writing at 0x00044000... (18 %)
Writing at 0x00048000... (20 %)
Writing at 0x0004c000... (21 %)
Writing at 0x00050000... (23 %)
Writing at 0x00054000... (25 %)
Writing at 0x00058000... (27 %)
Writing at 0x0005c000... (29 %)
Writing at 0x00060000... (30 %)
Writing at 0x00064000... (32 %)
Writing at 0x00068000... (34 %)
Writing at 0x0006c000... (36 %)
Writing at 0x00070000... (38 %)
Writing at 0x00074000... (40 %)
Writing at 0x00078000... (41 %)
Writing at 0x0007c000... (43 %)
Writing at 0x00080000... (45 %)
Writing at 0x00084000... (47 %)
Writing at 0x00088000... (49 %)
Writing at 0x0008c000... (50 %)
Writing at 0x00090000... (52 %)
Writing at 0x00094000... (54 %)
Writing at 0x00098000... (56 %)
Writing at 0x0009c000... (58 %)
Writing at 0x000a0000... (60 %)
Writing at 0x000a4000... (61 %)
Writing at 0x000a8000... (63 %)
Writing at 0x000ac000... (65 %)
Writing at 0x000b0000... (67 %)
Writing at 0x000b4000... (69 %)
Writing at 0x000b8000... (70 %)
Writing at 0x000bc000... (72 %)
Writing at 0x000c0000... (74 %)
Writing at 0x000c4000... (76 %)
Writing at 0x000c8000... (78 %)
Writing at 0x000cc000... (80 %)
Writing at 0x000d0000... (81 %)
Writing at 0x000d4000... (83 %)
Writing at 0x000d8000... (85 %)
Writing at 0x000dc000... (87 %)
Writing at 0x000e0000... (89 %)
Writing at 0x000e4000... (90 %)
Writing at 0x000e8000... (92 %)
Writing at 0x000ec000... (94 %)
Writing at 0x000f0000... (96 %)
Writing at 0x000f4000... (98 %)
Writing at 0x000f8000... (100 %)
Wrote 1555872 bytes (889938 compressed) at 0x00020000 in 22.2 seconds (effective 561.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
=============================================== [SUCCESS] Took 40.56 seconds ===============================================
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on /dev/cu.usbserial-0225F023  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
␛[0;32mI (719) esp_image: segment 5: paddr=0x00185710 vaddr=0x40087fa4 size=0x16664 ( 91748) load␛[0m
␛[0;32mI (777) boot: Loaded app from partition at offset 0x20000␛[0m
␛[0;32mI (832) boot: Set actual ota_seq=1 in otadata[0]␛[0m
␛[0;32mI (832) boot: Disabling RNG early entropy source...␛[0m
␛[0;32mI (833) psram: This chip is ESP32-D0WD␛[0m
␛[0;32mI (837) spiram: Found 64MBit SPI RAM device␛[0m
␛[0;32mI (841) spiram: SPI RAM mode: flash 80m sram 80m␛[0m
␛[0;32mI (846) spiram: PSRAM initialized, cache is in low/high (2-core) mode.␛[0m
␛[0;32mI (854) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (857) cpu_start: Application information:␛[0m
␛[0;32mI (862) cpu_start: Project name:     AWS_IoT_EduKit-Getting_Started␛[0m
␛[0;32mI (869) cpu_start: App version:      3c5aa62-dirty␛[0m
␛[0;32mI (875) cpu_start: Compile time:     Feb 12 2021 23:41:21␛[0m
␛[0;32mI (881) cpu_start: ELF file SHA256:  9747349fbca1eb77...␛[0m
␛[0;32mI (887) cpu_start: ESP-IDF:          3.40100.200827␛[0m
␛[0;32mI (892) cpu_start: Starting app cpu, entry point is 0x400830b0␛[0m
␛[0;32mI (0) cpu_start: App cpu up.␛[0m
␛[0;32mI (1396) spiram: SPI SRAM memory test OK␛[0m
␛[0;32mI (1396) heap_init: Initializing. RAM available for dynamic allocation:␛[0m
␛[0;32mI (1396) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM␛[0m
␛[0;32mI (1402) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM␛[0m
␛[0;32mI (1408) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM␛[0m
␛[0;32mI (1415) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM␛[0m
␛[0;32mI (1421) heap_init: At 3FFD3298 len 0000CD68 (51 KiB): DRAM␛[0m
␛[0;32mI (1427) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM␛[0m
␛[0;32mI (1434) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM␛[0m
␛[0;32mI (1440) heap_init: At 4009E608 len 000019F8 (6 KiB): IRAM␛[0m
␛[0;32mI (1446) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (1451) spiram: Adding pool of 4096K of external SPI memory to heap allocator␛[0m
␛[0;32mI (1471) spi_flash: detected chip: generic␛[0m
␛[0;32mI (1472) spi_flash: flash io: qio␛[0m
␛[0;32mI (1472) cpu_start: Starting scheduler on PRO CPU.␛[0m
␛[0;32mI (0) cpu_start: Starting scheduler on APP CPU.␛[0m
␛[0;32mI (1481) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations␛[0m
␛[0;32mI (1511) gpio: GPIO[39]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 1| Intr:3 ␛[0m
␛[0;32mI (1711) ILI9341: Initialization.␛[0m
␛[0;32mI (1911) ILI9341: Display orientation: LANDSCAPE␛[0m
␛[0;32mI (1911) ILI9341: 0x36 command value: 0x08␛[0m
I (2011) wifi:wifi driver task: 3ffd6044, prio:23, stack:6656, core=0
␛[0;32mI (2011) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE␛[0m
␛[0;32mI (2011) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE␛[0m
I (2211) wifi:wifi firmware version: 3ea4c76
I (2211) wifi:config NVS flash: enabled
I (2211) wifi:config nano formating: disabled
I (2211) wifi:Init dynamic tx buffer num: 32
I (2211) wifi:Init data frame dynamic rx buffer num: 16
I (2221) wifi:Init management frame dynamic rx buffer num: 16
I (2221) wifi:Init management short buffer num: 32
I (2231) wifi:Init static tx buffer num: 8
I (2231) wifi:Init static rx buffer size: 1600
I (2231) wifi:Init static rx buffer num: 4
I (2241) wifi:Init dynamic rx buffer num: 16
␛[0;32mI (2251) esp_claim: Initialising Assisted Claiming. This may take time.␛[0m
␛[0;33mW (2251) esp_claim: Generating the private key. This may take time.␛[0m
␛[0;32mI (67941) esp_rmaker_node: Node ID ----- 240AC4F99FAC␛[0m
␛[0;32mI (67941) display: configuring the house␛[0m
␛[0;32mI (67941) display: house configured␛[0m
␛[0;32mI (67951) display: lights off␛[0m
␛[0;32mI (69361) display: configuring the temperature␛[0m
␛[0;32mI (69361) display: temperature configured␛[0m
␛[0;32mI (69451) display: configuring the fan␛[0m
␛[0;32mI (69451) display: configured fan_object␛[0m
␛[0;32mI (69451) display: configured fan_strength_slider␛[0m
␛[0;32mI (69451) display: configured fan_sw1␛[0m
␛[0;32mI (69451) display: fan configured␛[0m
␛[0;32mI (69461) esp_rmaker_time_sync: Initializing SNTP. Using the SNTP server: pool.ntp.org␛[0m
␛[0;32mI (69471) esp_rmaker_core: Starting RainMaker Core Task␛[0m
␛[0;32mI (69481) esp_claim: Waiting for assisted claim to finish.␛[0m
␛[0;32mI (69481) wifi_prov_scheme_ble: BT memory released␛[0m
␛[0;32mI (69481) app_wifi: Starting provisioning␛[0m
␛[0;33mW (69501) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration␛[0m
␛[0;32mI (69631) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 2␛[0m
I (69691) wifi:mode : sta (24:0a:c4:f9:9f:ac)
␛[0;32mI (69701) BTDM_INIT: BT controller compile version [219866f]␛[0m
␛[0;32mI (69701) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE␛[0m
␛[0;32mI (69881) protocomm_nimble: BLE Host Task Started␛[0m
␛[0;32mI (69891) wifi_prov_mgr: Provisioning started with service name : PROV_02167d ␛[0m
␛[0;32mI (69891) app_wifi: Provisioning started␛[0m
␛[0;32mI (69891) app_wifi: Scan this QR code from the phone app for Provisioning.␛[0m
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=256 adv_itvl_max=256
                                      
  █▀▀▀▀▀█ ▄█ ▄▄ █▄▀ ▀▀██▀▀█ █▀▀▀▀▀█   
  █ ███ █ ▄█▀█ ▄ ▄▄▄▀ ▄▀▀▀▀ █ ███ █   
  █ ▀▀▀ █ ▄ █ ▀▄ ▄█ █▀ ▀█▀█ █ ▀▀▀ █   
  █▀████▀▄▀█▄█▀▀ █ ▀█▄▄▄█▄ █▀▄  ▄█    
    ▀█▀ ▀█▀█▄▀▄▀ ▀██▀▄▀▄▀▀ ▀▄▀▀ ▄▀▄   
   ▀ ▀▀ ▄▀▀▄▄▄█▀▀ ▀▄ ▀▄ ▄ ▄  ▄█▀ ▄▀▄   
  ▄▀▀█▄█▀▄  ▄▀▄█▀ ▄▀██▀  ▀▀▄▄█▀ ▄ ▄   
    ▀ ██▀▄▄▄▀ ▀▀▀▀█▀▄▄ ▄    ▄▀▀▀ █▄   
  █  ▀▄█▀▄▄   ▄ ▀█▀▀█▄ █▀▄█ █▀▄▄▄▄▄   
  ▀ ▀  ▀▀▀█▀█ ▀▀▀▀▄██▄ ▄ ▄█▀▀▀██▄▄█   
  █▀▀▀▀▀█ ▀███▀ █▀  ▄  ▄ ▄█ ▀ █ ▄▀    
  █ ███ █ █▀█▀█▀ ▀█▀█▄█▄█ █▀▀██▀▄▀    
  █ ▀▀▀ █ █ ▀  ▀ █▄▀█▄██ ▄█ ▀█▄▀█▀    
  ▀▀▀▀▀▀▀ ▀  ▀ ▀▀▀▀▀ ▀  ▀▀▀ ▀▀   ▀    
                                      
```

なんとかQRコード表示までうまくいったようです
アスキーアートでQRコードが出るとは思わなかったｗ
ターミナルでの表示なので確かに絵はでないか。。。
ちなみに上のQRコードは加工しています。

おそらくM5Stackの画面はこんな感じになっていると思います。
ファンのアイコンの下のスライドスイッチあたり触ると
「ぶーーん」とファンが回りますｗ
![IMG_4707_2.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/605817/cb37768d-0f8c-5283-d490-509d6e31f04d.png)

##2-2. あとは
あとはドキュメント通り、ESP RainMakerにデバイス登録すれば、
スマホ側からFanのOn/Offとか明るさ変えたりとかできると思います^^

#3. <a href="https://edukit.workshop.aws/jp/blinky-hello-world/prerequisites.html#esp-idf-v42-のインストール">ESP-IDF v4.2 のインストール</a>
##3-1. やっぱりココでもつまづく

ドキュメントにある下のコマンドを実行！！！

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install cmake ninja dfu-util
mkdir $HOME/esp
cd $HOME/esp
git clone -b release/v4.2 --recursive https://github.com/espressif/esp-idf.git
cd $HOME/esp/esp-idf
. $HOME/esp/esp-idf/install.sh
. $HOME/esp/esp-idf/export.sh
```

そして<b><font color="red">エラー</font></b> :cold_sweat:

```
〜〜〜いろいろ省略〜〜〜
Installing Python environment and packages
Creating a new Python environment in /Users/オレ/.espressif/python_env/idf4.2_py2.7_env
Installing virtualenv
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip
Traceback (most recent call last):
  File "/Users/オレ/esp/esp-idf/tools/idf_tools.py", line 1492, in <module>
    main(sys.argv[1:])
  File "/Users/オレ/esp/esp-idf/tools/idf_tools.py", line 1488, in main
    action_func(args)
  File "/Users/オレ/esp/esp-idf/tools/idf_tools.py", line 1205, in action_install_python_env
    stdout=sys.stdout, stderr=sys.stderr)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '-m', 'pip', 'install', '--user', 'virtualenv']' returned non-zero exit status 1

[プロセスが完了しました]
```
う〜ん、どうするかな。。。
。。。とりあえずpython3にしちゃおうｗ
コケているのは、
<b>. $HOME/esp/esp-idf/install.sh</b>
brewはインストールされている
ということで、、、

pyenvをインストール

```
% brew install pyenv
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 11 formulae.

==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.catalina.bottle.4.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/ca510b350e941fb9395522a03f9d2fb5df276085d806ceead763acb95889a368?response-content-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2_3.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/80f141e695f73bd058fd82e9f539dc67471666ff6800c5e280b5af7d3050f435?response-content-
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.22.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/b4f3038e29acde1d99579104ae100777621b9716fe797e7917dad1e9795d3473?response-content-
######################################################################## 100.0%
==> Installing dependencies for pyenv: autoconf and pkg-config
==> Installing pyenv dependency: autoconf
==> Pouring autoconf-2.69.catalina.bottle.4.tar.gz
🍺  /usr/local/Cellar/autoconf/2.69: 67 files, 3.0MB
==> Installing pyenv dependency: pkg-config
==> Pouring pkg-config-0.29.2_3.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 623.8KB
==> Installing pyenv
==> Pouring pyenv-1.2.22.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pyenv/1.2.22: 721 files, 2.6MB
```

で、python３は何をいれようかなー
最新はいくつかな〜

```
% pyenv install --list
Available versions:
  2.1.3
  2.2.3
  2.3.7
〜〜〜中略〜〜〜
  3.9.0
  3.9-dev
  3.9.1
  3.10-dev
  activepython-2.7.14
  activepython-3.5.4
〜〜〜以下略〜〜〜
```
ということで3.9.1に決定！
早速インストール

```
% pyenv install 3.9.1
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.1.tar.xz...
-> https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
Installing Python-3.9.1...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.9.1 to /Users/オレ/.pyenv/versions/3.9.1
```

無事インストール完了
ちゃんとpyenvでみられるか確認して、3.9.1を使うように。。。

```
% pyenv versions      
* system (set by /Users/オレ/.pyenv/version)
  3.9.1
% pyenv global 3.9.1
% pyenv rehash
% pyenv versions    
  system
* 3.9.1 (set by /Users/オレ/.pyenv/version)
```
で、.bash_profileに

```bash:.bash_profile
PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
```

shellがzshなので

```
% bash
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

bash-3.2$ cd
bash-3.2$ source .bash_profile 
bash-3.2$ python --version
Python 3.9.1
```
ということでpythonを実行すると3.9.1が起動するように〜
とりあえずpipも最新にしておこ

```
bash-3.2$ pip install --upgrade pip
Collecting pip
  Using cached pip-21.0.1-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-21.0.1
```
やっとこさ環境がそろったので
コケていたinstall.shを〜

```
bash-3.2$ cd $HOME/esp/esp-idf
bash-3.2$ . $HOME/esp/esp-idf/install.sh
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, esp32ulp-elf, esp32s2ulp-elf, openocd-esp32
Skipping xtensa-esp32-elf@esp-2020r3-8.4.0 (already installed)
Skipping xtensa-esp32s2-elf@esp-2020r3-8.4.0 (already installed)
Skipping esp32ulp-elf@2.28.51-esp-20191205 (already installed)
Skipping esp32s2ulp-elf@2.28.51-esp-20191205 (already installed)
Skipping openocd-esp32@v0.10.0-esp32-20200709 (already installed)
Installing Python environment and packages
Creating a new Python environment in /Users/オレ/.espressif/python_env/idf4.2_py3.9_env
Installing virtualenv
Collecting virtualenv
  Downloading virtualenv-20.4.2-py2.py3-none-any.whl (7.2 MB)
     |████████████████████████████████| 7.2 MB 6.7 MB/s 
Collecting distlib<1,>=0.3.1
  Downloading distlib-0.3.1-py2.py3-none-any.whl (335 kB)
     |████████████████████████████████| 335 kB 30.1 MB/s 
Collecting six<2,>=1.9.0
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)

〜〜〜省略〜〜〜

Successfully installed Flask-0.12.5 Flask-Compress-1.8.0 Flask-SocketIO-2.9.6 Jinja2-2.11.3 MarkupSafe-1.1.1 Pygments-2.7.4 Werkzeug-0.16.1 bidict-0.21.2 bitstring-3.1.7 brotli-1.0.9 cffi-1.14.5 click-7.1.2 cryptography-3.4.4 ecdsa-0.16.1 future-0.18.2 gdbgui-0.13.2.0 gevent-1.5.0 greenlet-1.0.0 itsdangerous-1.1.0 pycparser-2.20 pyelftools-0.27 pygdbmi-0.9.0.2 pyparsing-2.3.1 pyserial-3.5 python-engineio-4.0.0 python-socketio-5.0.4 reedsolo-1.5.4 six-1.15.0
All done! You can now run:

  . ./export.sh

```
インストールできた模様😁
あとはexport.sh

```
bash-3.2$ . $HOME/esp/esp-idf/export.sh
Adding ESP-IDF tools to PATH...
Using Python interpreter in /Users/オレ/.espressif/python_env/idf4.2_py3.9_env/bin/python
Checking if Python packages are up to date...
Python requirements from /Users/オレ/esp/esp-idf/requirements.txt are satisfied.
Added the following directories to PATH:
  /Users/オレ/esp/esp-idf/components/esptool_py/esptool
  /Users/オレ/esp/esp-idf/components/espcoredump
  /Users/オレ/esp/esp-idf/components/partition_table
  /Users/オレ/esp/esp-idf/components/app_update
  /Users/オレ/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin
  /Users/オレ/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf/bin
  /Users/オレ/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin
  /Users/オレ/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin
  /Users/オレ/.espressif/tools/openocd-esp32/v0.10.0-esp32-20200709/openocd-esp32/bin
  /Users/オレ/.espressif/python_env/idf4.2_py3.9_env/bin
  /Users/オレ/esp/esp-idf/tools
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

bash-3.2$ idf
idf.py          idf_monitor.py  idf_size.py     idf_tools.py    
bash-3.2$ 
```

というわけで、idf.pyできるようになった！（っぽい)🙌

Qiita書くのに疲れたので次回につづく。。。🙀