The Adafruit_BluefruitLE library used in this guide is deprecated in favor of the Adafruit_Blinka_bleio library. See this guide for more information:

This script will run on a macOS system. It will automatically enable bluetooth and connect to an arduino BLE controller. You will need to have installed the necessary package in the macOS BLE setup page, have created an account and update line #10 of the code below with 'YOUR ADAFRUIT IO KEY'. Please keep the single quotes '  ' around your key.


# BLE Catcher Modified by : Mikey Sklar
# Original Code Credit : Tony DiCola @ Adafruit
# BLE Catcher Modified by : Mikey Sklar @ Adafruit
import Adafruit_BluefruitLE
from import UART

from Adafruit_IO import Client
aio = Client('YOUR ADAFRUIT IO KEY')

# Get the BLE provider for the current platform.
ble = Adafruit_BluefruitLE.get_provider()

# Initialize the BLE system.  MUST be called before other BLE calls!

def main():
    # Clear any cached data because both bluez and CoreBluetooth have issues with
    # caching data and it going stale.

    # Get the first available BLE network adapter and make sure it's powered on.
    adapter = ble.get_default_adapter()
    print('Using adapter: {0}'.format(

    # Disconnect any currently connected UART devices.  Good for cleaning up and
    # starting from a fresh state.
    print('Disconnecting any connected UART devices...')

    # Scan for UART devices.
    print('Searching for UART device...')
        # Search for the first UART device found (will time out after 60 seconds
        # but you can specify an optional timeout_sec parameter to change it).
        device = UART.find_device()
        if device is None:
            raise RuntimeError('Failed to find UART device!')
        # Make sure scanning is stopped before exiting.

    print('Connecting to device...')
    device.connect()  # Will time out after 60 seconds, specify timeout_sec parameter
                      # to change the timeout.

    print('Discovering services...')

    while True:
        uart = UART(device)
        receive  = # 5min timeout

        if receive:
                sd = receive.split(",");
                print("T: " + sd[0] + " H: " + sd[1] + " Li: " + sd[2] + " Lux: " + sd[3] + " N: " + sd[4] + " HR: " + sd[5])

        if len(sd) == 6:
                aio.send('Temperature', sd[0])
                aio.send('Humidity', sd[1])
                aio.send('Light', sd[2])
                aio.send('Lux', sd[3])
                aio.send('Noise', sd[4])
                aio.send('Heart Rate', sd[5])

# Start the mainloop to process BLE events, and run the provided function in
# a background thread.  When the provided main function stops running, returns
# an integer status code, or throws an error the program will exit.

Run the python BLE catcher script on your macOS box in a constant loop to automatically reconnect should a disconnect occur. Use ctrl-\ to break out. 

while true; do python ; done

This guide was first published on Nov 19, 2016. It was last updated on Mar 08, 2024.

This page (macOS Catcher Script) was last updated on Mar 08, 2024.

Text editor powered by tinymce.