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 4.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 @sdetweil
      last edited by

      @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 Reply Quote 0
      • S Do not disturb
        sdetweil @Stinger0815
        last edited by sdetweil

        @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 Reply Quote 0
        • S Offline
          Stinger0815 @sdetweil
          last edited by

          @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 Reply Quote 0
          • S Do not disturb
            sdetweil @Stinger0815
            last edited by

            @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 Reply Quote 0
            • S Offline
              Stinger0815 @sdetweil
              last edited by

              @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.

              bugsounetB 1 Reply Last reply Reply Quote 0
              • bugsounetB Offline
                bugsounet Banned @Stinger0815
                last edited by

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

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  Stinger0815 @bugsounet
                  last edited by

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

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

                  :face_with_hand_over_mouth:

                  It’s certainly not a perfect solution - I have to add that every time there is an update in the detector helper - ohh, surprise, there is an update in the detector module :D

                  bugsounetB 1 Reply Last reply Reply Quote 0
                  • bugsounetB Offline
                    bugsounet Banned @Stinger0815
                    last edited by

                    @stinger0815

                    humm…
                    i’m so kind today … so try v3.0.4 of GA with this recipe:

                    var recipe = {
                      commands: {
                        "Bluetooth": {
                          shellExec: {
                            exec: (params) => {
                              if (params.notification == "GA_ACTIVATE") return "bluetooth_connector.sh"
                              else return null
                            }
                          }
                        }
                      },
                      plugins: {
                        onNotificationReceived: "Bluetooth"
                      },
                    }
                    
                    exports.recipe = recipe
                    

                    Note maybe you have to add path in the return value example /home/pi/bla/bla/bluetooth_connector.sh

                    S 1 Reply Last reply Reply Quote 0
                    • S Offline
                      Stinger0815 @bugsounet
                      last edited by

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

                      @stinger0815

                      humm…
                      i’m so kind today … so try v3.0.4 of GA with this recipe:

                      var recipe = {
                        commands: {
                      [...]
                      
                      Note maybe you have to add path in the return value example `/home/pi/bla/bla/bluetooth_connector.sh`
                      

                      That’s pretty sweet and works fine :) Thank you very much!

                      bugsounetB 1 Reply Last reply Reply Quote 0
                      • bugsounetB Offline
                        bugsounet Banned @Stinger0815
                        last edited by

                        that i says: i’m so kind today

                        because i offer no help there, so today you have a lot of chance :)

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          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