繁体   English   中英

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

[英]AWS IoT NodeJS SDK cannot update named shadows

试图围绕 AWS IoT 命名阴影总结我的想法,但我无法订阅或更新命名阴影,而只能订阅默认阴影。 在我的 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);
});

上面的代码工作正常。 我可以使用事物名称 (mySimulatedThing) 影响 Classic Shadow,在 AWS IoT 控制台中查看所需值的修改方式,如果我从 AWS 控制台更改 json 所需值,我可以看到 NodeJS 事件状态和正在调用的增量。

但是我找不到与命名阴影“simShadow1”进行交互的方法。 我尝试将事物名称设置为“mySimulatedThing/simShadow1”、“mySimulatedThing/shadow/name/simShadow1”和许多其他组合。 我也尝试过 thinkShadow.register("with the thing name"...),然后在更新和订阅这样的 thinkShadow.update(thingName+"/"+ shadowName, {...}) 和 thinkShadow 时添加命名阴影.subscribe(thingName+"/"+ shadowName, ...)。

有没有人有与命名阴影交互的工作示例?

显然我必须将完整路径设置为:

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

我没想到会设置完整路径。 我想知道是否有更优雅的解决方案。

我处于类似的情况 - 我能够使用 GG(v1) 和 IoT Cloud 中的东西进行更新。 但是无法使用本地影子服务影响设备上的状态更改 - 即当我使本地影子服务成为主题而不是事物的订阅者时。 我仍在试图弄清楚为什么.....

暂无
暂无

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

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