I have two RPi3 operating on Jessie OS distribution and I have already Bluez and Blueman in both of them. I want to be able to send string from one to another. To do so, I have used the Bluez scripts of client server from this blog: http://blog.kevindoran.co/bluetooth-programming-with-python-3/ To determine the mac address of each one of them for my bluetooth connection I have typed in the terminal:
and then I have picked the address labelled: default. This setup was working and I was able to send string between the two boards but since yesterday the system stopped working and I am always getting the following error message:
bluetooth.btcommon.BluetoothError: (111, 'Connection refused')
The pairing is established and the connection establishes for just a small amount of time and then they get disconnected.
Those are the client-server scripts of Bluez taking from the mentioned blog:
""" A simple Python script to send messages to a sever over Bluetooth using PyBluez (with Python 2). """ import bluetooth serverMACAddress = 'xx:xx:xx:xx:xx:xx' port = 3 s = bluetooth.BluetoothSocket(bluetooth.RFCOMM) s.connect((serverMACAddress, port)) while 1: text = raw_input() # Note change to the old (Python 2) raw_input if text == "quit": break s.send(text) sock.close()
""" A simple Python script to receive messages from a client over Bluetooth using PyBluez (with Python 2). """ import bluetooth hostMACAddress = 'xx:xx:xx:xx:xx:xx' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters. port = 3 backlog = 1 size = 1024 s = bluetooth.BluetoothSocket(bluetooth.RFCOMM) s.bind((hostMACAddress, port)) s.listen(backlog) try: client, clientInfo = s.accept() while 1: data = client.recv(size) if data: print(data) client.send(data) # Echo back to client except: print("Closing socket") client.close() s.close()