Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bluetooth device inquiry
#1
Two "inquiry " - scan for nearby bluetooth devices and two different results.

Where is the logical error in the first usage of function
bluetooth.discover_devices ?

inquiry is basins BlueZ function and it takes time , which the first code does not monitors.
Is that it ?

I am asking for second opinion.

CODE
import bluetooth

print("scanning for near-by bluetooth devices....")

target_name = "My Phone"
target_address = None

nearby_devices = bluetooth.discover_devices()

for bdaddr in nearby_devices:
    if target_name == bluetooth.lookup_name( bdaddr ):
        target_address = bdaddr
        break

if target_address is not None:
    print ("found target bluetooth device with address "), target_address
else:
    print ("could not find target bluetooth device nearby")


import bluetooth 

print("Performing inquiry...")

nearby_devices = bluetooth.discover_devices(duration=8, lookup_names=True,
                                            flush_cache=True, lookup_class=False)

print("Found {} devices".format(len(nearby_devices)))

for addr, name in nearby_devices:
    try:
        print("   {} - {}".format(addr, name))
    except UnicodeEncodeError:
        print("   {} - {}".format(addr, name.encode("utf-8", "replace")))
Output

Quote:scanning for near-by bluetooth devices....
could not find target bluetooth device nearby
Performing inquiry...
Found 2 devices
98:D3:31:F8:39:33 - SPP-CA
B8:27:EB:11:3F:82 - ARM
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Read data via bluetooth frohr 9 3,401 Jul-10-2022, 09:51 AM
Last Post: frohr
  Connect to HC-05 Bluetooth (NOT BLE) korenron 0 1,473 Jun-26-2022, 09:06 AM
Last Post: korenron
  Read buffer from bluetooth frohr 2 2,148 Jun-01-2022, 01:31 PM
Last Post: frohr
  Scan for Bluetooth device korenron 0 2,627 Jan-10-2022, 01:06 PM
Last Post: korenron
  Sending string commands from Python to a bluetooth device Rovelin 13 9,487 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  ModuleNotFoundError: No module named 'bluetooth' Error Rovelin 4 12,179 Aug-31-2021, 04:04 PM
Last Post: Rovelin
  Bluetooth send message after connecting? korenron 2 2,677 Apr-26-2021, 05:50 AM
Last Post: korenron
  Bluetooth problem Lad 0 1,902 Sep-24-2020, 07:26 PM
Last Post: Lad
  Reading Smartphone Battery Level via Bluetooth maxwell 1 2,187 Jun-17-2020, 12:48 AM
Last Post: Larz60+
  Access phone via Bluetooth maxwell 2 2,286 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