sidorares/dbus-native

listen for signal on system bus

cjcdev opened this issue · 1 comments

I'm tying to listen for a signal using dbus-native that was sent on the Linux command line with the following command:
dbus-send --system --type=signal /com/test/clock com.test.clock.bt boolean:true

I've tried various way of doing it and I can't seem to get it to work. I do see the signal when I use "dbus-monitor --system" on the command line, so that tells me it's on the bus.

This doesn't work...

var dbus = require('dbus-native');
var bus = dbus.systemBus();
bus.connection.on('message', function(msg) { console.log("msg nativeDbus: " + msg.path); });
bus.connection.on('error', function(err) { console.log("error nativeDbus: " + err); });
bus.addMatch("type='signal'", function() { console.log("Signal addMatch"); });

And this doesn't work...

var conn = dbus();
conn.message({
    path:  "/com/test/clock",
    interface: "com.test.clock",
    member: "bt",
    type: 4,
    });
    conn.on('message', function(msg) {
        console.log("msg: " + msg.member);
    });
    conn.on('error', function(err) {
        console.log("err: " + err);
    });

Can someone provide an example to this simple use case?

If you are still trying to do this, you might find some clues in the examples. I was doing something similar to what you are trying and found that the basic-client.js file led me to my answer.

In particular, it looks to me like you've skipped the steps of getting the "service" and then the "interface" by calling getService() and getInterface(). The example will show you how that's done. (Of course, you have to call dbus.systemBus() where the example code calls dbus.sessionBus() but you already know that.)

Good luck!