danny88o
Posts: 1
Joined: Tue Aug 27, 2019 1:48 pm

Python Bluetooth module isnt functioning correctly

Tue Aug 27, 2019 2:28 pm

I'm trying to connect my phone (Huawei P9 Lite) to my Raspberry Pi zero w to control the GPIO pins wirelessly.

Code: Select all

import bluetooth


port = 1
server_socket = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
server_socket.bind(("", port))
server_socket.listen(1)

client_socket, address = server_socket.accept()
print(str(address))

data = client_socket.recv(1024)
However running that code it seems to get stuck on:

Code: Select all

client_socket, address = server_socket.accept()
- the program runs forever and I can't work out why.

My phone is paired and I have tried running the program when it is connected and when it is not but nothing seems to work.
I have my pi up to date and all relevant modules installed (python-bluetooth, bluez, etc.) .

A beginner so any help is greatly appreciated!

User avatar
MrYsLab
Posts: 372
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Python Bluetooth module isnt functioning correctly

Wed Aug 28, 2019 12:41 pm

Pairing is only half of the story, your phone also needs an application to connect to the RPi. If you would like to see an example of configuring the RPi for Bluetooth operation, please take a look at: https://mryslab.github.io/bots-in-piece ... art-2.html

And for the phone side, take a look at: https://mryslab.github.io/bots-in-piece ... art-3.html

Return to “Python”