以前、環境センサのバッテリ長時間連続運用の時に使ったESP8266搭載の ESP-01S に、 ESP Easy を初めて焼いてみて、 Ser2Net シリアルサーバ機能を使ってみます。ESP-01Sは、これまで使ってきた他のESP系と比べても、そのコンパクトさが特徴的で、少ないながらもGPIOやシリアルも備えています。
フラッシュの焼き込みはUSBシリアルでもいいのですが、ESP−01S専用のゲタを持っているので、これを使います。
使い方はゲタにESP-01Sを挿して母艦にUSB接続するのみ、とても簡単です。
焼き込みはesptool.pyを使ってみます。
1 2 3 4 5 |
$ sudo esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio -fs 1MB 0x00000 ./ESP_Easy_mega_20200516_test_ESP8266_4M1M_VCC.bin esptool.py v2.8 Serial port /dev/ttyUSB0 Connecting........_____....._____....._____....._____....._____....._____....._____ A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header |
デバイスをプログラミングモードにせずに焼こうとするとこうなります。ESP-01SのIO0をGNDに落とすことでプログラミングモードとなるようですが、何せピンは最小構成。
先人さまの例を参考にして、手持ちの部品でジャンパ接続してみました。ハンダ付けしていないので取り外し可能、通常モードでも使用可能とする汎用性を維持出来ました。
早速焼いてみると、あっさり成功します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ sudo esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio -fs 1MB 0x00000 ./ESP_Easy_mega_20200516_test_ESP8266_4M1M_VCC.bin esptool.py v2.8 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266EX Features: WiFi Crystal is 26MHz MAC: 5c:cf:7f:28:e6:2a Uploading stub... Running stub... Stub running... Configuring flash size... Flash params set to 0x0220 Compressed 1029360 bytes to 665862... Wrote 1029360 bytes (665862 compressed) at 0x00000000 in 58.6 seconds (effective 140.4 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin... |
一度母艦から引き抜いて、挿し直して起動してみると、何やら定期的に基板上のLEDが光ります。これはコケて再起動繰り返している兆候。シリアルから覗いてみると、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
INIT : Booting version: (ESP82xx Core 9c56ed1f, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support) 70 : Info : INIT : Free RAM:30976 71 : Info : INIT : Warm boot #2 Last Task: Background Task Last systime: 0 - Restart Reason: Exception 72 : Info : FS : Mounting... FS : Mount failed 74 : Error : FS : Mount failed RESET: Resetting factory defaults... using default settings RESET: Warm boot, reset count: 3 RESET: Too many resets, protecting your flash memory (powercycle to solve this) 1077 : Info : CRC : No program memory checksum found. Check output of crc2.py 1079 : Error : FS : Error while reading/writing config.dat in 984 1080 : Info : WIFI : Start network scan PID:0 Version:0 INIT : Incorrect PID or version! RESET: Resetting factory defaults Exception (0): epc1=0x4000e25d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000 >>>stack>>> ctx: cont sp: 3fff2e70 end: 3fff30f0 offset: 0190 3fff3000: 3fff164c 3fff166c 3fff0df8 3fff1fb0 3fff3010: 40290522 00000000 3fff479c 40290629 3fff3020: 0000001c 00000000 00000000 00000000 3fff3030: 00000003 3fff166c 3fff426c 4029085e 3fff3040: 00000000 00000001 3fff1fb0 3fff1fb0 3fff3050: 00000000 00000001 3fff1fb0 4028a71c 3fff3060: 00000000 ffffffff ffffffff 4028e6c6 3fff3070: 00000000 0000001c 00000000 402903be 3fff3080: 3fff0e21 3fff164c 3fff1a20 40210430 3fff3090: 3fff0e21 3fff164c 3fff1a20 4027477c 3fff30a0: 3fff4000 0020002f 80290000 40298604 3fff30b0: 3fff4694 005a006f 00efeffe feefeffe 3fff30c0: feefeffe feefeffe feefeffe 3fff313c 3fff30d0: 3fffdad0 00000000 3fff30f8 4028d730 3fff30e0: feefeffe feefeffe 3ffe8760 401007d5 <<<stack<<< ets Jan 8 2013,rst cause:2, boot mode:(3,0) load 0x4010f000, len 3656, room 16 tail 8 chksum 0x0c csum 0x0c v9c56ed1f ~ld |
実は焼いたバイナリは、普段使うESP-12E用の物でした。あらためて1MBなESP-01S用でVcc計測可能なバイナリを見付けて焼き直します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ sudo esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio -fs 1MB 0x00000 ./ESP_Easy_mega_20200516_normal_ESP8266_1M_VCC.bin esptool.py v2.8 Serial port /dev/ttyUSB0 Connecting.... Detecting chip type... ESP8266 Chip is ESP8266EX Features: WiFi Crystal is 26MHz MAC: 5c:cf:7f:28:e6:2a Uploading stub... Running stub... Stub running... Configuring flash size... Flash params set to 0x0220 Compressed 857424 bytes to 563995... Wrote 857424 bytes (563995 compressed) at 0x00000000 in 49.7 seconds (effective 138.1 kbit/s)... Hash of data verified. Leaving... Hard resetting via RTS pin... |
ピンを通常モードに戻して起動させると今度は問題無さそう。ESP Easyの初期状態は自身がAPとなっているので、スマホから「ESP_Easy」と言うSSIDを探して接続、もし、パスワード必要ならそれは「espconfig」でしょう(ESP-12Eに焼いた時は不要でした)。その後、スマホのブラウザで192.168.4.1にアクセスしてGUIを開き、LANのWiFiへと繋ぎ直させます。最後にESP Easyは、繋ぎ直して変わったIPアドレスを以下のように教えてくれるはずです。
早速GUIから、ESP EasyのInfoページを確認してみると、Flash Chip Real Sizeが1024kBになっていることが特徴的です(ESP-12Eは4096kB)。
Ser2Netと呼ばれるシリアルサーバ機能は、Deviceから設定出来ます。設定後はリモートからtelnetでこのシリアルコンソールへアクセスします。
Raspberry Pi 1初号機に繋いでみました。この機体は自分にとって初めてのRaspberry Piなのですが、今でもRDL-SDRや環境ステーションとして現役です。
sshで直接Raspberry Piへアクセスする場合と異なり、ESP-01S小判鮫からシリアル経由で操作する大きな違いは、「再起動時のログを鑑賞することが出来る」点に尽きるでしょう。ほぼこれが今回の主目的です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
pi@pi1:~$ sudo shutdown -r now sudo shutdown -r now Stopping Manage Sound Card State (restore and store)... [ OK ] Started Show Plymouth Reboot Screen. [ OK ] Stopped dump1090 ADS-B rece…er (FlightAware customization). [ OK ] Stopped Manage Sound Card State (restore and store). [ OK ] Stopped User Manager for UID 1000. Stopping User Runtime Directory /run/user/1000... [ OK ] Unmounted /run/user/1000. [ OK ] Stopped User Runtime Directory /run/user/1000. [ OK ] Removed slice User Slice of UID 1000. Stopping Permit User Sessions... [ OK ] Stopped Permit User Sessions. [ OK ] Stopped target Remote File Systems. [ OK ] Stopped target Remote File Systems (Pre). [ OK ] Stopped target NFS client services. [ OK ] Stopped Flightradar24 Decoder & Feeder. [ OK ] Stopped target Network is Online. [ OK ] Stopped target Network. Stopping WPA supplicant... Stopping dhcpcd on all interfaces... Stopping Raise network interfaces... ... ... ...略 ... ... Stopping Restore / save the current clock... [ 107.727639] reboot: Restarting system [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.19.97+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1294 Thu Jan 30 13:10:54 GMT 2020 [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache [ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B Rev 2 [ 0.000000] Memory policy: Data cache writeback [ 0.000000] cma: Reserved 8 MiB at 0x1b400000 [ 0.000000] random: get_random_bytes called from start_kernel+0x8c/0x494 with crng_init=0 [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 113680 [ 0.000000] Kernel command line: coherent_pool=1M bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:6D:15:5E vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=PARTUUID=a3d11fe1-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait [ 0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes) [ 0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes) [ 0.000000] Memory: 434156K/458752K available (7144K kernel code, 656K rwdata, 2128K rodata, 472K init, 797K bss, 16404K reserved, 8192K cma-reserved) [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) [ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB) [ 0.000000] vmalloc : 0xdc800000 - 0xff800000 ( 560 MB) [ 0.000000] lowmem : 0xc0000000 - 0xdc000000 ( 448 MB) [ 0.000000] modules : 0xbf000000 - 0xc0000000 ( 16 MB) [ 0.000000] .text : 0x(ptrval) - 0x(ptrval) (7146 kB) [ 0.000000] .init : 0x(ptrval) - 0x(ptrval) ( 472 kB) [ , Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] ftrace: allocating 25657 entries in 76 pages [ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16 [ 0.000030] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns [ 0.000092] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns [ 0.000219] bcm2835: system timer (irq = 27) [ 0.000638] Console: colour dummy device 80x30 [ 0.001279] console [tty1] enabled [ 0.001361] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792) [ 0.060398] pid_max: default: 32768 minimum: 301 [ 0.060980] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.061042] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.062493] CPU: Testing write buffer coherency: ok [ 0.063853] Setting up static identity map for 0x8200 - 0x8238 [ 0.065323] devtmpfs: initialized [ 0.076492] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5 [ 0.076977] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.077053] futex hash table entries: 256 (order: -1, 3072 bytes) [ 0.078424] pinctrl core: initialized pinctrl subsystem [ 0.080056] NET: Registered protocol family 16 [ 0.083373] DMA: preallocated 1024 KiB pool for atomic coherent allocations [ 0.090829] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers. [ 0.090904] hw-breakpoint: maximum watchpoint size is 4 bytes. [ 0.091073] Serial: AMBA PL011 UART driver [ 0.094370] bcm2835-mbox 2000b880.mailbox: mailbox enabled [ 0.110707] raspberrypi-firmware soc:firmware: Attached to firmware from 2020-02-12 12:38, variant start [ 0.120736] raspberrypi-firmware soc:firmware: Firmware hash is 53a54c770c493957d99bf49762dfabc4eee00e45 [ 0.173244] bcm2835-dma 20007000.dma: DMA legacy API manager at (ptrval), dmachans=0x1 [ 0.175908] SCSI subsystem initialized [ 0.176238] usbcore: registered new interface driver usbfs [ 0.176386] usbcore: registered new interface driver hub [ 0.176665] usbcore: registered new device driver usb [ 0.179041] clocksource: Switched to clocksource timer [ 0.289321] VFS: Disk quotas dquot_6.6.0 [ 0.289508] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) [ 0.289878] FS-Cache: Loaded [ 0.290270] CacheFiles: Loaded [ 0.309826] NET: Registered protocol family 2 [ 0.311202] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes) [ 0.311328] TCP established hash table entries: 4096 (order: 2, 16384 bytes) [ 0.313407] RPC: Registered named UNIX socket transport module. [ 0.313470] RPC: Registered udp transport module. [ 0.313500] RPC: Registered tcp transport module. [ 0.313527] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 0.315692] hw perfevents: no irqs for PMU, sampling events not supported [ 0.315820] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available [ 0.320462] Initialise system trusted keyrings [ 0.320920] workingset: timestamp_bits=14 max_order=17 bucket_order=3 [ 0.337401] FS-Cache: Netfs 'nfs' registered for caching [ 0.338844] NFS: Registering the id_resolver key type [ 0.338946] Key type id_resolver registered [ 0.338981] Key type id_legacy registered [ 0.339141] nfs4filelayout_init: NFSv4 File Layout Driver Registering... [ 0.344930] Key type asymmetric registered [ 0.345001] Asymmetric key parser 'x509' registered [ 0.345138] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 250) [ 0.345662] io scheduler noop registered [ 0.345719] io scheduler deadline registered (default) [ 0.346375] io scheduler cfq registered [ 0.346429] io scheduler mq-deadline registered (default) [ 0.346464] io scheduler kyber registered ... ... ...略 ... ... [ OK ] Reached target Sockets. [ OK ] Reached target Basic System. Starting Avahi mDNS/DNS-SD Stack... Starting dhcpcd on all interfaces... Starting System Logging Service... Starting Deferred execution scheduler... Starting Generate Pirehose certificate if missing... Starting LSB: Switch to ond…unless shift key is pressed)... Starting triggerhappy global hotkey daemon... [ OK ] Started D-Bus System Message Bus. Starting Check for Raspberry Pi EEPROM updates... Starting Login Service... [ OK ] Started Regular background program processing daemon. Starting WPA supplicant... [ OK ] Started Manage Sound Card State (restore and store). Starting Save/Restore Sound Card State... [ OK ] Reached target System Time Synchronized. [ OK ] Started Daily apt download activities. [ OK ] Started Daily rotation of log files. [ OK ] Started Daily apt upgrade and clean activities. [ OK ] Started Daily man-db regeneration. [ OK ] Reached target Timers. [ OK ] Started System Logging Service. [ OK ] Started Deferred execution scheduler. [ OK ] Started Check for Raspberry Pi EEPROM updates. [ OK ] Started Save/Restore Sound Card State. [ OK ] Started dhcpcd on all interfaces. [ OK ] Started triggerhappy global hotkey daemon. [ OK ] Listening on Load/Save RF K…witch Status /dev/rfkill Watch. [ OK ] Reached target Sound Card. [ OK ] Started Login Service. [ OK ] Started Avahi mDNS/DNS-SD Stack. [ OK ] Started WPA supplicant. [ OK ] Started LSB: Switch to onde… (unless shift key is pressed). [ OK ] Reached target Network. [ OK ] Reached target Network is Online. Starting LSB: exim Mail Transport Agent... Starting Lighttpd Daemon... Starting Flightradar24 Decoder & Feeder... Starting OpenBSD Secure Shell server... Starting /etc/rc.local Compatibility... Starting Permit User Sessions... [ OK ] Started dump1090 ADS-B rece…er (FlightAware customization). [ OK ] Started vnStat network traffic monitor. [ OK ] Started dump978 ADS-B UAT receiver. [ OK ] Started skyaware978 ADS-B UAT web display. [ OK ] Started /etc/rc.local Compatibility. [ OK ] Started Permit User Sessions. Starting Hold until boot process finishes up... Starting Terminate Plymouth Boot Screen... Raspbian GNU/Linux 10 pi1 ttyAMA0 pi1 login: |
ESP-01SをRaspberry Piの小判鮫として搭載する手法は、昔、ESP Easyに類似したesp-linkというバイナリで、Raspberry PiのRUNピンを開閉してハード的に再起動させる際と同じでした。あの時は、RUNピンとESP-01SのGPIOを直接繋いだりと無茶したので、結局不安定な結果に。あの頃と違い今、私の手にはESP EasyとMOSFETがあることから、もう一度この命題にチャレンジしたいと思っています。
参考と鳴謝Great Tnx!!)