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?

More than 3 years have passed since last update.

MQTT(mosquitto)の動作確認

Posted at

概要

MQTT(Message Queueing Telemetry Transport)のOSSであるmosquittoについて簡単に動作確認する。

MQTTの詳細概要はhttps://kfep.jp/solution/iot-mqtt/mqtt 等を参照。
以下の構成のPublish/Subscribe型モデルの軽量プロトコル(ヘッダが2バイト)。TCP上のプロトコル。1対1、1対多、多対多に対応している。
Facebook Messengerにも採用されているようである。

Publisher→→Broker→→Subscriber

環境

  • osxのmultipass上で動作するUbuntu20.04
  • mosquitto_sub version 2.0.14 running on libmosquitto 2.0.14
  • mosquitto_pub version 2.0.14 running on libmosquitto 2.0.14.

動作確認

  • 環境構築
$ sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
$ sudo apt-get update
$ sudo apt install mosquitto
  • バージョン確認
ubuntu@mqtt:~$ systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT Broker
     Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor pre>
     Active: active (running) since Sun 2022-04-03 18:58:24 JST; 36s ago
       Docs: man:mosquitto.conf(5)
             man:mosquitto(8)
   Main PID: 3015 (mosquitto)
      Tasks: 1 (limit: 1132)
     Memory: 1.0M
     CGroup: /system.slice/mosquitto.service
             └─3015 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Apr 03 18:58:24 mqtt systemd[1]: Starting Mosquitto MQTT Broker...
Apr 03 18:58:24 mqtt systemd[1]: Started Mosquitto MQTT Broker.
  • クライアントインストール。
$ sudo apt install mosquitto-clients
  • subscriber起動
$ mosquitto_sub -t 'test/topic' -v
  • publisher起動
$ mosquitto_pub -t 'test/topic' -m 'hello world'
test/topic hello world

パケット確認

Subscriberポート : 48652
Brokerポート:1883
Publisherポート:48654

(1) SubscriberからのBorkerへ登録

No.     Time  Source       Destination  Protocol Length sport  
      1 0.000000 ::1 ::1 TCP      96     48652  48652 → 1883 [SYN] Seq=0 Win=65476 Len=0 MSS=65476 SACK_PERM=1 TSval=2807574009 TSecr=0 WS=128
      2 0.000013 ::1 ::1 TCP      96     1883   1883 → 48652 [SYN, ACK] Seq=0 Ack=1 Win=65464 Len=0 MSS=65476 SACK_PERM=1 TSval=2807574009 TSecr=2807574009 WS=128
      3 0.000024 ::1 ::1 TCP      88     48652  48652 → 1883 [ACK] Seq=1 Ack=1 Win=65536 Len=0 TSval=2807574009 TSecr=2807574009
      4 0.000173 ::1 ::1 MQTT     102    48652  Connect Command
      5 0.000181 ::1 ::1 TCP      88     1883   1883 → 48652 [ACK] Seq=1 Ack=15 Win=65536 Len=0 TSval=2807574009 TSecr=2807574009
      6 0.000229 ::1 ::1 MQTT     92     1883   Connect Ack
      7 0.000243 ::1 ::1 TCP      88     48652  48652 → 1883 [ACK] Seq=15 Ack=5 Win=65536 Len=0 TSval=2807574009 TSecr=2807574009
      8 0.000275 ::1 ::1 MQTT     105    48652  Subscribe Request
      9 0.000277 ::1 ::1 TCP      88     1883   1883 → 48652 [ACK] Seq=5 Ack=32 Win=65536 Len=0 TSval=2807574009 TSecr=2807574009
     10 0.000305 ::1 ::1 MQTT     93     1883   Subscribe Ack
     11 0.000315 ::1 ::1 TCP      88     48652  48652 → 1883 [ACK] Seq=32 Ack=10 Win=65536 Len=0 TSval=2807574009 TSecr=2807574009

