Jun-26-2022, 09:06 AM
Hello,
I'm trying to connect to a HC05 Bluetooth and send it "0"\"1"
in the scan I can see the device , but I'm unable to connect to it
when I try to connect to to it from my android phone - he ask me for a PIN numner
what am I missing in the code so we will ask me for PIN number also ? then I will be able to connect and send the wanted message ?
I'm trying to connect to a HC05 Bluetooth and send it "0"\"1"
in the scan I can see the device , but I'm unable to connect to it
when I try to connect to to it from my android phone - he ask me for a PIN numner
what am I missing in the code so we will ask me for PIN number also ? then I will be able to connect and send the wanted message ?
import bluetooth, subprocess
#import socket
name = 'HC-05' # Device name
addr = '98:D3:C5:B1:7D:AA' # Device Address
port = 1 # RFCOMM port
passkey = "1234" # passkey of the device you want to connect
nearby_devices = bluetooth.discover_devices(duration=1, lookup_names=True)
print('found %d devices' %len(nearby_devices))
for addr, name in nearby_devices:
print(' %s - %s' %(addr, name))
# Now, connect in the same way as always with PyBlueZ
try:
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((addr,port))
except bluetooth.btcommon.BluetoothError as err:
print(err)
pass
else:
s.send("1")
