LoginSignup
34
31

More than 1 year has passed since last update.

Raspberry Pi で mosquitto を使う

Last updated at Posted at 2017-12-04

ラズベリーパイへの mosquitto のインストール

サーバー (Broker) のインストール

sudo apt install mosquitto

サーバーの起動は

sudo systemctl start mosquitto

mosquitto_dec0401.png

クライアントのインストール

sudo apt install mosquitto-clients

サーバーの起動後
リスナー(Subscribe)を動かす

mosquitto_sub -d -t orz

Publish を動かす

mosquitto_pub -d -t orz -m "こんにちは Dec/04/2017"

mosquitto_dec0402.png

Subscribe の画面にメッセージが現れます

mosquitto_dec0403.png

ネットワーク越しにテストする為に、
Arch Linux に mosquitto をインストールして、Broker を動かします。
Arch Linux では、サーバーとクライアントが同時にインストールされます。

sudo pacman -S mosquitto

ラズベリーパイから、ホスト名、host_aa のプローカーにメッセージを送るには (Publish)

mosquitto_pub -d -t orz -m "こんにちは Dec/04/2017" -h host_aa

ラズベリーパイから、ホスト名、host_aa のプローカーから、メッセージを受け取るには (Subscribe)

mosquitto_sub -d -t orz

トピックを指定しての Publish

mosquitto_pub -d -t orz -m "こんにちは Feb/09/2018" -h host_aa --topic topic_1

トピックを指定しての Subscribe

mosquitto_sub -d -t orz --topic topic_1
mosquitto_sub -d -t orz -h host_aa --topic "ttt/test"

次のバージョンで動作を確認しました。

$ uname -a
Linux violet 5.10.52-v7l+ #1441 SMP Tue Aug 3 18:11:56 BST 2021 armv7l GNU/Linux

$ mosquitto -h
mosquitto version 1.5.7

mosquitto is an MQTT v3.1.1 broker.
34
31
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
34
31