0
6

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.

AWS IoTで デバイスが切断されたことを知る方法

Last updated at Posted at 2016-01-14

AWS IoTが10月にBetaとして登場した時、MQTTの"Will"の機能はありませんでした。
参考: AWS IoT Message Brokerに一般のMessage Brokerにあるべき実装がない理由を考えてみた。

ところが、今のドキュメントを見ると、Device Shadows Data Flowには以下の記載があります。

If you want to determine if a device is currently connected, include a connected
setting in the thing shadow and use an MQTT Last Will and Testament (LWT) message that
will set the connected setting to false if a device is disconnected due to error.

このような機能は最初無かったと思うのですが、追加されたのでしょうか?
AWSのドキュメントが変更されたことをお知らせしてくれるサービスとかあったらいいのに・・

実際に試してみるのは簡単で、例えば thing-passthrough-example.js なら、以下のようにすれば"Will"メッセージを設定することができます。
https://github.com/aws/aws-iot-device-sdk-js/blob/master/examples/thing-passthrough-example.js

const thingShadows = thingShadow({
  keyPath: args.privateKey,
  certPath: args.clientCert,
  caPath: args.caCert,
  clientId: args.clientId,
  region: args.region,
  reconnectPeriod: args.reconnectPeriod
  will: {
    topic: '$aws/things/thingname/shadow/update',
    payload:  '{ "state" : { "reported" : { "connected" : "false" }}}'
  }
});

上記の例だと、$aws/things/thingname/shadow/update を subscribe していれば、デバイスが切断した時にWillが送信されて来ます。

0
6
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
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?