3.- Bluetooth settings. Paired. Open channel 22.
Before executing the code we must configure the Bluetooth.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install bluetooth
sudo apt-get install bluez
sudo apt-get install python-bluez
service bluetooth start
service bluetooth status [To quit: Ctrl Z]
sudo bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# discoverable on
[bluetooth]# pairable on
[bluetooth]# scan on
[bluetooth]# pair MAC BLUETOOTH MOBILE
[bluetooth]# paired-devices
bluetooth]# help
[bluetooth]#quit

- The communication will be carried out through channel 22. Observe this line in the bluetooth4.py script:
port = 22
sudo sdptool add --channel=22 SP
sudo sdptool browse local
If you get this error: Failed to connect to SDP server on FF:FF:FF:00:00:00:No such file or directory
open, edit this file:
sudo nano /lib/systemd/system/bluetooth.service
and
add --compat in this line:
ExecStart=/usr/lib/bluetooth/bluetoothd --compat
[Ctrl O to save, Ctrl X to quit]
Summary
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth
[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/lib/bluetooth/bluetoothd --compat
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
ProtectHome=true
ProtectSystem=full
[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
sudo sdptool browse local
channel 22 activated

- To run.
- First run the script with Python2
python2 bluetooth4.py
- Then Click the "Inicio - Start" button in the app.