3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sonoff BasicにESPURNAを焼いてローカル上のAlexaでリレーを動かす

Last updated at Posted at 2020-03-14

そこらへんに転がっているSonoff Basicを、さくっとクラウド連携のいらない便利なWi-Fiリレーに変えたので簡単に備忘録を残す

とりあえず中華謹製アプリをやめよう

中華Wi-FiリレーのSonoffは通常「eWeLink」というアプリを使って設定制御ができるが、当然中華アプリなので中国クラウドに接続するわけで、いろんな意味でよろしくない。

そもそも技適通っているか怪しいよくわからないものを使うなって話だが

Sonoff Basicは実はESP8266が載っているので、ファームを書き換えれば得体の知れないものを使わずに済む。

ESPURNA

ESP8266にはESPURNA以外にもESPEasyやTasmotaといったファームウェアが存在するが、
今回使用するESPURNAはAlexa・MQTTプロトコルに対応できるので、Alexaを使う前提なら条件合致している。

準備

  • Sonoff Basic
  • UART接続するもの(USB-UARTとか)
  • はんだ・はんだゴテ
  • ピンソケットかピンヘッダ
  • UART接続に使えるワイヤ
  • 最低でもWindows/Linux環境

今回はWindows環境で焼く。ツール自体Linuxでも動くのでやり方はさほど変わらないかも。
当然のことだが、Sonoffへは100Vを渡せるように準備すること

ピンソケットの取り付け

RaspberryPiでもおなじみのGPIOにソケットを取り付ける。
基板の真ん中に、表面からみて4つの穴があると思うので、4ピン分付ける。
繋げれればいいので、使いたいワイヤがメスなら別にピンヘッダでもいい。

Sonoffへワイヤの接続

ボタン側から順に
3V TX RX GNDとなっているので、TX・RXを挿し間違えないこと
例としてこんな感じにつなぐ。まだこの時点で通電・USB接続しないこと
image.png

esptoolとESPURNAを用意

UARTでファームを送るため、ESPtoolバイナリが入ったESPEasyのzipを落としておく。
解凍するとesptool.exeが入っている。

ESPURNAはGitHubに投げ込まれているので、最新のファームを見つけてダウンロードしておく。
現時点で1.14.1の場合、ファイル名はespurna-1.14.1-itead-sonoff-basic.bin

ファームウェア書き換え

いよいよファームウェア書き換えの準備ができたので、PSかコマンドプロンプトを開く。
esptoolとESPURNAが置かれている作業フォルダをカレントディレクトリにしておくこと。

はじめにUARTモジュールを接続し、COMポートをデバイスマネージャで確認して把握しておく。
いったんUSBを外す。

ファームウェア書き換えモードに入る
Sonoff上のボタンを押しながら100V通電させるとファーム書き換えモードで起動する。

esptoolの実行
UARTモジュールを接続する。
把握したCOMポート番号(COM*)を忘れずに入れておくこと

esptool.exe -vv -cd nodemcu -cb 115200 -cp COM* -ca 0x00000 -cf espurna-1.14.1-itead-sonoff-basic.bin

うまくいけば以下の経過で書き換えが終了する。

esptool v0.4.6 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
        setting board to nodemcu
        setting baudrate from 115200 to 115200
        setting port from COM1 to COM*
        setting address from 0x00000000 to 0x00000000
        espcomm_upload_file
        stat espurna-1.14.1-itead-sonoff-basic.bin success
        setting serial port timeouts to 1000 ms
opening bootloader
resetting board
trying to connect
        flush start
        setting serial port timeouts to 1 ms
        setting serial port timeouts to 1000 ms
        flush complete
        espcomm_send_command: sending command header
        espcomm_send_command: sending command payload
        read 0, requested 1
trying to connect
        flush start
        setting serial port timeouts to 1 ms
        setting serial port timeouts to 1000 ms
        flush complete
        espcomm_send_command: sending command header
        espcomm_send_command: sending command payload
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_send_command: receiving 2 bytes of data
        espcomm_open
Uploading 463552 bytes from espurna-1.14.1-itead-sonoff-basic.bin to flash at 0x00000000
        erasing flash
        size: 0712c0 address: 000000
        first_sector_index: 0
        total_sector_count: 114
        head_sector_count: 16
        adjusted_sector_count: 98
        adjusted_size: 062000
        espcomm_send_command: sending command header
        espcomm_send_command: sending command payload
        setting serial port timeouts to 10000 ms
        setting serial port timeouts to 1000 ms
        espcomm_send_command: receiving 2 bytes of data
        writing flash
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................
starting app without reboot
        espcomm_send_command: sending command header
        espcomm_send_command: sending command payload
        espcomm_send_command: receiving 2 bytes of data
closing bootloader
        flush start
        setting serial port timeouts to 1 ms
        setting serial port timeouts to 1000 ms
        flush complete

書き換え中はアクセスランプが確認できれば問題ない。
image.png

ESPURNAの設定

書き換えが終了したら、「ESPURNA-******」というSSIDが飛んでるはずなので、「finabocci」で入る。(これがなかなか接続しづらかった)
192.168.4.*というセグメントでIPアドレスがとれているので、192.168.4.1にアクセスする。
「admin」「finabocci」でログインするとセキュリティ設定画面に入れる。
image.png

任意のパスワードを設定し、Saveする。この際切断される(っぽい)ので、再び飛んでる「ESPURNA-******」に、任意で設定したパスワードを使って接続する。
192.168.4.1に、「admin」で設置したパスワードでログインすると、今度はESPURNAの管理画面に入れる。

Wi-Fiに接続
Alexaデバイスが接続されているネットワークと同じAPに接続する。
image.png
SSID等自分でわかる範囲で適当に設定し、Save・OKすると無事に接続される。
IPアドレスの設定をしていなければ、DHCPで取得してくれるので問題ない(今後管理画面にアクセスするときが面倒なので、指定しておいたほうが楽)

(eWeLinkではできなかった静的IPも設定できるのはうれしい)

もしパスフレーズ誤字等で間違ったAP設定をしてしまっても、ESPURNAは構成用にAPを飛ばしなおしてくれるので心配はない

Alexaに接続する

Alexaアプリ→「デバイス」タブ→「すべてのデバイス」→右上の「+」→「デバイスを追加」→「その他」
またはAmazon Alexaコンパネ(https://alexa.amazon.co.jp/spa/index.html) →「デバイス」→「検出」

成功するとなぜか「Hue Hub(Royal Philips Electronicsデバイス)」として認識される。

あとがき

ちゃんと使える。しかもeWeLink使用時よりすごくレスポンスが良い。(LAN内なので当然)

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?