I would like to create a code in python 3 on my Raspberry PI 3 which will aim to read frames of bytes sent from a pc that uses a Bluetooth dongle, by my RPI using its built-in Bluetooth (a kind of client server in Bluetooth)
So I did several research, but I can not even do a good test to see if my Bluetooth works, the Bluetooth RPI works fine in command lines (bluetoothctl), but the code test does not work and I receive an error: here is the code:
Code: Select all
#!/usr/bin/env python # -*- coding: UTF-8 -*- import bluetooth from random import randint bd_addr = "XX:XX:XX:XX:XX:XX" #j'ai mis l'add mac du raspberry que j'ai pris avec la la ligne de commande (bluetoothctl) port = 1 sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) sock.connect((bd_addr, port)) rnd = randint(1,3) toSend = "profil:%d" % rnd sock.send(toSend) data = sock.recv(1024) print "received [%s]" % data sock.close()
sock.connect ((bd_addr, port))
File "<string>", line 5, in connect
bluetooth.btcommon.BluetoothError: (113, 'No route to host')
Indications on the error?
Indications (tutorials, documentation, codes, ...) on the code I want to create?