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

Send/Receive messages #128

Closed anhldbk closed 6 years ago

anhldbk commented 8 years ago

I'm following the tutorial. Here the provided code to send periodical messages to the program itself:

    setInterval(function(){
        console.log("sending message");
        conn.message({
            "devices": data.uuid,
            "payload": {
                "hello":"world"
            }
        });
    },300);

But if I modify the message to send to all devices, "devices": "all" there's no message to receive.

Would you pls tell me what wrong is?

chrismatthieu commented 8 years ago

Try "devices: "*"

anhldbk commented 8 years ago

@chrismatthieu The same thing. It does NOT work.

chrismatthieu commented 8 years ago

Sending messages to "*" devices only works for devices that are subscribing to the emitters UUID. Our subscription API is documented here - https://meshblu-socketio.readme.io/docs/subscribe

chrismatthieu commented 8 years ago

I mocked up the following demo for you to try - https://gist.github.com/chrismatthieu/5949e465e67f52134e7e30dbe65b9506

anhldbk commented 8 years ago

@chrismatthieu Thank you for the explanation! You're so kind.

The device must have the appropriate whitelists configured in order to allow message forwarding, right?

So imagine we have a code like this one:

conn.on('ready', function(data){
    console.log('UUID AUTHENTICATED!');
    console.log(data);

    setInterval(function(){
        console.log("sending message");
        conn.message({
            "devices": "*",
            "payload": {
                "hello":"world"
            }
        });
    },300);

    conn.subscribe(config.uuid, function(data){ // the device subscribes to itself
        console.log(data)
    })
    conn.on('message', function(data){
        console.log('message received');
        console.log(data);
    });
});

Also the device is set up with the following property:

{
  "receiveWhitelist": [] 
}

The property indicates that there's no device could receive messages from the device (including itself)

To my surprise, the device still receive broadcast messages. Anything wrong?