octoblu / meshblu

Meshblu is a cross-protocol IoT machine-to-machine messaging system.
https://meshblu.readme.io/
MIT License
816 stars 181 forks source link

TypeErrors using MQTT or websocket #95

Closed Oxymoron79 closed 9 years ago

Oxymoron79 commented 9 years ago

I'm running meshblu in a docker container and wrote test client using the meshblu-mqtt node module. The client periodically broadcasts a message that results in a TypeError in the container:

{"name":"mosca","hostname":"7828215cab06","pid":12,"client":"d62201dd-9eef-4716-83a7-8f6c264640bb","level":20,"timeout":1500000,"msg":"setting keepalive timeout","time":"2015-06-22T00:19:49.909Z","v":0}
{"name":"mosca","hostname":"7828215cab06","pid":12,"client":"d62201dd-9eef-4716-83a7-8f6c264640bb","level":20,"packet":{"topic":"message"},"msg":"published packet","time":"2015-06-22T00:19:49.910Z","v":0}
[TypeError: Cannot call method 'in' of undefined]

And when I try to send a message to the test client using the REST interface, another TypeError is thrown:

Object #<MessageIO> has no method 'in' TypeError: Object #<MessageIO> has no method 'in'
  at /usr/src/app/lib/messageIOEmitter.coffee:16:7
  at arrayEach (/usr/src/app/node_modules/lodash/index.js:1314:13)
  at Function.<anonymous> (/usr/src/app/node_modules/lodash/index.js:3355:13)
  at MessageIOEmitter.emit (/usr/src/app/lib/messageIOEmitter.coffee:14:7)
  at /usr/src/app/lib/messageIOEmitter.coffee:1:1
  at /usr/src/app/lib/sendMessage.js:132:11
  at /usr/src/app/lib/simpleAuth.coffee:11:17
  at [object Object]._onTimeout (/usr/src/app/node_modules/lodash/index.js:1777:43)
  at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

I wrote the same test client using the meshblu node module (websocket), which results in the following TypeError when the client broadcasts a message:

Object #<MessageIO> has no method 'in' TypeError: Object #<MessageIO> has no method 'in'
  at /usr/src/app/lib/messageIOEmitter.coffee:16:7
  at arrayEach (/usr/src/app/node_modules/lodash/index.js:1314:13)
  at Function.<anonymous> (/usr/src/app/node_modules/lodash/index.js:3355:13)
  at MessageIOEmitter.emit (/usr/src/app/lib/messageIOEmitter.coffee:14:7)
  at /usr/src/app/lib/messageIOEmitter.coffee:1:1
  at broadcastMessage (/usr/src/app/lib/sendMessage.js:59:5)
  at Object.sendMessage (/usr/src/app/lib/sendMessage.js:161:5)
  at /usr/src/app/lib/socketLogic.js:147:16
  at /usr/src/app/lib/socketLogic.js:33:14
  at /usr/src/app/lib/whoAmI.js:10:5
  at deviceFound (/usr/src/app/lib/getDevice.coffee:6:5)
  at deviceFound (/usr/src/app/lib/getDeviceWithToken.coffee:48:5)
  at /usr/src/app/lib/getDeviceWithToken.coffee:35:5
  at callback (/usr/src/app/node_modules/nedb/lib/executor.js:30:17)
  at Cursor.execFn (/usr/src/app/node_modules/nedb/lib/datastore.js:449:14)
  at Cursor._exec (/usr/src/app/node_modules/nedb/lib/cursor.js:172:17)
  at /usr/src/app/node_modules/nedb/lib/executor.js:40:13
  at Object.q.process (/usr/src/app/node_modules/nedb/node_modules/async/lib/async.js:731:21)
  at next (/usr/src/app/node_modules/nedb/node_modules/async/lib/async.js:728:27)
  at Object._onImmediate (/usr/src/app/node_modules/nedb/node_modules/async/lib/async.js:24:16)
  at processImmediate [as _immediateCallback] (timers.js:354:15)

