このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
mae3xx_tips:setup_mosquitto:start [2014/04/09 17:55] – admin | mae3xx_tips:setup_mosquitto:start [2014/04/09 18:04] (現在) – admin | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Mosquittoの導入 (MQTT) ====== | ||
+ | |||
+ | ===== MQTTとは ===== | ||
+ | |||
+ | ここのページに非常にわかりやすいまとめがあります。\\ | ||
+ | [[http:// | ||
+ | |||
+ | ここでは、[[http:// | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ===== セットアップ ===== | ||
+ | |||
+ | ==== PPAの追加 ==== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | [sudo] password for user1: | ||
+ | |||
+ | More info: https:// | ||
+ | Press [ENTER] to continue or ctrl-c to cancel adding it | ||
+ | |||
+ | gpg: keyring `/ | ||
+ | gpg: keyring `/ | ||
+ | gpg: requesting key 262C4500 from hkp server keyserver.ubuntu.com | ||
+ | gpg: / | ||
+ | gpg: key 262C4500: public key " | ||
+ | gpg: Total number processed: 1 | ||
+ | gpg: | ||
+ | OK | ||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== パッケージリストの更新 ==== | ||
+ | |||
+ | " | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Ign http:// | ||
+ | Ign http:// | ||
+ | Get:1 http:// | ||
+ | Ign http:// | ||
+ | Get:2 http:// | ||
+ | Ign http:// | ||
+ | Hit http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Get:5 http:// | ||
+ | Hit http:// | ||
+ | Get:6 http:// | ||
+ | Get:7 http:// | ||
+ | Ign http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Get:8 http:// | ||
+ | Get:9 http:// | ||
+ | Get:10 http:// | ||
+ | Get:11 http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Get:12 http:// | ||
+ | Get:13 http:// | ||
+ | Get:14 http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Hit http:// | ||
+ | Fetched 734 kB in 12s (61.1 kB/s) | ||
+ | Reading package lists... Done | ||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | Mosquitto関係のパッケージを検索してみます。 | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | libmosquitto0 - MQTT version 3.1 client library | ||
+ | libmosquitto0-dev - MQTT version 3.1 client library, development files | ||
+ | libmosquittopp0 - MQTT version 3.1 client C++ library | ||
+ | libmosquittopp0-dev - MQTT version 3.1 client C++ library, development files | ||
+ | mosquitto - MQTT version 3.1 compatible message broker | ||
+ | mosquitto-clients - Mosquitto command line MQTT clients | ||
+ | python-mosquitto - MQTT version 3.1 Python client library | ||
+ | python3-mosquitto - MQTT version 3.1 Python 3 client library | ||
+ | libmosquitto-dev - MQTT version 3.1 client library, development files | ||
+ | libmosquittopp-dev - MQTT version 3.1 client C++ library, development files | ||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | クライアント(ライブラリ/ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== クライアントの導入 ==== | ||
+ | |||
+ | mosquitto-clients を導入します。 | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | libmosquitto0 | ||
+ | The following NEW packages will be installed: | ||
+ | libmosquitto0 mosquitto-clients | ||
+ | 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 30.6 kB of archives. | ||
+ | After this operation, 147 kB of additional disk space will be used. | ||
+ | Do you want to continue [Y/ | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Fetched 30.6 kB in 1s (25.6 kB/s) | ||
+ | Selecting previously unselected package libmosquitto0. | ||
+ | (Reading database ... 18538 files and directories currently installed.) | ||
+ | Unpacking libmosquitto0 (from .../ | ||
+ | Selecting previously unselected package mosquitto-clients. | ||
+ | Unpacking mosquitto-clients (from .../ | ||
+ | Setting up libmosquitto0 (0.15-2ubuntu1) ... | ||
+ | Setting up mosquitto-clients (0.15-2ubuntu1) ... | ||
+ | Processing triggers for libc-bin ... | ||
+ | localepurge: | ||
+ | localepurge: | ||
+ | |||
+ | Total disk space freed by localepurge: | ||
+ | |||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | 導入されたアプリケーションのファイルを確認してみます。 | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | /. | ||
+ | /usr | ||
+ | /usr/bin | ||
+ | / | ||
+ | / | ||
+ | /usr/share | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ==== サーバーブローカーの導入 ==== | ||
+ | |||
+ | サーバーブローカーを導入します。 | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | apparmor libapparmor-perl libapparmor1 | ||
+ | Suggested packages: | ||
+ | apparmor-profiles apparmor-docs apparmor-utils | ||
+ | The following NEW packages will be installed: | ||
+ | apparmor libapparmor-perl libapparmor1 mosquitto | ||
+ | 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. | ||
+ | Need to get 438 kB of archives. | ||
+ | After this operation, 1269 kB of additional disk space will be used. | ||
+ | Do you want to continue [Y/ | ||
+ | Get:1 http:// | ||
+ | Get:2 http:// | ||
+ | Get:3 http:// | ||
+ | Get:4 http:// | ||
+ | Fetched 438 kB in 3s (122 kB/s) | ||
+ | Preconfiguring packages ... | ||
+ | Selecting previously unselected package libapparmor1. | ||
+ | (Reading database ... 18549 files and directories currently installed.) | ||
+ | Unpacking libapparmor1 (from .../ | ||
+ | Selecting previously unselected package libapparmor-perl. | ||
+ | Unpacking libapparmor-perl (from .../ | ||
+ | Selecting previously unselected package apparmor. | ||
+ | Unpacking apparmor (from .../ | ||
+ | Selecting previously unselected package mosquitto. | ||
+ | Unpacking mosquitto (from .../ | ||
+ | Processing triggers for ureadahead ... | ||
+ | Setting up libapparmor1 (2.8.0-0ubuntu31.1) ... | ||
+ | Setting up libapparmor-perl (2.8.0-0ubuntu31.1) ... | ||
+ | Setting up apparmor (2.8.0-0ubuntu31.1) ... | ||
+ | Processing triggers for ureadahead ... | ||
+ | Setting up mosquitto (0.15-2ubuntu1) ... | ||
+ | mosquitto start/ | ||
+ | Processing triggers for libc-bin ... | ||
+ | Processing triggers for ureadahead ... | ||
+ | localepurge: | ||
+ | localepurge: | ||
+ | |||
+ | Total disk space freed by localepurge: | ||
+ | |||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | サーバーブローカーを導入すると、自動でサービスとして起動します。 | ||
+ | |||
+ | < | ||
+ | 1774 ? Ss 0:00 / | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ===== 実行例 ===== | ||
+ | |||
+ | 早速、導入したホスト上で、PUB/ | ||
+ | |||
+ | ターミナルで、Subscribe するクライアントを立ち上げておきます。\\ | ||
+ | トピックは " | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Received CONNACK | ||
+ | Received SUBACK | ||
+ | Subscribed (mid: 1): 0 | ||
+ | |||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | |||
+ | 別のターミナルから、Subscribeされているトピック " | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Received CONNACK | ||
+ | Sending PUBLISH (d0, q0, r0, m1, ' | ||
+ | user1@plum: | ||
+ | </ | ||
+ | |||
+ | Subscribe している側にメッセージが送信されたのが確認できます。 | ||
+ | |||
+ | < | ||
+ | user1@plum: | ||
+ | Received CONNACK | ||
+ | Received SUBACK | ||
+ | Subscribed (mid: 1): 0 | ||
+ | Received PUBLISH (d0, q0, r0, m0, ' | ||
+ | Hello World | ||
+ | |||
+ | </ | ||