RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Help with script to maintain bluetooth connection

    Scheduled Pinned Locked Moved Help and Support
    13 Posts 5 Posters 6.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lilbudL
      lilbud
      last edited by

      Might want to try these instructions, use the 8bitdo instructions

      https://github.com/RetroPie/RetroPie-Setup/wiki/Setting-up-a-Bluetooth-controller

      Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

      Backlog: http://backloggery.com/lilbud

      1 Reply Last reply Reply Quote 0
      • JasperSladeJ
        JasperSlade
        last edited by

        I followed those instructions exactly, and have had 100% success connecting the gamepad at startup. My issue is when the gamepad goes to sleep (say I get up to help my wife with something) when I come back and my gamepad has powered down due to inactivity, when I power it back up, it doesn't reconnect to the Pi.
        At this point I have to either reconnect via the command line, or reboot the Pi.

        ~Jasper

        1 Reply Last reply Reply Quote 0
        • JasperSladeJ
          JasperSlade
          last edited by

          I think I may have found a solution. If someone with a little more knowledge than me can take a look at this and let me know what they think. Adding this to my already existing startup script:

          #!/bin/bash
          address="XX:XX:XX:XX:XX:XX"
          while (sleep 1)
          do
          connected=$(hidd --show) > /dev/null
          if [[ ! $connected =~ .${address}. ]] ; then
          hidd --connect ${address} > /dev/null 2>&1
          fi
          done

          ~Jasper

          lilbudL 1 Reply Last reply Reply Quote 1
          • meleuM
            meleu
            last edited by

            I suffer with this problem as well.

            • Useful topics
            • joystick-selection tool
            • rpie-art tool
            • achievements I made
            1 Reply Last reply Reply Quote 0
            • lilbudL
              lilbud @JasperSlade
              last edited by

              @JasperSlade Did you create those files listed in the guide?

              Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

              Backlog: http://backloggery.com/lilbud

              1 Reply Last reply Reply Quote 0
              • JasperSladeJ
                JasperSlade
                last edited by

                So far I've done the following:

                Created: sudo nano /bin/connect-bluetooth.sh

                Added the following text:
                #!/bin/bash
                sudo bluetoothctl << EOF
                power on
                connect [MAC Address]
                exit
                EOF

                Made the file executable: sudo chmod +x /bin/connect-bluetooth.sh

                Created a service file: sudo nano /etc/systemd/system/connect-bluetooth.service

                Added the following text:
                [Unit]
                Description=Connect Bluetooth
                [Service]
                Type=oneshot
                ExecStart=/bin/connect-bluetooth.sh
                [Install]
                WantedBy=multi-user.target

                Enabled the service file: sudo systemctl enable /etc/systemd/system/connect-bluetooth.service

                At this point, my gamepad connects at startup flawlessly. When the gamepad powers down, it fails to reconnect.
                I'm hoping that if I add the following text to my connect-bluetooth.sh, it will continually check for my gamepad, and reconnect when needed. Hopefully that is, it looks like the below code is for an older version of RetroPie, one that utilizes bluez, where as my build has bluetoothctl instead

                (#!/bin/bash
                address="XX:XX:XX:XX:XX:XX"
                while (sleep 1)
                do
                connected=$(hidd --show) > /dev/null
                if [[ ! $connected =~ .${address}. ]] ; then
                hidd --connect ${address} > /dev/null 2>&1
                fi
                done)

                ~Jasper

                1 Reply Last reply Reply Quote 0
                • lilbudL
                  lilbud
                  last edited by

                  In /bin/connect-bluetooth.sh, you did put the Mac Address where it says right?

                  Creator of the Radiocade: https://retropie.org.uk/forum/topic/6077/radiocade

                  Backlog: http://backloggery.com/lilbud

                  1 Reply Last reply Reply Quote 0
                  • JasperSladeJ
                    JasperSlade
                    last edited by

                    Yes. 85:55:08:78:17:D1

                    ~Jasper

                    1 Reply Last reply Reply Quote 0
                    • JasperSladeJ
                      JasperSlade
                      last edited by

                      I found my solution. I made the following changes (in bold) to my /bin/connect-bluetooth.sh file.

                      #!/bin/bash
                      while (sleep 30)
                      do
                      sudo bluetoothctl << EOF
                      power on
                      connect [MAC Address]
                      exit
                      EOF
                      done

                      You can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.

                      ~Jasper

                      RionR meleuM 2 Replies Last reply Reply Quote 1
                      • RionR
                        Rion @JasperSlade
                        last edited by Rion

                        @JasperSlade said in Help with script to maintain bluetooth connection:

                        I found my solution. I made the following changes (in bold) to my /bin/connect-bluetooth.sh file.

                        #!/bin/bash
                        while (sleep 30)
                        do
                        sudo bluetoothctl << EOF
                        power on
                        connect [MAC Address]
                        exit
                        EOF
                        done

                        You can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.

                        Nice solution! Could you add this to the wiki page? Setting up a Bluetooth controller

                        FBNeo rom filtering
                        Mame2003 Arcade Bezels
                        Fba Arcade Bezels
                        Fba NeoGeo Bezels

                        herb_fargusH 1 Reply Last reply Reply Quote 0
                        • meleuM
                          meleu @JasperSlade
                          last edited by

                          @JasperSlade said in Help with script to maintain bluetooth connection:

                          You can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.

                          It'll sleep for 30 seconds during the boot?

                          • Useful topics
                          • joystick-selection tool
                          • rpie-art tool
                          • achievements I made
                          1 Reply Last reply Reply Quote 0
                          • herb_fargusH
                            herb_fargus administrators @Rion
                            last edited by

                            @Rion it's a wiki. Anyone can add to it provided the content is valid.

                            If you read the documentation it will answer 99% of your questions: https://retropie.org.uk/docs/

                            Also if you want a solution to your problems read this first: https://retropie.org.uk/forum/topic/3/read-this-first

                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post

                            Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

                            Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.