Read the statement by Michael Teeuw here.
Automatically wake bluetooth speaker from sleep/suspend
-
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 :)
-
@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…
-
@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!
-
@stinger0815 well, you could add it to the boot sequence too…
make it a bash script, and call it from boot and GA recipe
-
@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…
-
@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…
-
@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
-
@stinger0815 start here
https://linuxcommand.org/lc3_wss0010.phpbut 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 doespath is an important topic here. covered in the linked topic
most of this works in windows too
-
@sdetweil said in Automatically wake bluetooth speaker from sleep/suspend:
@stinger0815 start here
https://linuxcommand.org/lc3_wss0010.phpbut 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 doespath 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.
-
(if you think that is the better solution… I will engage you for coding :D)