Raspberry Pi + Bluez + A2DP + AVRCP - raspberry-pi

In the past 2 days i've been googling for a way to control the media playback from my iPhone through my Raspiberry pi headless speaker.
I've successfully setup the pi using the following tutorial:
Headless A2DP Audio Streaming on Raspbian Stretch
and now i'm looking for a way to control the playback of the audio stream from my raspberry pi.
I've been looking into MediaTransport1, MediaPlayer1, MediaControl1 but unfortunately i wasn't successful.
to give you a few examples of the trial and error I've performed:
for:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B org.bluez.MediaPlayer1.Pause
i received:
Error org.freedesktop.DBus.Error.UnknownMethod: Method "Pause" with signature "" on interface "org.bluez.MediaPlayer1" doesn't exist
for
qdbus --system org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0 org.freedesktop.DBus.Properties.Set org.bluez.MediaTransport1 Volume 127
i received
Error: org.freedesktop.DBus.Error.InvalidSignature
Invalid signature for 'Volume'
Additionally, i've found a player that i thought i could use to build my own script as an example Here but i've got an error:
pi#raspberrypi:~/blueutils $ python simpleplayer.py
Available commands:
PropertiesChanged(interface, properties)
help(cmd)
Use python syntax to pass arguments to available methods.
E.g.: PropertiesChanged({'Metadata' : {'Title': 'My title', 'Album': 'my album' }})
>>> <Interface <ProxyObject wrapping <dbus._dbus.SystemBus (system) at 0xb61968d0> :1.13 /org/bluez/hci0 at 0xb619db70> implementing 'org.bluez.Media1' at 0xb619dc50>
Traceback (most recent call last):
File "simpleplayer.py", line 197, in <module>
media.RegisterPlayer(dbus.ObjectPath(path), player.properties)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.bluez.Error.NotSupported: Operation is not supported
when i do an introspect
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect
i get his:
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.Adapter1">
<method name="StartDiscovery"></method>
<method name="SetDiscoveryFilter">
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="StopDiscovery"></method>
<method name="RemoveDevice">
<arg name="device" type="o" direction="in"/>
</method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Powered" type="b" access="readwrite"></property>
<property name="Discoverable" type="b" access="readwrite"></property>
<property name="DiscoverableTimeout" type="u" access="readwrite"></property>]
<property name="Pairable" type="b" access="readwrite"></property>
<property name="PairableTimeout" type="u" access="readwrite"></property>
<property name="Discovering" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" access="read"></property>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface" type="s" direction="in"/>
<arg name="properties" type="a{sv}" direction="out"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
<interface name="org.bluez.GattManager1">
<method name="RegisterApplication">
<arg name="application" type="o" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterApplication">
<arg name="application" type="o" direction="in"/>
</method>
</interface>
<interface name="org.bluez.Media1">
<method name="RegisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
</method>
<method name="RegisterPlayer">
<arg name="player" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterPlayer">
<arg name="player" type="o" direction="in"/>
</method>
</interface>
<node name="dev_40_9C_28_07_63_DD"/>
<node name="dev_C8_85_50_B1_C8_6B"/>
</node>
Can anybody help me figure this issue out, or does anybody know a procedure to control the playback of the music on the phone, using the raspberry pi ?
Regards.
Update 1:
Thank you so much #Parthiban for it works perfectly.
Additionally, i have to say that i reinstalled the bluez version to 5.50 by following the tutorial here: Install bluez on the Raspberry Pi as i wasn't able to see /playerX (0 in my case). Before i compiled the sources, i did a little extra (not sure it's relevant but it doesn't hurt), i added the .auto_connect = true
the the avrcp profiles as indicated :
Here
hope this helps everybody that may face my problem

