/ / Azure IoTハブデバイスツイン変更通知の問題 - azure、iot、azure-eventhub、azure-iot-hub、azure-iot-sdk

Azure IoTハブデバイスツイン変更通知の問題 - azure、iot、azure-eventhub、azure-iot-hub、azure-iot-sdk

デバイスのツインプロパティが変更されたときに、クラウドのバックエンドで通知を受け取ろうとしています。これを行うには、以下の画像リンクに示すようにルートを設定しています

https://imgur.com/a/uh0mV

私は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

あなたの投稿のコードでテストしたところ、それはうまくいきました。あなたのルート設定とコードは正しいです。 ここに画像の説明を入力 ここに画像の説明を入力

あなたはこれを参照しましたか? トピック?私は問題がそれと似ていると思います。アカウントの場所を確認し、ローマン・キッスの提案でテストしてみてください。