2017-02-24 62 views
0

我已經創建了AWS物聯網一個東西叫做RasberryPi,我試圖用下面的代碼它的身影登記註冊:AWS IOT:不能與影子

var awsIot = require('aws-iot-device-sdk'); 

var thingShadows = awsIot.thingShadow({ 
    keyPath: "./certs/private.pem.key", 
    certPath: "./certs/certificate.pem.crt", 
    caPath: "./certs/root-CA.crt", 
    clientId: "RasberryPi1", 
    region: "eu-west-1", 
    port: "8883", 
    debug: true 
}); 

thingShadows.on('connect', function() { 

    console.log('connected'); 

    thingShadows.register('RasberryPi1', function() { 
     console.log('registered'); 
... 

我連接成功,但我從來沒有註冊。也就是說,第二個console.log語句永遠不會運行。任何人都可以爲我的錯誤提供建議嗎?我對AWS IoT非常陌生,我的錯誤可能很基本。

非常感謝

回答

0

這可能是真正的混亂,但正是因爲文檔的。你可能下面的例子喜歡這裏:https://github.com/aws/aws-iot-device-sdk-js#thing-shadow-class

// 
// After connecting to the AWS IoT platform, register interest in the 
// Thing Shadow named 'RGBLedLamp'. 
// 
thingShadows.register('RGBLedLamp', function() { 
    // Your code here 
} 

但是當你讀到這裏的文檔:https://github.com/aws/aws-iot-device-sdk-js#awsiotthingshadowregisterthingname-options-callback-,你可以看到寄存器功能需要的回調並不像第二個參數,但作爲第三

(!)只是這樣稱呼它:

thingShadows.register('RGBLedLamp', {}, function() { 
    // Your code here 
} 

,它會工作像一個魅力