[英]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.