BleuIO

BleuIO

  • Back to Site
  • Buy Now
  • Manual
  • AT Commands
  • Help

›Python library

Manual

  • How it works
  • How to use
  • Verbose Mode
  • Known Issues
  • Firmware Updates
  • Release History
  • Troubleshooting

AT-Commands

  • List of AT Commands

Scripts & Tutorials

  • Python: iBeacon
  • Python: Eddystone Beacon
  • Python: Scan
  • Python: Scan and Store
  • Python: SPS Script
  • Python: File transfer Script
  • Python: Repeater Script
  • Javascript: Google chrome.serial Beacon
  • C# Console App Example
  • C# WFA Example

Script using libraries

    Python library

    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library
    • SPS example using Python library
    • Security Example using Python library

    JS library

    • Eddystone example using Javascript library
    • IBeacon example using Javascript library
    • Scan example using Javascript library
    • Security Example using Javascript library
    • Get Device Distance

STM32 Example

  • STM32 Example
  • Smart Bulb Example

Arduino Example

  • Arduino Example

Beaglebone Example

  • Beaglebone Example

Build Your Own Firmware

  • Build Your Own Firmware
  • Advertising Example

More

  • Links

Scan example using Python library

Introduction

In this example, we're going to set up the dongle using the following Python script to scan for nearby Bluetooth devices.

from bleuio_lib.bleuio_funcs import BleuIo
from time import sleep

my_dongle = BleuIo()
my_dongle.start_daemon()

print(
    "\nConnected to dongle\n\n" "Welcome to the Bluetooth device Scanning example!\n\n"
)

# Set the dongle in central role
my_dongle.at_central()


user_input = input(
    "Enter:\n"
    '"1" Continuous scan\n'
    '"2" Scan for a limited time\n'
    '"3" Scan a target device\n'
)

if user_input == "1":
    # "Continuous scan" option

    # Start scanning for bluetooth devices
    my_dongle.at_gapscan()
    log = []
    try:
        while True:
            # Fetch response from the dongle
            response = my_dongle.rx_scanning_results
            # Iterate the response for every device found
            for device in response:

                # Add and print the device if its not already found
                if device not in log:
                    print(device)
                    log.append(device)
    except:
        my_dongle.stop_scan()
        exit()

elif user_input == "2":
    # "Scan for a limited time" option
    time_limit = input("Enter time limit(seconds):\n")

    while not time_limit.isdigit():
        time_limit = input("Wrong input please try again")

    print("Scanning..")

    # Starts scan with entered time limit
    my_dongle.at_gapscan(int(time_limit))
    response = my_dongle.rx_scanning_results
    # Prints the result
    for device in response:
        print(device)

elif user_input == "3":
    # "Scan a target device" option

    # Prompting user to enter a device address scanned for
    device_address = input(
        "Enter device type and address:\n" "Example: [0]40:48:FD:E5:2F:A5\n"
    )

    print("Scanning target device: {}".format(device_address))

    # Start scanning for the device
    my_dongle.at_scantarget(device_address)

    user_input = input("Press ENTER to get the result")

    # Stop the scan
    my_dongle.stop_scan()

    # Fetch the result
    devices = my_dongle.rx_scanning_results

    # Print the result
    for device in devices:
        print(device)

    # Stop daemon and exit
    my_dongle.stop_daemon()
    exit()

Full source also available on GitHub.


← IBeacon example using Python libraryScan and store example using Python library →
  • Introduction
Docs
ManualAT CommandsHelp
Community
YouTubeLinkedInFacebook
More
BleuIOSmart Sensor DevicesGitHub
Copyright © 2022 BleuIO. A product of Smart Sensor Devices