13 Replies Latest reply on Jul 14, 2017 12:02 PM by Intel Corporation

    Play music on start up with bluetooth device

    c2

      Hello,

       

      I am trying to get edison to play a song on startup. I have the bluetooth device paired and edison is getting connected to the bluetooth speaker at startup. But I am not able to play a song on the speaker at start up though it works fine from a terminal.

       

      This is the service I am using(songtest.service)

       

      [Unit]

      Description=song test

      Wants=network-online.target sound.target bluetooth.target bluetooth.service pulseaudio.service obex.service bluetoothconnecttest.service

      After=sound.target console-shell.service console-getty.service media-sdcard.mount bluetooth.target bluetooth.service pulseaudio.service obex.service bluetoothconnecttest.service

       

      [Service]

      Type=oneshot

      ExecStart=/home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3

       

      [Install]

      WantedBy=multi-user.target

       

      bluetoothconnecttest.service is the service used to connect to the bluetooth speaker. When I check the output of ps, I can see that the process has definitely started:

       

      1325 root     29288 S    /home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3

       

      The line '/home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3' works fine from the terminal and it plays the song on the bluetooth speaker.

       

      Any help is appreciated.

       

      Thanks!

        • 1. Re: Play music on start up with bluetooth device
          c2

          I also tried to start with sh instead

           

          ExecStart=/bin/sh -c "/home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3"

          • 2. Re: Play music on start up with bluetooth device
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi c2,

             

            Thanks for your interest in the Intel® Edison™ Platform.

             

            Yes indeed, it is strange that it runs on your Linux console, but not on the system service. From this behavior, I can conclude that there must be something wrong with your service configuration. I would encourage to check your [Service] section and add the line WorkingDirectory, also I would try to change the Type line. By the way I think that this document might be handy https://www.freedesktop.org/software/systemd/man/systemd.service.html#Options .

             

            Finally, I would check the shebang on your service file, if you don't know what a shebang is, please see the image below in order to understand what I'm trying to explain (Look at the highlighted line).

             

            shebang.PNG

             

            Have a great weekend!

             

            Best Regards,
            -Jose P.

            • 3. Re: Play music on start up with bluetooth device
              c2

              I tried both. But there is no change. Here is the service now:

              #!/bin/sh

              [Unit]

              Description=song test

              Wants=network-online.target sound.target bluetooth.target bluetooth.service pulseaudio.service obex.service bluetoothconnecttest.service dbus.service

              After=sound.target console-shell.service console-getty.service media-sdcard.mount bluetooth.target bluetooth.service pulseaudio.service obex.service dbus.service bluetoothconnecttest.service

               

              [Service]

              ExecStart=/home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3

              WorkingDirectory=/home/root/MPlayer-1.1.1/

               

              [Install]

              WantedBy=multi-user.target

              • 4. Re: Play music on start up with bluetooth device
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi c2,

                 

                I'm sorry to hear that my suggestion didn't work. I would like to perform a little experiment instead of using the ExecStart=/home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3, I would like for you to use the Blink example How to create a system service with systemd on Edison and Galileo’s eglibc image . Please don't modify anything on the [Unit] and [Install] section, so your system service file should look like this:

                 

                [Unit]

                Description=song test

                Wants=network-online.target sound.target bluetooth.target bluetooth.service pulseaudio.service obex.service bluetoothconnecttest.service dbus.service

                After=sound.target console-shell.service console-getty.service media-sdcard.mount bluetooth.target bluetooth.service pulseaudio.service obex.service dbus.service bluetoothconnecttest.service

                 

                [Service]

                ExecStart=/usr/bin/node /home/root/blink.js 

                 

                [Install]

                WantedBy=multi-user.target

                 

                We will be waiting for your results, have a nice day!

                 

                Best Regards,
                -Jose P.

                • 5. Re: Play music on start up with bluetooth device
                  c2

                  Hello

                   

                  I am using the sparkfun board for edison and I could not find the corresponding GPIO pin connected to led. I checked http://download.intel.com/support/edison/sb/edisonarduino_hg_331191007.pdf and http://mu.elecfans.net/201611/Intel-04-edisonbreakout_hg_331190006.pdf . But I am not sure. I tried to run it without service first and no led was blinking. I tried with pin 13 acc. to the link How to create a system service with systemd on Edison and Galileo’s eglibc image .

                   

                  But I have another service that works ok. Its bluetoothconnecttest.service which runs a script to connect to bluetooth speaker on startup.

                  bluetoothconnecttest.service:

                  [Unit]

                  Description=bluetoooth connect to speaker service

                  After=bluetooth.target hostapd.service pulseaudio.service

                  Wants=bluetooth.target pulseaudio.service

                  [Service]

                  Type=oneshot

                  ExecStart=/home/root/register_bt_speaker.sh

                  [Install]

                  WantedBy=multi-user.target

                   

                  register_bt_speaker.sh:

                  #!/bin/bash

                  mac_addr=58:56:12:30:09:9D

                  sink_addr=$(echo "$mac_addr" | tr ':' '_')

                  echo "Connecting device $mac_addr and sink $sink_addr"

                  rfkill unblock bluetooth

                  sleep 2

                  #bluetoothctl <<< "unblock $mac_addr"

                  while bluetoothctl <<< "info $mac_addr" | grep "Connected: no"; do

                    bluetoothctl <<< "connect $mac_addr"

                    echo "connecting $mac_addr ...."

                    sleep 10

                  done

                  sleep 5

                  pactl set-default-sink bluez_sink.58_56_12_30_09_9D

                   

                  Thanks!

                  • 6. Re: Play music on start up with bluetooth device
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hi c2,

                    I'm glad to hear that you were able to solve your issue by own! And thanks for sharing your solution in such a detailed manner, it will be useful for other members of the community having similar issues.

                    Have a great day!

                    Best Regards,
                    -Jose P.

                    • 7. Re: Play music on start up with bluetooth device
                      c2

                      My issue is not solved!!!

                      My problem is that music is not played on the Bluetooth speaker. I can connect to Bluetooth speaker at start up.. I execute the second service (song test) after Bluetooth connect. I can even see the process /home/root/MPlayer-1.1.1/mplayer /home/root/done.mp3 start but its not being played!!!

                      Thanks!

                      • 8. Re: Play music on start up with bluetooth device
                        Intel Corporation
                        This message was posted on behalf of Intel Corporation

                        Hi c2,

                        I apologize when I read "But I have another service that works ok" I thought that you were able to solved your issue. 

                        Would you be so kind to explain me the Wants and After of your [Unit], I'm referring to these ones:

                        Wants=network-online.target sound.target bluetooth.target bluetooth.service pulseaudio.service obex.service bluetoothconnecttest.service dbus.service
                        After=sound.target console-shell.service console-getty.service media-sdcard.mount bluetooth.target bluetooth.service pulseaudio.service obex.service dbus.service bluetoothconnecttest.service

                        We will be waiting for your reply, have a nice day!

                        Best Regards,
                        -Jose P.

                        • 9. Re: Play music on start up with bluetooth device
                          c2

                          Its dependencies for this service. More details are here: https://www.freedesktop.org/software/systemd/man/systemd.unit.html

                          I was not sure which all to add. So I added most services related to Bluetooth or sound. bluetoothconnecttest.service is the service connecting the speaker to edison. That is required. Without it, this service might start before the speaker is connected. I think that I might not have added all the services needed to play music on bluetooth speaker?

                          • 10. Re: Play music on start up with bluetooth device
                            Intel Corporation
                            This message was posted on behalf of Intel Corporation

                            Hi c2,

                            Unfortunately, I don't  have a speaker, so I can't replicate your issue. At the moment the best advice that I can give you is to try to use another ExecStart file with the song service, this in order to see if the root of the error is in the Wants and After that you define in your [Unit] section.

                            We will be waiting for your results, have a nice day!

                            Best Regards,
                            -Jose P.

                            • 11. Re: Play music on start up with bluetooth device
                              Intel Corporation
                              This message was posted on behalf of Intel Corporation

                              Hi c2,

                              Were you able to solve your issue? Has my advice been helpful? Please let me know to see if there is anything else that we can do for you.

                              We will be waiting for your reply, have a nice day!

                              Best Regards,
                              -Jose P.
                               

                              • 12. Re: Play music on start up with bluetooth device
                                c2

                                No. Its not resolved. If I use another Execstart it works. Even this Execstart works and I can see the process running also! But music is not playing!

                                • 13. Re: Play music on start up with bluetooth device
                                  Intel Corporation
                                  This message was posted on behalf of Intel Corporation

                                  Hi c2,

                                  I'm sorry to hear that it is still not working. Unfortunately, like I mention we don't have the necessary hardware in order to replicate your issue. If another Execstart worked then I can conclude that you might no have added all the services needed to play music, so you might want to look into that. We would like to apologize for not being able to help you any further, maybe other members of the community might share their feedback with you. 

                                  Best Regards,
                                  -Jose P.