maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   Desktop Command Execution Widget scripts (https://talk.maemo.org/showthread.php?t=39177)

5spdvl 2011-10-27 04:58

Re: Desktop Command Execution Widget scripts
 
I have the script I want to use, but I can't seem to get it to work with DCEW:

-trying to connect to a specific BT MAC address (Nokia BH-503 headphones)

I have tried this from karimko:
Quote:

Originally Posted by karimko
Try this in xterm:

Code:

rfcomm connect 0 <MAC_ADDRESS>
don't forget to have your bluetooth enabled and just replace <MAC_ADDRESS> with your car's stereo.

I have the same problem like you guys, except with a Kenwood

[EDIT]: You can use Desktop Command Execution widget with this command to have a shortcut on ur desktop

(http://talk.maemo.org/showpost.php?p=746631&postcount=4)

However, this only works once BT is on, and doesn't "genuinely connect" (status bar BT icon turns blue, but device does not respond/receive commands).

I have tried this:
Code:

adapter=$(dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.DefaultAdapter | awk -F'"' '/at/ {print $2}')
device=$(dbus-send --system --print-reply --dest=org.bluez ${adapter} org.bluez.Adapter.FindDevice string:${devmac} | awk -F'"' '/at/ {print $2}')
dbus-send --system --type=method_call --print-reply --dest=org.bluez ${device} org.bluez.${service}.Connect

...inside a script I called "headphones.sh", which I call inside DCEW via:

Code:

run-standalone.sh <directory>/headphones.sh
which does not work. My understanding of shell scripting is probably at fault - I created a notepad file in windows with the script code, saved it as headphones.sh(.txt), then transferred to my N900 and renamed it just headphones.sh.

Can anyone point me in the right direction? Nokia revised the programming for their BH-503 (board revision 3), and now I can't connect to my latest pair automatically (must access via the BT menu, despite being "trusted").

nicolai 2011-10-27 08:34

Re: Desktop Command Execution Widget scripts
 
Quote:

Originally Posted by 5spdvl (Post 1114359)
which does not work. My understanding of shell scripting is probably at fault - I created a notepad file in windows with the script code, saved it as headphones.sh(.txt), then transferred to my N900 and renamed it just headphones.sh.

Maybe wrong line endings dos/unix ?
Run the script from the commandline and post the error messages.

5spdvl 2011-10-27 08:52

Re: Desktop Command Execution Widget scripts
 
1 Attachment(s)
Code:

~ $ sh /home/user/MyDocs/headphones.sh
: not foundMyDocs/headphones.sh: line 2: /home/user/MyDocs/headphones.sh: line 4: syntax error: Bad substitution

I've attached my headphones.sh script. My shell scripting knowledge is pretty limited, but unlike others that just ask how at least I come prepared with some effort!

Edit: I know it says .sh.txt, but it's been renamed via FileBox on my N900 .sh.

2nd edit: if someone can recommend a program (Win7 or Maemo) that I can use for writing shell scripts that will save with the correct file extension, I'm all for it.

nicolai 2011-10-27 09:10

Re: Desktop Command Execution Widget scripts
 
1 Attachment(s)
Try this one.
I removed the DOS lineendings and removed the ${..} around
your mac address (this was the "bad substitution" error)

5spdvl 2011-10-27 09:29

Re: Desktop Command Execution Widget scripts
 
Thanks a lot nicolai, I really appreciate it. :)

Code:

~ $ sh /home/user/MyDocs/headphones2.sh
process 27316: arguments to dbus_message_new_method_call() were incorrect, assertion "interface == NULL || _dbus_check_is_valid_interface (interface)" failed in file dbus-message.c line 1080.
This is normally a bug in some application using the D-Bus library.
process 27316: arguments to dbus_message_set_auto_start() were incorrect, assertion "message != NULL" failed in file dbus message.c line 2492.
This is normalle a bug in some application using the D-Bus library.
Couldn't allocate D-Bus message
~ $

So what I gather from that is my method of calling the script via xterm is now correct (thanks to you, nicolai), however the code of the script appears to be erroneous.

nicolai 2011-10-27 09:54

Re: Desktop Command Execution Widget scripts
 
1 Attachment(s)
I found a similiar script at the phone control wiki entry.
http://wiki.maemo.org/Phone_control#...pecific_device
There are two variables are defined, one for the MAC
and one for the service.

In your script you missed the "service" variable, too.
I changed your code and put the "AudioSink" value in the
dbus call.

5spdvl 2011-10-27 10:05

Re: Desktop Command Execution Widget scripts
 
Ah! I had "AutoSink" in there (I know you can put any service in that string, but I wasn't sure what the available options are, or which one I needed).

Code:

~ $ sh /home/user/MyDocs/headphones3.sh
Error org.bluez.Error.Failed: Failed to create a stream

Same again, but this time with BT already on:

Code:

~ $ sh /home/user/MyDocs/headphones3.sh
Error org.bluez.Error.Failed: Stream setup failed

Same again, but this time with BT already on, and headphones awaiting pairing:

Code:

~ $ sh /home/user/MyDocs/headphones3.sh
method return sender=:1.32 -> dest=:1.639 reply_serial=2

Success! Connects as per normal, streams audio under AD2P profile. Only issue is now having to turn BT on first. Again, thanks for you help nicolai!

In DCEW, using

Code:

sh /home/user/MyDocs/headphones3.sh
successfully pairs with the headphones when both the N900/BH-503 are awaiting connection.

Any ideas on having the script also turn BT on (N900) before it attempts connection?

I write a script with the content

Code:

dbus-send --system --type=method_call --dest=org.bluez /org/bluez/906/hci0 org.bluez.Adaptor.SetProperty string:Powered variant:boolean:true
and tried it via xterm

Code:

sh /home/user/MyDocs/Bton.sh
which executes fine, but doesn't turn BT on or leave any comments in xterm. :(

nicolai 2011-10-27 10:30

Re: Desktop Command Execution Widget scripts
 
1 Attachment(s)
Again :-)
Phone control wiki:
http://wiki.maemo.org/Phone_control#Enable

I added the "enable" dbus-call command to your script.

Nicolai

5spdvl 2011-10-27 10:39

Re: Desktop Command Execution Widget scripts
 
Excellent. Perfect Nicolai. :D

I had some trouble opening the phone Control wiki page for a few minutes there, but found the enable code right when you posted. But as above my little script didn't enable it. Guess it's the way you've inserted the enable command within the rest of the script.

So, problem solved. now to make a fancy button. :D

5spdvl 2011-10-27 10:44

Re: Desktop Command Execution Widget scripts
 
Actually, it seems to keep turning BT on now. Which is odd, because it's only when the DCEW is placed on the desktop, yet without pushing on it. Like it's running the script without being called?

Edit: unchecked "Update when switched to the desktop", now it behaves normally (turns BT on only when called).

Edit: does not connect to defined MAC address after being called. Buuuuuuuut it helps when I put the right MAC in. D'oh!


All times are GMT. The time now is 13:52.

vBulletin® Version 3.8.8