• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Automatically wake bluetooth speaker from sleep/suspend

Scheduled Pinned Locked Moved Troubleshooting
16 Posts 5 Posters 3.8k Views 5 Watching
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.
  • S Offline
    Stinger0815
    last edited by Jul 21, 2021, 3:25 PM

    Hello all,
    I’ve finally brought the Google Assistant to live and I’m quite happy with it. However, I’ve a quite practical problem.
    My mirror will typically be used a few times per day but not throughout the whole day. And here comes the problem - I’ve connected a bluetooth sound bar for the audio. This soundbar goes to sleep mode after a couple of minutes without audio used. Unfortunately neither Rasbian nor the smart Mirror by himself will reestablish the suspended bluetooth connection once they want to play audio again - evn though that bluetooth is the “only” available audio output interface.

    Reconnecting the device is quite easy:

    $ bluetoothctl
    $ connect <BLE ID>
    

    So what I’m looking for is a way to either:

    • list itemavoid the sleep with some sort of periodic output?
    • any way to force the system to reconnect / wake the suspended bluetooth connection
    • implement/run a short script once an action on the mirror is performed (could be the PIR - wake, any “OK google” input, the face recognition or anything else that indicates a user presence)

    I would really appreciate any help.

    Thanks :)

    S B 2 Replies Last reply Jul 21, 2021, 3:36 PM Reply Quote 0
    • S Offline
      sdetweil @Stinger0815
      last edited by Jul 21, 2021, 3:36 PM

      @stinger0815 said in Automatically wake bluetooth speaker from sleep/suspend:

      implement/run a short script once an action on the mirror is performed (could be the PIR - wake, any “OK google” input, the face recognition or anything else that indicates a user presence)

      i think you can create a recipe for GA to launch anything on specific words…

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      S 1 Reply Last reply Jul 21, 2021, 3:52 PM Reply Quote 0
      • S Offline
        Stinger0815 @sdetweil
        last edited by Jul 21, 2021, 3:52 PM

        @sdetweil said in Automatically wake bluetooth speaker from sleep/suspend:

        i think you can create a recipe for GA to launch anything on specific words…

        Thanks for the reply, that’s something I actually thought about but wanted to look for “better” options - simply due to the fact that the reconnection takes some time (roughly 5 seconds) and I did not wanted to delay the response or miss parts simply due to the system still booting…

        thanks again!

        S 1 Reply Last reply Jul 21, 2021, 3:54 PM Reply Quote 0
        • S Offline
          sdetweil @Stinger0815
          last edited by Jul 21, 2021, 3:54 PM

          @stinger0815 well, you could add it to the boot sequence too…

          make it a bash script, and call it from boot and GA recipe

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          S 1 Reply Last reply Jul 21, 2021, 3:57 PM Reply Quote 0
          • S Offline
            Stinger0815 @sdetweil
            last edited by Jul 21, 2021, 3:57 PM

            @sdetweil said in Automatically wake bluetooth speaker from sleep/suspend:

            @stinger0815 well, you could add it to the boot sequence too…

            make it a bash script, and call it from boot and GA recipe

            Hey - I actually did not dig into the PIR wake that much and have not implemented it yet, sorry for that. But I thought it is more about switching on the display and not rebooting the whole mirror or am I wrong? If it actually runs over boot this could definitely do the job! I’ll check the module real quick…

            S 1 Reply Last reply Jul 21, 2021, 4:03 PM Reply Quote 0
            • S Offline
              sdetweil @Stinger0815
              last edited by sdetweil Jul 21, 2021, 4:04 PM Jul 21, 2021, 4:03 PM

              @stinger0815 u are the one that mentioned boot…

              and I did not wanted to delay the response or miss parts simply due to the system still booting…

              PIR is turn off/on monitor somehow… (none of them work on my monitors or tvs)

              i don’t know if u can tag along on pir wakeup

              well, YES, you can… on linux ANYTHING is an executable…

              SO, you could make a script named the same as the pgm that GA will call on PIR wakeup

              and inside that script do your thing and then call the original pgm (U will probably have to rename it, or move it a new location) passing the original parms…

              I’ve done this a hundred times over the years…

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              S 1 Reply Last reply Jul 22, 2021, 6:26 AM Reply Quote 0
              • S Offline
                Stinger0815 @sdetweil
                last edited by Jul 22, 2021, 6:26 AM

                @sdetweil said in Automatically wake bluetooth speaker from sleep/suspend:

                SO, you could make a script named the same as the pgm that GA will call on PIR wakeup

                and inside that script do your thing and then call the original pgm (U will probably have to rename it, or move it a new location) passing the original parms…

                I’ve done this a hundred times over the years…

                Sounds pretty good to me - however, here comes the next problem. I’m pretty bad with all kinds of script based + OO languages. My only background is embedded development, so translating what you said sounds a little bit like creating a new callback function and from there calling the original one. BUT how?! :beaming_face_with_smiling_eyes: No, for real, I’ve looked the forum real quick for stuff like “how to invoke small scripts” but was not successful. Do you have by any chance some sort of quick-start guide or any other tutorial to look at? I feel bad for asking as this is nothing really “magic mirror” related rather a basic programming thing - however, still want to give it a try in order to avoid mistakes that could come from the MM structure/architecture.

                Best regards and thanks again

                S 1 Reply Last reply Jul 22, 2021, 12:49 PM Reply Quote 0
                • S Offline
                  sdetweil @Stinger0815
                  last edited by Jul 22, 2021, 12:49 PM

                  @stinger0815 start here
                  https://linuxcommand.org/lc3_wss0010.php

                  but one point the filename does NOT NEED the .sh extension

                  The leap from this topic to my idea is that your ‘script’ can be named the same as the program u wish to run and no one could tell it was your script instead!
                  and your script can call the original program so you don’t have to recreate everything it does

                  path is an important topic here. covered in the linked topic

                  most of this works in windows too

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  S 1 Reply Last reply Jul 22, 2021, 1:46 PM Reply Quote 0
                  • S Offline
                    Stinger0815 @sdetweil
                    last edited by Jul 22, 2021, 1:46 PM

                    @sdetweil said in Automatically wake bluetooth speaker from sleep/suspend:

                    @stinger0815 start here
                    https://linuxcommand.org/lc3_wss0010.php

                    but one point the filename does NOT NEED the .sh extension

                    The leap from this topic to my idea is that your ‘script’ can be named the same as the program u wish to run and no one could tell it was your script instead!
                    and your script can call the original program so you don’t have to recreate everything it does

                    path is an important topic here. covered in the linked topic

                    most of this works in windows too

                    Hey thank you very much! I’ve in the meantime started to look for a hack to get it to work:

                    in the node_helper of the detector module I’ve changed the function that sends the notification once the trigger command is received and added a child_process (from nodejs) there:

                    
                      onDetected: function (from, detected) {
                        this.deactivate()
                    
                        let ble = require('child_process');
                            ble.exec('sh bluetooth_connector.sh',
                                function (error, stdout, stderr) {
                                    console.log('stdout: ' + stdout);
                                    console.log('stderr: ' + stderr);
                                    if (error !== null) {
                                         console.log('exec error: ' + error);
                                    }
                                });
                    
                        this.sendSocketNotification("DETECTED", { from: from, key: detected } )
                      },
                    
                    

                    The script that is called by exec “bluetooth_connector” only contains:

                    #!/bin/bash
                    
                    bluetoothctl \
                    connect <<BLE ADDRESS>>
                    exit
                    

                    pretty hacky but does the job for now. I’ll now try to figure out whether this is actually decoupled enough so that the exec does not block the rest of the application. As I can tell from the logs it looks like the script is decoupled and runs in the background - what is good.

                    So as this is running now I’ll look into the solution you gave.

                    B 1 Reply Last reply Jul 22, 2021, 3:47 PM Reply Quote 0
                    • B Offline
                      bugsounet Banned @Stinger0815
                      last edited by Jul 22, 2021, 3:47 PM

                      (if you think that is the better solution… I will engage you for coding :D)

                      S 1 Reply Last reply Jul 22, 2021, 4:15 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        6/16
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy