Find Your Bluetooth Low Energy Peripheral Devices
You can see a list of nearby Bluetooth® Low Energy peripheral devices using blelist
. After
you identify your device on the list, you can establish a connection to it from MATLAB® using ble
.
Scan for Devices
Scan for Bluetooth Low Energy peripheral devices from MATLAB using blelist
. This
function lists all nearby peripheral devices that are advertising data. You can view the
advertisement data for each device in MATLAB to determine whether it is connectable. If your device does not appear in the
list, make sure it is powered on, nearby, and disconnected from any other devices or
applications. Then scan for it again.
list = blelist
list=5×5 table Index Name Address RSSI Advertisement _____ __________________ ______________ ____ _____________ 1 "Gear Fit2 (E16A)" "8498663EE16A" -54 [1×1 struct] 2 "" "2C4D2724754D" -69 [1×1 struct] 3 "" "1B75E09FD18F" -70 [1×1 struct] 4 "" "4F7D6DAF9FCE" -75 [1×1 struct] 5 "" "7B8ADB5851BD" -76 [1×1 struct]
Devices are sorted by RSSI, which represents signal strength. If there are several
devices listed, use the Name
field to identify your device.
The advertisement data for each device contains data defined in the Generic Access
Profile (GAP) by Bluetooth SIG. The Type
field in the advertisement data
Advertisement
shows the connection status. View advertisement data of
the first device.
list.Advertisement(1)
ans = struct with fields: Type: ["Connectable Undirected" "Scan Response"] Appearance: "Generic Watch" ShortenedLocalName: [] CompleteLocalName: "Gear Fit2 (E16A)" TxPowerLevel: [] SlaveConnectionIntervalRange: [] ManufacturerSpecificData: [0 117 1 0 2 0 1 3 0] ServiceData: [] CompleteServiceUUIDs: [] IncompleteServiceUUIDs: [] ServiceSolicitationUUIDs: []
Scan for Devices by Name
You can use name-value pair arguments to list only devices with a particular name.
For example, list all peripheral devices with names starting with the string
"UA"
.
list = blelist("Name","UA")
list=2×5 table Index Name Address RSSI Advertisement _____ ___________________ ______________ ____ _____________ 1 "UA E39 MODULE" "84DD20E39AB6" -84 [1×1 struct] 2 "UA Footpod 239AE2" "0CF3EE239AE2" -87 [1×1 struct]
Scan for Devices by Service Name or UUID
For devices that are advertising services, you can use name-value pair arguments to list only devices with the specified service. Service name and service UUID are both valid.
For example, list all peripheral devices that advertise the Heart
Rate
service.
list = blelist("Services","Heart Rate")
list=1×5 table Index Name Address RSSI Advertisement _____ ___________________ ______________ ____ _____________ 1 "UA E39 MODULE" "84DD20E39AB6" -84 [1×1 struct]
Scan for Longer Time
You can increase the amount of time MATLAB scans for nearby devices. This is useful if your device has a high advertising interval and does not appear in the list with the default timeout value of three seconds.
list = blelist("Timeout",10);
Connect to a Device
After you discover your device, establish a connection between MATLAB and the peripheral device using ble
. Specify
the device name or address from the blelist
output.
b = ble("Gear Fit2 (E16A)")
b = ble with properties: Name: "Gear Fit2 (E16A)" Address: "8498663EE16A" Connected: 1 Services: [2×2 table] Characteristics: [3×5 table] Show services and characteristics
After creating a connection to your device, you can work with the
Characteristics
listed in the ble
properties. See
Work with Device Characteristics and Descriptors for more information
and next steps.