Search code examples
javascriptibm-cloudiot

IoT Raspberry Pi Sensor Tag


I am trying build a IoT small application, using IBM Bluemix platform. I found a video of Ryan J Baxter's on connecting a Sensor Tag to the IoT Cloud Foundation with a Beagle-bone. Now I'm trying the same procedure with a Raspberry Pi device instead of a Beagle-Bone, facing some issues with the sensor-tag.js file we are not able to get the cfg parameter values like cfg type, cfg org, cfg id from config.properties file.

I got the mac address which I gave when I'm registering the device I gave my Raspberry Pi mac address as it is connected to my Ethernet 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!');

Solution

  • If you are using raspberry pi, take a look at the recipe for raspberry pi https://developer.ibm.com/iotfoundation/recipes/raspberry-pi/

    There is also source code for raspberry pi on GitHub which may be helpful: https://github.com/ibm-messaging/iot-raspberrypi/

    Using the recipe, you store the device info in a device.cfg file and it is used by the IoT service when you connect. /etc/iotsample-raspberrypi/device.cfg

    EDITED TO ADD: Looking at the logs, I see you registered the Raspberry Pi Device with a different ID than what you are using. Please register the device with the correct ID that I emailed to you.