简体   繁体   English

AWS IoT NodeJS SDK 无法更新命名阴影

[英]AWS IoT NodeJS SDK cannot update named shadows

Trying to wrap-up my head around AWS IoT named shadows but I cannot subscribe or update to named shadows but only default shadow.试图围绕 AWS IoT 命名阴影总结我的想法,但我无法订阅或更新命名阴影,而只能订阅默认阴影。 In my IoT Console I have the Classic Shadow and an named shadow called simShadow1在我的 IoT 控制台中,我有经典阴影和一个名为 simShadow1 的命名阴影

const awsIoT = require('aws-iot-device-sdk');
const pathToCerts = "./certs";

const thingName = "mySimulatedThing";
const shadowName = "simShadow1";

const options = {
  keyPath:`${pathToCerts }/xxxx-private.pem.key`,
  certPath:`${pathToCerts }/xxxx-certificate.pem.crt`,
  caPath:`${pathToCerts }/rootCa.pem`,
  clientId:"xxxx",
  host:"xxxx-ats.iot.eu-west-1.amazonaws.com", 
  debug:true
};

let clientTokenUpdate;

const thinkShadow = awsIoT.thingShadow(options);
thinkShadow.on("connect", ()=>{
  console.info("connected to shadow");

  thinkShadow.register( thingName, {}, ()=>{
    console.debug(`registered to ${thingName} thing`);
    console.warn(`about to perform an update on ${thingName}`);

    clientTokenUpdate = thinkShadow.update( thingName, {
      state:{
        desired:{
          welcome:"Hello new value",
          ts:Date.now()
        }
      }
    });

    thinkShadow.subscribe(thingName, {}, (error, result)=>{
      console.info("simShadow1 subscription callback", error, result);
    });

    if(clientTokenUpdate === null){
      console.warn('update shadow failed, operation still in progress');
    }
  });

});

thinkShadow.on('status', (thingName, stat, clientToken, stateObject)=>{
  console.debug("on status", thingName, stat, clientToken, stateObject);
});

thinkShadow.on('delta', (thingName, stateObject)=>{
  console.debug("on delta", thingName, stateObject);
});

thinkShadow.on('timeout', (thingName, clientToken)=>{
  console.debug("on timeout", thingName, clientToken);
});

The above code works fine.上面的代码工作正常。 I can affect the Classic Shadow using the thing name (mySimulatedThing), see in the AWS IoT Console how the desired values are modified and if I change the json desired value from the AWS Console I can see the NodeJS events status and delta being called.我可以使用事物名称 (mySimulatedThing) 影响 Classic Shadow,在 AWS IoT 控制台中查看所需值的修改方式,如果我从 AWS 控制台更改 json 所需值,我可以看到 NodeJS 事件状态和正在调用的增量。

But I cannot find a way to interact with the named shadow "simShadow1".但是我找不到与命名阴影“simShadow1”进行交互的方法。 I have tried to set the thing name to "mySimulatedThing/simShadow1", "mySimulatedThing/shadow/name/simShadow1" and many other combinations.我尝试将事物名称设置为“mySimulatedThing/simShadow1”、“mySimulatedThing/shadow/name/simShadow1”和许多其他组合。 I also have tried to thinkShadow.register("with the thing name"...), and then add the named shadow when updating and subscribing such thinkShadow.update(thingName+"/"+ shadowName, {...}) and thinkShadow.subscribe(thingName+"/"+ shadowName, ...).我也尝试过 thinkShadow.register("with the thing name"...),然后在更新和订阅这样的 thinkShadow.update(thingName+"/"+ shadowName, {...}) 和 thinkShadow 时添加命名阴影.subscribe(thingName+"/"+ shadowName, ...)。

Does anyone have a working example for interacting with named shadows ?有没有人有与命名阴影交互的工作示例?

Apparently I have to set the full path as:显然我必须将完整路径设置为:

     device.subscribe(`$aws/things/${thingName}/shadow/name/${shadowName}/update/accepted`, (error, result)=>{
         console.info(">>", error, result);
     });

I wouldn't have expected to set the full path.我没想到会设置完整路径。 I wonder if there are more more elegant solutions.我想知道是否有更优雅的解决方案。

I am in a similar situation - I am able to update using thing in GG(v1) and IoT Cloud.我处于类似的情况 - 我能够使用 GG(v1) 和 IoT Cloud 中的东西进行更新。 But unable to affect state change on the device using local shadow service - ie when i make the local shadow service the subscriber of the topic instead of the thing.但是无法使用本地影子服务影响设备上的状态更改 - 即当我使本地影子服务成为主题而不是事物的订阅者时。 I am still trying to figure out why .....我仍在试图弄清楚为什么.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM