Page 1 of 1

Bluetooth Shutter remote

Posted: Wednesday 07 December 2016 22:50
by johnwulp
I got myself a bluetooth IOS/Android shutter remote, and i decided that i won't be using it where it's made for.
Image
I use it now switch my alarm, here are the details.

First pair the remote:

Code: Select all

bluetoothctl
pairable on
scan on
pair 0C:FC:83:72:C9:87
trust 0C:FC:83:72:C9:87
connect 0C:FC:83:72:C9:87
For monitoring the bluetooth buttons (the big and small one) i created a pyhton script thats running in a endless loop. Adjust your button IDX:

Code: Select all

from evdev import InputDevice
from select import select
import time
import json, requests

var = 1

while var == 1:
   try:
      dev = InputDevice('/dev/input/event0')

      while True:
         r,w,x = select([dev], [], [])
         for event in dev.read():
             if event.code == 115:
                if event.value == 1:
                   print("Grote knop")
                   requests.get(url="http://127.0.0.1:8888/json.htm?type=command&param=switchlight&idx=457&switchcmd=On")
             elif event.code == 28:
                if event.value == 1:
                   print("Kleine knop")
                   requests.get(url="http://127.0.0.1:8888/json.htm?type=command&param=switchlight&idx=458&switchcmd=On")
   except:
      time.sleep(5)
The events are mapped to /dev/input/event0 in my case, it could be something else in yours...

Finally i am using supervisor (sudo apt-get install supervisor) to make shure the pyhton script is always started:

Code: Select all

cd /etc/supervisor/conf.d/
sudo nano bluetoothbutton.conf
Adjust the config file to your pyhton script path:

Code: Select all

[program:bluetoothbutton]
command = /usr/bin/python3 /home/pi/scripts/getButton.py
autostart=true
autorestart=true
stdout_logfile = /var/log/bluetoothbutton-stdout.log
stderr_logfile = /var/log/bluetoothbutton-stderr.log
After that reread, and update supervisor

Code: Select all

sudo supervisorctl reread
sudo supervisorctl update
After this the button should work, since it is a push button, i configured this also in domoticz. I'm using the lua script below to actually trigger the security panel. I tried it several ways, but the only thing that seems to work is to use a json call in the lua script.

The seccode value is your security code md5 http://www.miraclesalad.com/webtools/md5.php

Code: Select all

commandArray = {}
if (devicechanged['BluetoothButtonSmall'] == 'On') then
    if(globalvariables['Security'] == 'Disarmed') then
        print('Arm away alarm')
        commandArray['SendNotification']='Alarm#Alarm is armed#0'
        commandArray['OpenURL']='http://127.0.0.1:8888/json.htm?type=command&param=setsecstatus&secstatus=2&seccode=3083202a936b7d0ef8b680d7ae73fa1a' 
    else
        print('Disarm alarm')
        commandArray['SendNotification']='Alarm#Alarm is disabled#0'
        commandArray['OpenURL']='http://127.0.0.1:8888/json.htm?type=command&param=setsecstatus&secstatus=0&seccode=3083202a936b7d0ef8b680d7ae73fa1a' 
    end
commandArray['BluetoothButtonSmall'] = 'Off'
end
return commandArray

Re: Bluetooth Shutter remote

Posted: Monday 17 April 2017 22:06
by dakipro
Thank you for share, I was considering building something similar.
The way I see it, the infinitive loop will occupy bluetooth so that it cannot be used by other applications (presence beacon?).
I have a plant monitor, but I guess generic loop could be made for all apps that need bluetooth, and then programatically use the bluetooth for desired application (based on time or something else)

Re: Bluetooth Shutter remote

Posted: Monday 01 May 2017 14:40
by johnwulp
Hi, i also have Bluetooth presence detection (based on mac address) And this works fine for me with the way i described it in the first post. I do use the raspberry with built-in Bluetooth.

Re: Bluetooth Shutter remote

Posted: Saturday 04 January 2020 4:27
by gabylan
I have tried to connect this tag with a raspberry pi and this is my results:

[bluetooth]# connect 11:22:33:D0:9A:93
Attempting to connect to 11:22:33:D0:9A:93
[CHG] Device 11:22:33:D0:9A:93 Connected: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 11:22:33:D0:9A:93 Connected: no



any ideas?

Re: Bluetooth Shutter remote

Posted: Tuesday 14 February 2023 1:02
by HvdW
Old post, same error.
Are there any people knowing their way in bluetooth connections from the terminal?
I'm trying to connect to screen motors.
Connection seems to work and is then rejected.
Same answers
Connected yes
Connected no

My logic
Connected no
Connected no
What's the deal with that first yes answer.

Is there a good how-to?
I followed the Ubuntu instructions.

Re: Bluetooth Shutter remote

Posted: Friday 17 February 2023 8:44
by lost
HvdW wrote: Tuesday 14 February 2023 1:02 Connection seems to work and is then rejected.
What's your raspberry PI&system version?

PI3B for instance cannot manage flow control control between the SoC & BT chip because lacking IO's. I had timeout issues in the past affecting reliability & had to slow down the speed.

This setup is located in /usr/bin/btuart

I have this line replaced 5 lines before script end:

Code: Select all

		#$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR
		$HCIATTACH /dev/serial1 bcm43xx 460800 noflow - $BDADDR # SPEED DOWN IN NOFLOW MODE !!!
