このプログラムを動かすにはMQTTブローカーと、コントローラとなるアプリが必要です。 また、本プログラムはGo言語で動かしますので、Go言語がインストールされていることを確認して下さい。
- Raspberry Pi
- 学習リモコンモジュール : ADRSIR
※学習リモコンの対応Raspberry PiにRaspberry Pi Model B+/Raspberry Pi 2 Model B/Raspberry Pi 3 Model B
とありますが、Raspberry Pi 4でも可能です。
まずはプログラムをダウンロード。
$ go get github.com/Yosh0124/home-remocon-raspberrypi
ますはsample.env
のファイル名を.env
に変更し、ファイルの中身をご自身で立てたMQTT Brokerの設定に合わせて修正して下さい。
例えば、
MQTT_USER=username
MQTT_PASSWD=password
MQTT_HOST="wss://mqtt.example.com:8083"
のような具合です。
次に、ビルドします。
$ cd $GOPATH/src/github.com/Yosh0124/home-remocon-raspberrypi
$ go build
$ go run
できちんと動作すれば成功です。
以下のようにSystemdで自動起動するようにします。
$ sudo nano /etc/systemd/system/home-remocon.service
そして、ファイルを以下のように設定します。
[Unit]
Description= launch home remote controller
After=syslog.target network.target
[Service]
WorkingDirectory=/home/pi/dev/src/github.com/Yosh0124/home-remocon-raspberrypi
ExecStart=/home/pi/dev/src/github.com/Yosh0124/home-remocon-raspberrypi/home-remocon-raspberrypi
Restart = always
Type = simple
User=pi
[Install]
WantedBy = multi-user.target
そして、サービスを起動します。
$ sudo systemctl start home-remocon.service
以下のコマンドで正常に起動していることを確認します。
$ sudo systemctl status home-remocon.service
問題なく動いてたら自動起動するように有効化します。
$ sudo systemctl enable home-remocon.service
以上です。