Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

4
2

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 5 years have passed since last update.

PubNubのMQTTサポートをmosquittoで使ってみる

Posted at

PubNubとは

Publish/Subscribeなメッセージブローカーをフルマネージドで提供するサービスです
単純にメッセージを仲介するだけでなく Function と呼ばれる機能でデータに介在することも可能な仕組みもあります

詳しいことは TitaniumとPubNubでリアルタイムサービス - Qiitaアプリにリアルタイムメッセージング機能を簡単に導入できるPubNubが$4.5Mを調達 を見てください

MQTT サポート

PubNubは2014年の段階でMQTT をサポートしていたようですが、2018年1月にIoTなユースケースで使えるように改善されています

それに伴いMQTTブローカーのエンドポイントも mqtt.pndsn.com に変更されてます
(昔は mqtt.pubnub.com だったようです → このアドレスは既に無効ですのでご注意を)

mosquitto(MQTT)での確認方法

あらかじめアカウントを作ってから Keyset を作ってください
サンプル的にはこんな感じです

pubnub.png

あとはこんな感じでコマンドラインを組み立てます

Subscribe;

$ mosquitto_sub -h mqtt.pndsn.com \
-t 'YOUR_PUBLISH_KEY/YOUR_SUBSCRIBE_KEY/my_topic/foo/bar' \
-i 'YOUR_PUBLISH_KEY/YOUR_SUBSCRIBE_KEY/anyID-sub1'

Publish;

$ mosquitto_pub -h mqtt.pndsn.com \
-t 'YOUR_PUBLISH_KEY/YOUR_SUBSCRIBE_KEY/my_topic/foo/bar' \
-i 'YOUR_PUBLISH_KEY/YOUR_SUBSCRIBE_KEY/anyID-pub1' \
-m '{"i":1}'
  • YOUR_PUBLISH_KEY: Keyset の中の PUBLIC KEY
  • YOUR_SUBSCRIBE_KEY: Keyset の中の SUBSCRIBE KEY
  • anyID-pub1 は適当に設定してください

ちょっと困ってること

MQTTなsubscribeクライアントがusageにカウントされない希ガス

EoT

4
2
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?