title: NodeJS dbus not working
body: <p>I'm trying to get status from omxplayer with NodeJS via DBus, to do that i'm just trying to execuce shell script:</p>
  
  <pre><code>    #!/bin/bash
      #set -x
      OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus"
      OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.pid"
      export DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR`
      export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`
      [ -z "$DBUS_SESSION_BUS_ADDRESS" ] &amp;&amp; { echo "Must have DBUS_SESSION_BUS_ADDRESS" &gt;&amp;2; exit 1; }
      duration=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Duration`
      [ $? -ne 0 ] &amp;&amp; exit 1
      duration="$(awk '{print $2}' &lt;&lt;&lt; "$duration")"
      position=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Position`
      [ $? -ne 0 ] &amp;&amp; exit 1
      position="$(awk '{print $2}' &lt;&lt;&lt; "$position")"
      playstatus=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.PlaybackStatus`
      [ $? -ne 0 ] &amp;&amp; exit 1
      playstatus="$(sed 's/^ *//;s/ *$//;' &lt;&lt;&lt; "$playstatus")"
      paused="true"
      [ "$playstatus" == "Playing" ] &amp;&amp; paused="false"
      echo "Duration: $duration"
      echo "Position: $position"
      echo "Paused: $paused"
      ;;
  </code></pre>
  
  <p>with</p>
  
  <pre><code>var exec = require('child_process').exec;
  exec('bash status.sh', function() {
      console.log(arguments);
  })
  </code></pre>
  
  <p>but it prints </p>
  
  <pre><code>    { '0':
         { [Error: Command failed: Failed to open connection to "session" message bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
         ] killed: false, code: 1, signal: null },
        '1': '',
        '2': 'Failed to open connection to "session" message bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.\n' }
  </code></pre>
  
  <p>When I execute that script directly in console it works. NodeJS is running on Raspberry Pi.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have also tried "node-dbus" and "dbus-native" modules, but none of them worked for me, but maybe I used them incorrectly? To execute</p>
  
  <pre><code>dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Duration
  </code></pre>
  
  <p>I used
  <strong>dbus-native</strong></p>
  
  <pre><code>    var exec = require('child_process').exec;
      exec('cat /tmp/omxplayerdbus', function(error, data, stderr) {
          data = data.replace("\n",'');
          var dbus = require('dbus-native');
          var bus = dbus.sessionBus({
              busAddress: data //unix:abstract=/tmp/dbus-7BuZanKhmv,guid=7fafe7baa2d38357478f04ff5429712a
          });
          bus.invoke({
              path: '/org/mpris/MediaPlayer2',
              destination: 'org.mpris.MediaPlayer2.omxplayer',
              'interface': 'org.freedesktop.DBus.Properties.Position'
          }, function(err, res) {
              console.log(arguments);
          });
          //And this
          var conn = dbus({
              busAddress: data
          });
          conn.message({
              path:'/org/mpris/MediaPlayer2',
              destination: 'org.mpris.MediaPlayer2.omxplayer',
              type: dbus.messageType.methodCall
          });
          conn.on('message', function(msg) { console.log(msg); }).on('error', function() {
              console.log(arguments);
          }).on('connect', function() {
              console.log(arguments);
          });
      });
  </code></pre>
  
  <p>both of these methods throws me this error:</p>
  
  <pre><code>    events.js:72
              throw er; // Unhandled 'error' event
                    ^
      Error: write EPIPE
          at errnoException (net.js:904:11)
          at Object.afterWrite (net.js:720:19)
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I'm now using "dbus-native" module and still keep getting "EPIPE" error. I have checked "Handshake.js" and there is everything alright, so I dumped stdin and stdout messages:</p>
  
  <pre><code>    {stdin}AUTH EXTERNAL 30
  
      {stdout}OK df028c4a159a4db39ccc41c0542b9e3b
  
      {stdin}BEGIN
  
      {stdin}lmo/org/freedesktop/DBussorg.freedesktop.DBussHellosorg.freedesktop.DBus
      PuTTY{stdin}l5�o/org/mpris/MediaPlayer2sorg.freedesktop.DBus.PropertiessGets org.mpris.MediaPlayer2.omxplayegss org.mpris.MediaPlayer2.omxplayePosition
  </code></pre>
  
  <p>{stdout} - stdout message line
  {stdin} - stdin message line</p>
  
  <p>and then "EPIPE".</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>I have found out that "EPIPE" error is throwed right after first dbus "DATA" command, in this case it's </p>
  
  <p><code>lmo/org/freedesktop/DBussorg.freedesktop.DBussHellosorg.freedesktop.DBus
  PuTTY{stdin}l5�o/org/mpris/MediaPlayer2sorg.freedesktop.DBus.PropertiessGets org.mpris.MediaPlayer2.omxplayegss org.mpris.MediaPlayer2.omxplayePosition</code></p>
  
  <p>i'm new in communications via dbus, but according to <a href="http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol-overview" rel="nofollow">DBus protocol</a>, messages should be sent <code>DATA &lt;data in hex encoding&gt;</code>, but <code>dbus-native</code> sends messages without <code>DATA</code> command name.</p>