デバイスのツインプロパティが変更されたときに、クラウドのバックエンドで通知を受け取ろうとしています。これを行うには、以下の画像リンクに示すようにルートを設定しています
私はAzure関数を作成しました。組み込みのエンドポイントイベントのデフォルトのコンシューマグループをトリガします。しかし、デバイスのツインドキュメントを自分のデバイスの1つにアップデートすると、紺色の機能は起動しません。また、iothubexplorerやDevice Explorerを使ってデバイスのイベントを監視すると、「updateTwin」イベントはまったく表示されません。しかし、デバイスからクラウドへ定期的にデバイスを送信すると機能します。
次のコードを使用してデバイスのツインを更新する
"use strict";
var Client = require("azure-iot-device").Client;
var Protocol = require("azure-iot-device-mqtt").Mqtt;
var connectionString = "";
var client = Client.fromConnectionString(connectionString, Protocol);
client.open(function(err) {
if (err) {
console.error("could not open IotHub client");
} else {
console.log("client opened");
client.getTwin(function(err, twin) {
if (err) {
console.error("could not get twin");
} else {
var body = {
temperature: "40"
}
console.log(twin.properties.reported);
twin.properties.reported.update(body, function(err) {
if (err) {
console.error("could not update twin");
} else {
console.log("twin state reported");
process.exit();
}
});
}
});
}
});
Iveはまた、次のコマンドを使ってiothub-explorerを使って試してみました: iothub-explorer update-twin InitialDevice {"プロパティ":{"希望": {"interval":9000}}} --login ""
回答:
回答№1は0あなたの投稿のコードでテストしたところ、それはうまくいきました。あなたのルート設定とコードは正しいです。
あなたはこれを参照しましたか? トピック?私は問題がそれと似ていると思います。アカウントの場所を確認し、ローマン・キッスの提案でテストしてみてください。