dbus-native icon indicating copy to clipboard operation
dbus-native copied to clipboard

Implement dbus-send command

Open hoigo opened this issue 10 years ago • 12 comments

I'm a newbie here and I would like to use your d-bus library. I wanted to implement the following call with node-dbus, but I couldn't get it to a successful run:

dbus-send --print-reply --type=method_call --bus='unix:path=/var/run/dbus/my_bus_socket' --dest='de.my.Device' '/de/my/Device/alarm' de.my.common.Alarm.get_alarm_state

Could you give me a hint on how to do it?

Thanks in advance!

hoigo avatar Mar 19 '15 12:03 hoigo

var dbus = require('dbus-native');
var bus = dbus.sessionBus({socket: '/var/run/dbus/my_bus_socket'});
bus.invoke({
   destination: 'de.my.Device',
   path: '/de/my/Device/alarm',
   interface: 'de.my.common.Alarm',
   member: 'get_alarm_state'
}, function(err, param1, param2, param3) {
  // you get as much parameters here as your response signature indicate
});

sidorares avatar Mar 19 '15 13:03 sidorares

Does the current version run with Node 0.12.0?

hoigo avatar Mar 23 '15 08:03 hoigo

I need to check binary abstractsocket module status but if you connect using tcp or normal unix sockets ( usually the case for system bus ) it does work for any node version from 0.6 to 1.6.1 (iojs) as it uses very little of node api ( basically EventEmitter, Buffer and net )

sidorares avatar Mar 23 '15 09:03 sidorares

Well, I tried it with Node 0.10 and I got a TypeError. This is the stack trace:

events.js:74 throw TypeError('Uncaught, unspecified "error" event.'); ^ TypeError: Uncaught, unspecified "error" event. at TypeError () at EventEmitter.emit (events.js:74:15) at /home/node_modules/dbus-native/index.js:93:19 at /home/node_modules/dbus-native/lib/handshake.js:105:22 at /home/node_modules/dbus-native/lib/handshake.js:29:14 at Object.oncomplete (fs.js:107:15)

I logged the error and it says the following:

Error: ENOENT, stat '/root/.dbus-keyrings'

Well, there's no ".dbus-keyrings" folder in the system. Do I need such a directory?

hoigo avatar Mar 27 '15 13:03 hoigo

Does dbus-send command work for you? If so, it's a bug in handhake part of this library

sidorares avatar Mar 27 '15 21:03 sidorares

Yes, dbus-send works without a problem! Could you provide a bugfix?

hoigo avatar Mar 30 '15 06:03 hoigo

I'll need to replicate issue you have

Can you add one line just after readLine at https://github.com/sidorares/node-dbus/blob/master/lib/handshake.js#L74 with

    console.log(authMethod, id, line);

And post results?

You can edit your local copy in ./node_modules/dbus-native/lib/handshake.js

sidorares avatar Mar 30 '15 06:03 sidorares

Yep, here's the output:

EXTERNAL 30 <Buffer 52 45 4a 45 43 54 45 44 20 45 58 54 45 52 4e 41 4c 20 44 42 55 53 5f 43 4f 4f 4b 49 45 5f 53 48 41 31 20 41 4e 4f 4e 59 4d 4f 55 53 0d>

hoigo avatar Mar 30 '15 07:03 hoigo

the buffer part is 'REJECTED EXTERNAL DBUS_COOKIE_SHA1 ANONYMOUS\r'

thanks, I'm looking into it

sidorares avatar Mar 30 '15 07:03 sidorares

did you find something for solving it?

hoigo avatar Apr 14 '15 12:04 hoigo

can't reproduce locally - handshake succeeds, after "EXTERNAL 30\r" I get "OK .." reply ( I started unity root session )

Why are you running your script as root? Do you have dbus session started for root user?

sidorares avatar Apr 15 '15 00:04 sidorares

On that system every process is running as root and I started the script as root.

I tried to run your p2p example on a 32-bit Ubuntu system under a user account and I got the same error at the client script.

hoigo avatar Apr 15 '15 06:04 hoigo