MQTTでIoT通信(2)mosquittoの設定
mosquittoの設定する。 /etc/mosquitto/mosquitto.confが設定ファイルで、初期設定では以下のようになっている。 #Place your local configuration in /etc/mosquitto/conf.d/ # # A full description of the configuration file is at # /usr/share/doc/mosquitto/examples/mosquitto.conf #pid_file /run/mosquitto/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ log_dest file /var/log/mosquitto/mosquitto.log include_dir /etc/mosquitto/conf.d 詳細は /etc/mosquitto/conf.d 以下からインクルードするようになっている。特にファイルは置かれていない(READMEだけ)。取りあえず最低限の記述をするために /etc/mosquitto/conf.d/01mosquitto.conf を作成 listener 1883 0.0.0.0 allow_anonymous true 全てのIPからポート1883で受信する パスワード認証とかは無し という設定です。 sudo systemctl restart mosquitto で再起動。 mosquitto_sub -d -t /client/abc を実行。別クライアントから mosquitto_pub -h [ IP address ] -p 1883 -t /client/abc -m "shee546978" で通信できる。 ユーザー認証 以下でユーザー作成1回目だけ -c をつける(ファイル pwfile が作成される) sudo mosquitto_passwd -c /etc/mosquitto/pwfile testuser パスワード入力を2回求められるので適当にいれると ファイル pwfile にハッシュ値?で保存される(違うユーザーで同じパスワードいれても違う値になるね)。...