0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MQTT: localhost でのテスト

Posted at

Arch Linux でテストしました。

サーバーの構築

インストール

sudo pacman -S mosquitto

バージョンの確認

$ mosquitto -h
mosquitto version 2.0.20

mosquitto is an MQTT v5.0/v3.1.1/v3.1 broker.

サーバーの起動

sudo systemctl start mosquitto

Publish

go_pub_mqtt.sh
BROKER="localhost"
#
echo $BROKER
message="Hello Mqtt "`date`
mosquitto_pub -d -t orz -m "${message}" \
    -h  $BROKER \
    --topic example/testTopic

実行結果

$ ./go_pub_mqtt.sh 
localhost
Client null sending CONNECT
Client null received CONNACK (0)
Client null sending PUBLISH (d0, q0, r0, m1, 'example/testTopic', ... (53 bytes))
Client null sending DISCONNECT

Subscribe

go_sub_mqtt.sh
BROKER="localhost"
#
mosquitto_sub -d -t orz -h $BROKER \
    --topic example/testTopic

実行結果

$ ./go_sub_mqtt.sh 
Client null sending CONNECT
Client null received CONNACK (0)
Client null sending SUBSCRIBE (Mid: 1, Topic: orz, QoS: 0, Options: 0x00)
Client null sending SUBSCRIBE (Mid: 1, Topic: example/testTopic, QoS: 0, Options: 0x00)
Client null received SUBACK
Subscribed (mid: 1): 0, 0
Client null received PUBLISH (d0, q0, r0, m0, 'example/testTopic', ... (53 bytes))
Hello Mqtt 2025年  2月  4日 火曜日 16:05:35 JST
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?