(2) PublisherからBorkerへ接続とメッセージ送信。

     12 2.872744 ::1 ::1 TCP      96     48654  48654 → 1883 [SYN] Seq=0 Win=65476 Len=0 MSS=65476 SACK_PERM=1 TSval=2807576881 TSecr=0 WS=128
     13 2.872757 ::1 ::1 TCP      96     1883   1883 → 48654 [SYN, ACK] Seq=0 Ack=1 Win=65464 Len=0 MSS=65476 SACK_PERM=1 TSval=2807576881 TSecr=2807576881 WS=128
     14 2.872769 ::1 ::1 TCP      88     48654  48654 → 1883 [ACK] Seq=1 Ack=1 Win=65536 Len=0 TSval=2807576881 TSecr=2807576881
     15 2.873002 ::1 ::1 MQTT     102    48654  Connect Command
     16 2.873013 ::1 ::1 TCP      88     1883   1883 → 48654 [ACK] Seq=1 Ack=15 Win=65536 Len=0 TSval=2807576882 TSecr=2807576882
     17 2.873405 ::1 ::1 MQTT     92     1883   Connect Ack
     18 2.873411 ::1 ::1 TCP      88     48654  48654 → 1883 [ACK] Seq=15 Ack=5 Win=65536 Len=0 TSval=2807576882 TSecr=2807576882
     19 2.873470 ::1 ::1 MQTT     113    48654  Publish Message
     20 2.873473 ::1 ::1 TCP      88     1883   1883 → 48654 [ACK] Seq=5 Ack=40 Win=65536 Len=0 TSval=2807576882 TSecr=2807576882

(3) BorkerからSubscriberへメッセージ送信。

     21 2.873503 ::1 ::1 MQTT     113    1883   Publish Message
     22 2.873510 ::1 ::1 TCP      88     48652  48652 → 1883 [ACK] Seq=32 Ack=35 Win=65536 Len=0 TSval=2807576882 TSecr=2807576882

(4) Publisher、SubscriberがBrokerと切断。

     23 2.874045 ::1 ::1 MQTT     90     48654  Disconnect Req
     24 2.874050 ::1 ::1 TCP      88     1883   1883 → 48654 [ACK] Seq=5 Ack=42 Win=65536 Len=0 TSval=2807576883 TSecr=2807576883
     25 2.874139 ::1 ::1 TCP      88     1883   1883 → 48654 [FIN, ACK] Seq=5 Ack=42 Win=65536 Len=0 TSval=2807576883 TSecr=2807576883
     26 2.874258 ::1 ::1 TCP      88     48654  48654 → 1883 [FIN, ACK] Seq=42 Ack=6 Win=65536 Len=0 TSval=2807576883 TSecr=2807576883
     27 2.874269 ::1 ::1 TCP      88     1883   1883 → 48654 [ACK] Seq=6 Ack=43 Win=65536 Len=0 TSval=2807576883 TSecr=2807576883
     28 6.103422 ::1 ::1 MQTT     90     48652  Disconnect Req
     29 6.103442 ::1 ::1 TCP      88     1883   1883 → 48652 [ACK] Seq=35 Ack=34 Win=65536 Len=0 TSval=2807580112 TSecr=2807580112
     30 6.103521 ::1 ::1 TCP      88     1883   1883 → 48652 [FIN, ACK] Seq=35 Ack=34 Win=65536 Len=0 TSval=2807580112 TSecr=2807580112
     31 6.103667 ::1 ::1 TCP      88     48652  48652 → 1883 [FIN, ACK] Seq=34 Ack=36 Win=65536 Len=0 TSval=2807580112 TSecr=2807580112
     32 6.103676 ::1 ::1 TCP      88     1883   1883 → 48652 [ACK] Seq=36 Ack=35 Win=65536 Len=0 TSval=2807580112 TSecr=2807580112

参考

参考にさせていただきました。
https://symfoware.blog.fc2.com/blog-entry-2205.html

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?