Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js AWS IoT NodeJS SDK无法更新命名阴影_Node.js_Shadow_Aws Iot - Fatal编程技术网

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

Node.js AWS IoT NodeJS SDK无法更新命名阴影,node.js,shadow,aws-iot,Node.js,Shadow,Aws Iot,试图将我的头围绕AWS IoT命名阴影,但我无法订阅或更新命名阴影,只能订阅或更新默认阴影。 在我的物联网控制台中,我有一个经典的阴影和一个名为simShadow1的命名阴影 const awsIoT = require('aws-iot-device-sdk'); const pathToCerts = "./certs"; const thingName = "mySimulatedThing"; const shadowName = "s

试图将我的头围绕AWS 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)影响经典阴影,在AWS IoT控制台中查看如何修改所需值,如果我从AWS控制台更改json所需值,我可以查看节点JS事件状态和被调用的增量

但我找不到一种与命名的影子“simShadow1”互动的方法。我已经尝试将事物名称设置为“mySimulatedThing/simShadow1”、“mySimulatedThing/shadow/name/simShadow1”和许多其他组合。我也尝试过thinkShadow.register(“使用thingName”…),然后在更新和订阅thinkShadow.update(thingName+“/”+shadowName,{…})和thinkShadow.subscribe(thingName+“/”+shadowName,…)时添加命名的shadow


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

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

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

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

我也有类似的情况——我能够使用GG(v1)和物联网云中的东西进行更新。但无法影响使用本地影子服务的设备上的状态更改-即当我将本地影子服务作为主题的订户而不是对象时。我仍在试图找出原因……

以及thingShadow.register和update函数如何-您是否必须指定整个主题路径?