0

I am trying to automatically bind/pair (not connect) an ePuck robot with Linux using a bash script. I researched a lot about bluetoothctl but found nothing really useful. The problem is that the ePuck uses a fixed pin, so I have to manually type the pin every time I want to bind/pair it (I remove/unpair the ePuck every time after I finished my work that's why I have to reenter the pin every time).

It shouldn't nessesserly be a bashscript. I've heard that I could make it with python too. But I'am new at Linux and coding so that's why I'm asking.

This is what I have so far (2228 is the pin of the ePuck):

#!/bin/bash

##first tried with EOF
bluetoothctl <<EOF
power on
agnet on
scan on
pair 10:00:E8:AD:77:31
2228
EOF

##then with echo -e
echo -e 'power on\nagent on\nscan on\npair 10:00:E8:AD:77:31\n2228\n' | bluetoothctl 

I don't know exactly how to use EOF or echo -e but I have this solutions out of the internet. In both ways no pairing has been done. It seems like bluetoothctl is quit too quickly.

farhad94
  • 1
  • 2

1 Answers1

0

bluetoothctl interface might not be handy for your use case. You can try the following dbus-send commands (Not tested, but this should work).

dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set string:"org.bluez.Adapter1" string:"Powered" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Properties.Set string:"org.bluez.Adapter1" string:"Discoverable" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter1.StartDiscovery
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.freedesktop.DBus.Properties.Set string:"org.bluez.Device1" string:"Trusted" variant:boolean:true
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.bluez.Device1.Pair
dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0/dev_10_00_E8_AD_77_31 org.bluez.Device1.Connect

There is no need to start the bluetooth daemon service if it is socket activatable in bluetooth.service.

To answer the key over dbus, you may also need to register default agent or external agent manager to reply.

dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/hci0 org.bluez.AgentManager1.RegisterAgent
Parthiban
  • 2,130
  • 2
  • 14
  • 27