You need to specify the signature to set the volume as below,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0' org.freedesktop.DBus.Properties.Set string:"org.bluez.MediaTransport1" string:"Volume" variant:uint16:127
This is because, as mentioned in dbus specification you need to specify three arguments when using set,
Interface Name
Property Name
Property value as variant
For the pause method, explore the "org.bluez.MediaPlayer1" interface of your device using "org.freedesktop.DBus.Introspectable.Introspect". The object path which you have used to access the method "Pause" is wrong. As stated here, you need to use "[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX".
So in your case, it should be,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/playerX' org.bluez.MediaPlayer1.Pause
Where playerX needs to be replaced by your device player (you can get that from Introspect or watch on "InterfaceAdded" Signal.

Related

Why the node's name in the console is different that the one in .launch file?

I am working with the bebop_driver package and running the bebop_driver_node.
The bebop_node.launch file is like this:
<?xml version="1.0"?>
<launch>
<arg name="namespace" default="bebop" />
<arg name="ip" default="10.202.0.1" />
<arg name="drone_type" default="bebop2" /> <!-- available drone types: bebop1, bebop2 -->
<arg name="config_file" default="$(find bebop_driver)/config/defaults.yaml" />
<arg name="camera_info_url" default="package://bebop_driver/data/$(arg drone_type)_camera_calib.yaml" />
<group ns="$(arg namespace)">
<node pkg="bebop_driver" name="bebop_driver" type="bebop_driver_node" output="screen">
<param name="camera_info_url" value="$(arg camera_info_url)" />
<param name="bebop_ip" value="$(arg ip)" />
<rosparam command="load" file="$(arg config_file)" />
</node>
<include file="$(find bebop_description)/launch/description.launch" />
</group>
</launch>
But when I run rosnode list I receive :
/bebop/bebop_driver
Since I am trying to use the rospy.init_node('node_name') this is a problem because I cant type a namespace.
The namespace and name of your node is defined in the launch file. You can find the documentation at thr ROS wiki: roslaunch/XML.
Namespace:
Since you are using a group, the node will be placed in it's namespace, defined by the ns attribute:
<group ns="$(arg namespace)">
In your case the namespace is defined by the argument namespace which is bebop by default:
<arg name="namespace" default="bebop" />
Note that multiple and nested groups are also possible to create namespaces.
Node name:
The node name is specified by its name attribute:
<node [...] name="bebop_driver" [...]
The result is bebop/bebop_driver what you can see by calling rosnode list.

CXF wadl2java generate code from grammar

The code generation with for the methods works fine, but it seems to me that the grammar part is omitted because no Pojo and JAXB annotations are generated. Do I have to specify some additional configuration? I used this command: wadl2java.bat -p packagename /path/to/wadl
Here is a snippet of the wadl.
<application
xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.tns.de">
<grammer>
<xsd:include href="file1.xsd"></xsd:include>
<xsd:include href="file2.xsd"></xsd:include>
<xsd:include href="file3.xsd"></xsd:include>
<xsd:include href="file14.xsd"></xsd:include>
</grammer>
<resources base="http:localhost:8080/rest">
<resource path="status/{id}" id="statusId">
<param name="id" type="xsd:unsignedInt" required="true" default="" style="template"/>
<method name="GET" id="getById">
<request>
<representation mediaType="application/json" element="tns:type1"/>
</request>
<response>
<representation mediaType="application/json" element="tns:type2"/>
</response>
</method>
....
I found my mistake. There was a typo in the wadl. Previously I used <grammer> but you have to use <grammars>
Now it works.
<application
xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.tns.de">
<grammars>
<include href="file1.xsd"></xsd:include>
<include href="file2.xsd"></xsd:include>
<include href="file3.xsd"></xsd:include>
<include href="file14.xsd"></xsd:include>
</grammars>
<resources base="http:localhost:8080/rest">
<resource path="status/{id}" id="statusId">
<param name="id" type="xsd:unsignedInt" required="true" default="" style="template"/>
<method name="GET" id="getById">
<request>
<representation mediaType="application/json" element="tns:type1"/>
</request>
<response>
<representation mediaType="application/json" element="tns:type2"/>
</response>
</method>

phing dbdeploy with postgres

Hiho,
I want to use Phing an dbdeploy with a postgres DB.
the problem is that I can not connect to the database with the connection string because I can not define a password.
Does any one has an solution for this?
The following is the deply xml:
`
<!-- load the dbdeploy task -->
<taskdef name="dbdeploy" classname="phing.tasks.ext.dbdeploy.DbDeployTask" />
<!-- these two filenames will contain the generated SQL to do the deploy and roll it back -->
<property name="build.dbdeploy.deployfile" value="scripts/deploy-${DSTAMP}${TSTAMP}.sql" />
<property name="build.dbdeploy.undofile" value="scripts/undo-${DSTAMP}${TSTAMP}.sql" />
<!-- generate the deployment scripts -->
<dbdeploy
url="pgsql:host=${db.host};dbname=${db.name}"
userid="${db.username}"
password=""
dir="${phing.dir}/sql"
outputfile="${build.dbdeploy.deployfile}"
undooutputfile="${build.dbdeploy.undofile}" />
<!-- execute the SQL - Use psql command line to avoid trouble with large
files or many statements and PDO -->
<trycatch>
<try>
<exec
command="pqsql -h${db.host} -U${db.username} -p${db.port} -d${db.name} < ${build.dbdeploy.deployfile} -W"
dir="${phing.dir}"
checkreturn="true"
output="${phing.dir}/cache/deploy-${DSTAMP}${TSTAMP}.log"
error="${phing.dir}/cache/deploy-error-${DSTAMP}${TSTAMP}.log"
/>
<echo msg="Datenbank erfolgreich ausgerollt"/>
</try>
<catch>
<echo msg="Fehler beim ausrollen der Datenbank, führe Rollback durch"/>
<exec
command="pgsql -h${db.host} -U${db.username} -p${db.port} -d${db.name} < ${build.dbdeploy.undofile}"
dir="${phing.dir}"
checkreturn="true"
/>
<echo msg="Rollback erfolgreich"/>
</catch>
</trycatch>
</target>
<!-- ============================================ -->
<!-- Target: writeFiles -->
<!-- ============================================ -->
<target name="writeFiles" description="Write all properties in files">
<copy
file="${dir}config/autoload/local.php.dist"
tofile="${dir}config/autoload/local.php"
overwrite="true"
>
<filterchain>
<replacetokens begintoken="#" endtoken="#">
<token key="db.host" value="${db.host}"/>
<token key="db.username" value="${db.username}"/>
<token key="db.password" value="${db.password}"/>
<token key="db.name" value="${db.name}"/>
<token key="db.port" value="${db.port}"/>
</replacetokens>
</filterchain>
</copy>
<echo>local.php geschrieben.</echo>
</target>`
You can create a password file for the system user (the user which will execute the phing script).

Passing a parameter to NAnt build script

This is my scenario:
I have a build.bat that holds:
call tools\nant-0.92\bin\nant.exe -buildfile:deploy.build %* -logfile:deploy_NAnt.log
Part of deploy.build holds:
<project
name="EdpClient"
basedir="." default="build"
xmlns="http://nant.sf.net/release/0.92/nantContrib.xsd">
<!--INIT -->
...
<property name="version" value="1.48.0.4" />
...
<!--RELEVANT TARGET-->
<target name="BuildProductionApplication" description="Build">
<property
name="publishFolderParameter"
value="/p:PublishDir=${productionPublishFolder}" />
<echo message="Building..." />
<exec
program="${msbuildExe}"
workingdir="." verbose="true">
<arg value="${projectFile}" />
<arg value="/target:Clean;Publish" />
<arg value="${publishFolderParameter}" />
<arg value="/property:ApplicationVersion=${version}" />
<arg value="/property:PublisherName="${publisherName}"" />
</exec>
<echo message="Built" />
</target>
...
</project>
Now my question is:
How can i call "build.bat -version 1.48.0.4" and replace the param
in my structure?
If the -version param is not supplied the script should throw some
sort of msg back in command line?
Thanks to all that help!
This is how i did it:
In deploy.build file i changed:
<property name="version" value="1.48.0.4" />
to:
<property name="version" value="${arg.version}" />
And this is how build.bat (batch) looks like now:
#ECHO OFF
IF %1.==. GOTO ERROR
ECHO:BUILDING VERSION: %1 ...
CALL tools\nant-0.92\bin\nant.exe -buildfile:deploy.build -D:arg.version=%1 -logfile:deploy_NAnt.log
GOTO END
:ERROR
ECHO.
ECHO Please provide the version parameter (eg. "deploy 1.1.1.1")
ECHO.
GOTO END
:END
Now I can call build 1.48.0.4 command.
It suits all my needs.

Default components in install4j

When my "installation components" screen runs (I'm in console mode, if it matters), I get the list of components to install, as expected. However, the "default" response is to accept 2 of the components, even though their "Initially Selected for installation" option is false.
I want the user to be able to NOT select any of the optional components, and this isn't possible when it's defaulting to have some of them "Selected".
As far as I can tell, there are no varfiles being loaded.
Snippet from my install4j file:
<component name="A" id="527" customizedId="a" displayDescription="false" hideHelpButton="false" selected="false" changeable="true" downloadable="false" hidden="false">
<description />
<include all="false">
<entry location=".i4j_external_314/a" fileType="regular" />
<entry location=".i4j_external_2366/a" fileType="regular" />
<entry location=".i4j_external_316/a" fileType="regular" />
<entry location=".i4j_external_8155/a" fileType="regular" />
<entry location=".i4j_external_318/a" fileType="regular" />
</include>
<dependencies />
</component>
<component name="B" id="528" customizedId="b" displayDescription="false" hideHelpButton="false" selected="false" changeable="true" downloadable="false" hidden="false">
<description />
<include all="false">
<entry location=".i4j_external_316/b" fileType="regular" />
<entry location=".i4j_external_8155/b" fileType="regular" />
<entry location=".i4j_external_318/b" fileType="regular" />
</include>
<dependencies />
</component>
<component name="C" id="69" customizedId="c" displayDescription="false" hideHelpButton="false" selected="false" changeable="true" downloadable="false" hidden="false">
<description />
<include all="false">
<entry location=".i4j_external_316/c" fileType="regular" />
<entry location=".i4j_external_8155/c" fileType="regular" />
<entry location=".i4j_external_318/c" fileType="regular" />
</include>
<dependencies />
Notice that in all 3 components, "selected" is false, and "changeable" is true.
When the installer runs, though, here is how it is presented:
Which components should be installed?
*: D
*: E
1: A
2: B
3: C
Please enter a comma-separated list of the selected values or [Enter] for the default selection:
[1,2]
(D and E are fine - they're set to "selected" and "not user changeable")
So, even though A and B are not "selected", they show up as a default. Also notice that "C" is configured the same way as "A" and "B", yet doesn't show up in the default.
This is problematic, because I have no way to select "none" of the optional components. I have to select at least 1 in order to not accept the default.
Thanks for any info - if you need more detail, I'd be happy to provide it.