Warm tip: This article is reproduced from serverfault.com, please click

get messages from backend service app from device twins in microsoft azure

发布于 2020-11-28 11:58:50

My goal is to update my service side app (in Node.js) when my azure device twin is updated or when I call the function. But I cant figure out how to do it. Is there a way to accomplish this with only the shared access primary key (in other words without the device key).

From my research I have found that this might work (but not sure)

Twin.get (){
}

The problem I have is I don't know how to complete this code. In this link I have given a screen shot of the function and its description. screenshot

Can anyone of you suggest a suitable code which might work(Doesn't have to be the one I mentioned)

Thanks in advance

Questioner
Senuda Jayalath
Viewed
0
Stefan Wick MSFT 2020-11-29 00:11:18

Here is a sample how to do this:
https://github.com/Azure/azure-iot-sdk-node/blob/master/service/samples/javascript/twin.js

The relevant code is this:

var Registry = require('azure-iothub').Registry;
var registry = Registry.fromConnectionString(IOTHUB_CONNECTION_STRING);
registry.getTwin(deviceId, function(err, twin) {
  if (err) {
    console.error(err.message);
  } else {
    console.log(JSON.stringify(twin, null, 2));
}