1
var Subscription = require('./Subscription');
var api = require('./api');

exports = module.exports = {};
var bridgeData;

function validateAccount(account) {
  if (!account) throw new Error('Muzzley account details must be present!');
  if (!account.appToken) throw new Error('appToken is not defined!');
  if (!account.profileId) throw new Error('profileId is not defined!');
  if (!account.serialNumber) throw new Error('serialNumber is not defined!');
}

function validateComponents(components) {
  if (!components || components.length === 0) throw new Error('Bridge components must be defined!');

  for (var i = 0; i != components.length; ++i) {
    if(!components[i].id) throw new Error('Missing component id!');
    if (!components[i].type) throw new Error('Missing component type!');
    if (!components[i].label) throw new Error('Missing component label!');
  }
}

exports.connect = function (account, components, callback) {

  validateAccount(account);
  validateComponents(components);

  bridgeData.appToken = account.appToken;
  bridgeData.profileId = account.profileId;

  api.registerBridge(account, function (err, bridge) {
    if (err) return callback(err);

    bridgeData.deviceKey = bridge.deviceKey;

    api.updateBridge(bridge, components, function (err) {
      if (err) return callback(err);

      var subscription = new Subscription(account.profileId, account.appToken);
      subscription.load(function (err) {
        return callback(err, subscription);
      });
    });
  });
};

exports.updateComponents = function (components, callback) {
  api.updateBridge(bridgeData, components, function (err) {
    return callback(err);
  });
};

There is an error called undefined:

ERROR: /home/root/.node_app_slot/node_modules/muzzley-bridge-node/lib/index.js:29                                                                                     
ERROR:   bridgeData.appToken = account.appToken;                                                                                                                      
ERROR:                       ^                                                                                                                                        
ERROR: TypeError: Cannot set property 'appToken' of undefined
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Hat hout
  • 471
  • 1
  • 9
  • 18
  • 1
    You are not declaring `bridgeData` variable in your code. so it undefined. – Ziki Nov 23 '15 at 04:41
  • @Ziki is right. Also make var bridgeData = {}; – Harpreet Singh Nov 23 '15 at 04:46
  • This should not have been that hard to debug. Place a breakpoint on the line causing the error. Examine the value of `bridgeData`, noting that it is undefined. Then take it from there. –  Nov 23 '15 at 06:53
  • Any news on this item. In this days I have the same problem: my guess is that bridgeData should be defined inside the muzzley-bridge-node lib (see the ERROR file path), is it ?? – SteMMo Jan 11 '17 at 11:31

3 Answers3

1

You are declaring bridgeData wrong in your code.

Just change the following line:

var bridgeData;

To:

var bridgeData = {};

When you do: var bridgeData; your variable is undefined, and you can't assign new property to undefined variable.

Ziki
  • 1,390
  • 1
  • 13
  • 34
  • @Hathout Please post the updated code. Also add `console.log(JSON.stringify(account));` after: `validateComponents(components);` – Ziki Nov 26 '15 at 04:32
0

Are you connecting a board to Muzzley using this library? It has been fixed already. Run:

npm install muzzley-bridge-node

to install the most recent version

Miguel Sousa
  • 210
  • 2
  • 10
  • I did, but nothing changed – Hat hout Nov 26 '15 at 01:00
  • Can you give me a bit more information about what are you trying to accomplish? Are you using Intel XDK IoT Edition with Intel Edison/Galileo? If you are using Intel XDK you'll have to rebuild your app packages with the rebuild and the upload buttons. If you want to install it manualy, the app can be found inside the folder `node_app_slot`. Inside you should find a folder named `node_modules` containing the external dependencies. Look at the `muzzle-bridge-node/package.json` file and check if the version is the most recent (0.0.3) – Miguel Sousa Nov 27 '15 at 11:33
0

I've just written to the author.
He fixed the library -> ver.0.0.4 .
Now 'npm update muzzley-bridge-node' !

SteMMo
  • 392
  • 1
  • 4
  • 23