2015-07-13 132 views
3

我正在嘗試使用IBM Bluemix平臺構建物聯網小應用程序。我發現了一個Ryan J Baxter的視頻,將傳感器標籤連接到物聯網雲基礎上,並帶有Beagle-bone骨架。現在,我正在嘗試使用Raspberry Pi設備而不是Beagle-Bone執行相同的過程,在sensor-tag.js文件面臨一些問題時,我們無法從config.properties文件中獲取像cfg type,cfg org,cfg id這樣的cfg參數值。物聯網Raspberry Pi傳感器標籤

我得到了我在註冊設備時給予的mac地址,我給了我的Raspberry Pi mac地址,因爲它連接到我的以太網eth0

if(cfg.id != deviceId) { 
     console.warn('The device MAC address does not match the ID in the configuration file.'); 
    } 
    //------------- This is where I'm facing a problem -------- 

    var clientId = ['d', cfg.org, cfg.type, cfg.id].join(':'); 

    var client = mqtt.connect("mqtts://" + cfg.org + 
     '.messaging.internetofthings.ibmcloud.com:8883', 
     { 
     "clientId" : clientId, 
     "keepalive" : 30, 
     "username" : "use-token-auth", 
     "password" : cfg['auth-token'] 
     }); 
    client.on('connect', function() { 
     console.log('MQTT client connected to IBM IoT Cloud.'); 
    }); 
    client.on('error', function(err) { 
     console.log('client error' + err); 
     process.exit(1); 
    }); 
    client.on('close', function() { 
     console.log('client closed'); 
     process.exit(1); 
    }); 
    monitorSensorTag(client); 
    }); 
}); 

function monitorSensorTag(client) { 
    console.log('Make sure the Sensor Tag is on!'); 
+0

請確保您的代碼中的括號相符。 – Ram

回答

2

如果使用的是樹莓派,看看幾招樹莓派https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/

還爲在GitHub上樹莓派這可能是有用的源代碼:https://github.com/ibm-messaging/iot-raspberrypi/

使用配方,您將設備信息存儲在device.cfg文件中,並在連接時由IoT服務使用。 /etc/iotsample-raspberrypi/device.cfg

編輯添加:查看日誌,我看到您註冊了與您使用的ID不同的Raspberry Pi設備。請使用我通過電子郵件發送給您的正確ID註冊設備。

+0

是的。它已經完成,但我希望我的傳感器標籤可以使用Raspberry Pi連接到IoT Cloud。如果我必須這樣做,我必須在註冊模式下連接我的覆盆子pi是嗎? –

+0

您是否註冊了物聯網基金會的覆盆子pi?它預計mac地址是小寫的,沒有冒號。 – ValerieLampkin

+0

如果你讓我知道你的組織,我會檢查IoT日誌,看看我能否找到你的連接錯誤。 – ValerieLampkin