Python Forum
Connect to HC-05 Bluetooth (NOT BLE)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connect to HC-05 Bluetooth (NOT BLE)
#1
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 ?

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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Read data via bluetooth frohr 9 3,422 Jul-10-2022, 09:51 AM
Last Post: frohr
  Read buffer from bluetooth frohr 2 2,158 Jun-01-2022, 01:31 PM
Last Post: frohr
  Scan for Bluetooth device korenron 0 2,630 Jan-10-2022, 01:06 PM
Last Post: korenron
  Sending string commands from Python to a bluetooth device Rovelin 13 9,531 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  ModuleNotFoundError: No module named 'bluetooth' Error Rovelin 4 12,210 Aug-31-2021, 04:04 PM
Last Post: Rovelin
  Bluetooth send message after connecting? korenron 2 2,682 Apr-26-2021, 05:50 AM
Last Post: korenron
  Bluetooth problem Lad 0 1,905 Sep-24-2020, 07:26 PM
Last Post: Lad
  bluetooth device inquiry anne 0 2,347 Aug-01-2020, 12:24 AM
Last Post: anne
  Reading Smartphone Battery Level via Bluetooth maxwell 1 2,191 Jun-17-2020, 12:48 AM
Last Post: Larz60+
  Access phone via Bluetooth maxwell 2 2,293 Jun-03-2020, 05:22 PM
Last Post: maxwell

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020