Here's the code of the client using the meshblu-mqtt module:

var meshblu = require('meshblu-mqtt');
var conn = meshblu.createConnection({
  "uuid": "d62201dd-9eef-4716-83a7-8f6c264640bb",
  "token": "48f8a93f41e61bd89a8449d07a55a4e736cfee48",
  "qos": 0, // MQTT Quality of Service (0=no confirmation, 1=confirmation, 2=N/A)
  "host": "localhost", // optional - defaults to meshblu.im
  "port": 1883  // optional - defaults to 1883
});
conn.on('ready', function(){
  console.log('UUID AUTHENTICATED!');
  //Listen for messages
  conn.on('message', function(message){
    console.log('message received', message);
  });
  setInterval(function(){
        var data = Math.random()*100
        console.log("sending temperature: "+data);
    conn.message({
            "devices": "*",
            "payload": {
                "temp": data
            }
        });

    },3000);
});

And here's the code of the client using the meshblu module:

var meshblu = require('meshblu');
var uuid = "d62201dd-9eef-4716-83a7-8f6c264640bb"
var token = "48f8a93f41e61bd89a8449d07a55a4e736cfee48"
var conn = meshblu.createConnection({
    "server": "localhost",
    "port": 8080,
    "uuid": uuid,
    "token": token
});
conn.on('notReady', function(data){
    console.log('UUID FAILED AUTHENTICATION!');
    console.log(data);
});
conn.on('ready', function(data){
    console.log('UUID AUTHENTICATED!');
    setInterval(function(){
        var data = Math.random()*100
        console.log("sending temperature: "+data);
    conn.message({
            "devices": "*",
            "payload": {
                "temp": data
            },
            "qos": 0
        });
    },3000);
    conn.on('message', function(data){
        console.log('message received:');
        console.log(data);
    });
});

Any ideas what's going wrong here?

lapsule commented 9 years ago

Looks like same issue for me:

undefined is not a function TypeError: undefined is not a function
  at /home/ubuntu/meshblu/lib/messageIOEmitter.coffee:16:7
  at Function.forEach (/home/ubuntu/meshblu/node_modules/lodash/dist/lodash.js:3298:15)
  at MessageIOEmitter.emit (/home/ubuntu/meshblu/lib/messageIOEmitter.coffee:14:7)
  at /home/ubuntu/meshblu/lib/messageIOEmitter.coffee:1:1
  at /home/ubuntu/meshblu/lib/sendMessage.js:140:11
  at /home/ubuntu/meshblu/lib/simpleAuth.coffee:11:17
  at [object Object]._onTimeout (/home/ubuntu/meshblu/node_modules/lodash/dist/lodash.js:5496:43)
  at Timer.listOnTimeout (timers.js:110:15)
iamruinous commented 9 years ago

Actually my change only fixes it in one case. Reopening.

tryeasy commented 9 years ago

i get the same error with an android mqtt client

Cannot call method 'in' of undefined TypeError: Cannot call method 'in' of undefined at /Users/zhai/work/node/octublu/meshblu/lib/messageIOEmitter.coffee:16:7 at arrayEach (/Users/zhai/work/node/octublu/meshblu/node_modules/lodash/index.js:1289:13) at Function. (/Users/zhai/work/node/octublu/meshblu/node_modules/lodash/index.js:3345:13) at MessageIOEmitter.emit (/Users/zhai/work/node/octublu/meshblu/lib/messageIOEmitter.coffee:14:7) at /Users/zhai/work/node/octublu/meshblu/lib/messageIOEmitter.coffee:1:1 at /Users/zhai/work/node/octublu/meshblu/lib/sendMessage.js:140:11 at /Users/zhai/work/node/octublu/meshblu/lib/simpleAuth.coffee:11:17 at [object Object]._onTimeout (/Users/zhai/work/node/octublu/meshblu/node_modules/lodash/index.js:1773:43) at Timer.listOnTimeout as ontimeout

tryeasy commented 9 years ago

i start redis and it works, nice