So BT pseudo-serial interface speed is half'ed compared to default setup. This'll of course minimise BT bandwith once up but increase reliability in noflow mode.

Another issue I had in the past (previous raspbian version) was after an update: Looks Debian changed firmware location but the SW loading them on raspberries was not in sync with this change! dmesg was thus showing BT FW load errors.

This issue had huge consequences: Without latest BT FW loaded, the old factory buggy one built-in the BT chip was likely used. And causing lot of issues: Sometimes this was all the PI BT that was silently hung. But more surprising, sometimes this was likely even able to hang the remote side BT stack: I use phones BT as a presence detection & sometimes only smartphones full restart could get their BT working again: Had this with several brands: Samsung, Sony, Nokia... This was occurring after a few hours or even a few days with my usual presence checks periods, but could be triggered quite quickly from a test script doing this almost non-stop: IMO, this PI3B original crappy BT FW would be nice to use... for doing BT DoS! This may depend on PI manufacturing dates indeed, as some FW update was done & may have been included in newer chips golden/factory FW.

At the time I made a symbolic link between old location of firmware files & new one:

Code: Select all

sudo ln -s  /lib/firmware/ /etc/firmware
After a system restart, no more issues.

Re: Bluetooth Shutter remote

Posted: Friday 17 February 2023 11:53
by HvdW
Hi,
Thanks.
RPI3 lite 5.15.30-v7+
However I'll have a look at it.
It's completely new for me.
At the moment just struggling with this
Attempting to connect to 11:22:33:D0:9A:93
[CHG] Device 11:22:33:D0:9A:93 Connected: yes
Failed to connect: org.bluez.Error.Failed
[CHG] Device 11:22:33:D0:9A:93 Connected: no

I'm up to 2 things:
- try the same on my RPI4
- Install a GUI on RPI3 and use the built in BT GUI

The RPI4 is my Domoticz device, my experiments are mostly done on RPI3.

EDIT
So this is what I tried on RPI4
- sudo bluetoothctl
New prompt inside blootoothctl
- power on
- agent on
- default-agent
- scan on
selected a device (a roller screen)
- scan off
and then:

Code: Select all

Discovery stopped
[bluetooth]# trust CF:20:CA:F9:AB:CD
[CHG] Device CF:20:CA:F9:AB:CD Trusted: yes
Changing CF:20:CA:F9:AB:CD trust succeeded
[bluetooth]# pair CF:20:CA:F9:AB:CD
Attempting to pair with CF:20:CA:F9:AB:CD
[CHG] Device CF:20:CA:F9:AB:CD Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device CF:20:CA:F9:AB:CD Connected: no
One step further than: Failed to connect: org.bluez.Error.Failed

When trying to connect to my Sone headphones:

Code: Select all

[bluetooth]# trust CC:98:8B:31:D5:08
[CHG] Device CC:98:8B:31:D5:08 Trusted: yes
Changing CC:98:8B:31:D5:08 trust succeeded
[bluetooth]# pair CC:98:8B:31:D5:08
Attempting to pair with CC:98:8B:31:D5:08
[CHG] Device CC:98:8B:31:D5:08 Connected: yes
[CHG] Device CC:98:8B:31:D5:08 Name: WH-1000XM3
[CHG] Device CC:98:8B:31:D5:08 Alias: WH-1000XM3
[CHG] Device CC:98:8B:31:D5:08 Modalias: usb:v054Cp0CD3d0452
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 00000000-deca-fade-deca-deafdecacaff
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 7b265b0e-2232-4d45-bef4-bb8ae62f813d
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 81c2e72a-0591-443e-a1ff-05f988593351
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 931c7e8a-540f-4686-b798-e8df0a2ad9f7
[CHG] Device CC:98:8B:31:D5:08 UUIDs: 96cc203e-5068-46ad-b32d-e316f5e069ba
[CHG] Device CC:98:8B:31:D5:08 UUIDs: b9b213ce-eeab-49e4-8fd9-aa478ed1b26b
[CHG] Device CC:98:8B:31:D5:08 UUIDs: f8d1fbe4-7966-4334-8024-ff96c9330e15
[CHG] Device CC:98:8B:31:D5:08 ServicesResolved: yes
[CHG] Device CC:98:8B:31:D5:08 Paired: yes
Pairing successful
[CHG] Device CC:98:8B:31:D5:08 ServicesResolved: no
[CHG] Device CC:98:8B:31:D5:08 Connected: no
On RPI3 it shows the same results as in the dump above.

Re: Bluetooth Shutter remote

Posted: Wednesday 22 February 2023 10:08
by lost
HvdW wrote: Friday 17 February 2023 11:53 One step further than: Failed to connect: org.bluez.Error.Failed
That's strange the tag is KO and headphone OK... Looking again in my BT configuration, I have another change in /etc/bluetooth/main.conf:

Code: Select all

ControllerMode = bredr
That's for enhanced data rate as I use phones and original setting was "dual", others also looks possible like "le" (BT low emission used by the tag???).
Maybe you should try several settings there, I don't remember why I changed this on my system: IMO, not a malfunction, most probably for not having BT fiddling with several modes & get better reactivity in finding my phones. So not sure this'll be helpful in your case (if this is the case, this may IMO more be a tag issue than a PI BT one).