2015-07-13 136 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