Bluetooth Low Energy, also referred to as Bluetooth LE or simply BLE, is a new communication protocol similar to classic Bluetooth except that it is designed to consume less power while maintaining comparable functionality. For this reason, Bluetooth LE is the preferred choice of communication with IoT devices that have limited power resources. Starting with Android 4.3, Google introduced built-in support for Bluetooth Low Energy. The BluetoothLE extension requires Android 5.0 or higher to avoid known issues with Google's Bluetooth LE support prior to Android 5.0.
Properties
AdvertiserAddresses
– Returns a list of the addresses of devices found during Advertisement scanning.
AutoReconnect
– If true, the application will attempt to reestablish a lost connection to a device due to link loss (e.g., moving out of range). This will not apply to connections that are disconnected by a call to theDisconnect
method. Such disconnects will need to be reconnected via a call toConnect
orConnectWithAddress
.
ConnectedDeviceName
– The advertised name of the connected device. If no device is connected or Bluetooth low energy is not supported, this will return the empty string.
ConnectionTimeout
– The amount of time, in seconds, that the BluetoothLE component will wait for a connection to be established with a device after a call toConnect
orConnectWithAddress
. If a connection is not established in the given amount of time, the attempt will be aborted and theConnectionFailed
event will be run.
DeviceCharacteristics
– A list of triples, one for each characteristic advertised by the connected device, containing the service UUID, characteristic UUID, and the characteristic's name, if known. The format of the list will be ((service1 characteristic1 name1) (service2 characteristic2 name2) ...). If no device is connected or Bluetooth low energy is not supported, then an empty list will be returned.
DeviceServices
– A list of pairs, one for each advertised service, indicating the service's UUID and its name, if known. The format of the list will be ((uuid1 name1) (uuid2 name2) ...). If no device is connected or Bluetooth low energy is not supported, then an empty list will be returned.
Methods
-
Parameters:
-
Parameters:
deviceName
(text) — The advertised name of the target Bluetooth low energy device.
-
Parameters:
deviceAddress
(text) — The Media Access Control (MAC) address of the target Bluetooth low energy device.
CharacteristicByIndex
– Returns Unique ID of selected characteristic with index. Index specified by list of supported characteristics for a connected device, starting from 1.Parameters:index
(number) — The index of the desired characteristic, which must be between 1 and the length of the characteristic list.
Connect
– Use theConnect
method to connect to a Bluetooth low energy device at the given index in the device list.Parameters:index
(number) — The index of the target device, which must be between 1 and the length of the list.
ConnectWithAddress
– Use theConnectWithAddress
method to connect to a specific Bluetooth low energy device if its Media Access Control (MAC) address is known. If none of the devices in the device list matches the given address, theConnectionFailed
event will be run. Otherwise, if a connection is successful theConnected
event will be run.Parameters:address
(text) — The MAC address of the target device, of the form "12:34:56:78:90:ab"
-
Parameters:
address
(text) — The Media Access Control (MAC) address of the device to disconnect, of the form "12:34:56:78:90:ab"
FoundDeviceAddress
– Gets the Media Access Control (MAC) address of the found device at the given index in the device list. Index specifies the position in the BluetoothLE device list, starting from 1.Parameter:index
(number) — The index of the desired device, which must be between 1 and the length of the device list.
-
Parameter:
index
(number) — The index of the desired device, which must be between 1 and the length of the device list.
FoundDeviceRssi
– Gets the Received Signal Strength Indicator (RSSI) of the found device at the given index. The returned value will be between -100 and 0 indicating the strength of the connection.Parameter:index
(number) — The index of the desired device, which must be between 1 and the length of the device list.
GetCharacteristicsForService
– Returns the list of supported characteristics for the given service. The list will contain (UUID, name) pairs for each characteristic provided by the service UUID.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.
ReadBytes
– Reads one or more 8-bit integer values from a connected BluetoothLE device. Service Unique ID and Characteristic UniqueID are required. Thesigned
parameter indicates whether the bytes should be interpreted as signed values or not when being converted into App Inventor numbers. After the bytes are read, theBytesReceived
event will be run.Parameters:
ReadFloats
– Reads one or more IEEE 754 floating point numbers from a connected BluetoothLE device. Service Unique ID and Characteristic UniqueID are required. TheshortFloat
parameter indicates whether the floats are either 16-bit half-precision floating point or 32-bit single precision floating point numbers. After the floats are read, theFloatsReceived
event will be run.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.shortFloat
(boolean) Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).
ReadIntegers
– Reads one or more 32-bit integer values from a connected BluetoothLE device. Service Unique ID and Characteristic UniqueID are required. Thesigned
parameter indicates whether the integers should be interpreted as signed values or not when being converted into App Inventor numbers. After the integers are read, theIntegersReceived
event will be run.Parameters:
ReadShorts
– Reads one or more 16-bit integer values from a connected BluetoothLE device. Service Unique ID and Characteristic UniqueID are required. Thesigned
parameter indicates whether the shorts should be interpreted as signed values or not when being converted into App Inventor numbers. After the shorts are read, theShortsReceived
event will be run.Parameters:
ReadStrings
– Reads one or more null-terminated strings from a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. Theutf16
parameter indicates whether the content should be decoded as UTF-16 (true) or UTF-8 (false) code points when converting to App Inventor strings. After the strings are read, theStringsReceived
event will be run.Parameters:
RegisterForBytes
– Registers to receive updates when one or more 8-bit integer values from a connected BluetoothLE device are changed. Service Unique ID and Characteristic Unique ID are required. Thesigned
parameter indicates whether the bytes should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theBytesReceived
event will be run.Parameters:
RegisterForFloats
– Registers to receive updates when one or more IEEE 754 floating point numbers from a connected BluetoothLE device are changed. Service Unique ID and Characteristic Unique ID are required. TheshortFloat
parameter indicates whether the floats are either 16-bit half-precision floating point or 32-bit single precision floating point numbers. Whenever a change is received, theFloatsReceived
event will be run.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.shortFloat
(boolean) Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).
RegisterForIntegers
– Registers to receive updates when one or more 32-bit integer values from a connected BluetoothLE device are changed. Service Unique ID and Characteristic Unique ID are required. Thesigned
parameter indicates whether the integers should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theIntegersReceived
event will be run.Parameters:
RegisterForShorts
– Registers to receive updates when one or more 16-bit integer values from a connected BluetoothLE device are changed. Service Unique ID and Characteristic Unique ID are required. Thesigned
parameter indicates whether the shorts should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theShortsReceived
event will be run.Parameters:
RegisterForStrings
– Registers to receive updates when one or more null-terminated strings from a connected BluetoothLE device are changed. Service Unique ID and Characteristic Unique ID are required. Theutf16
parameter indicates whether the content should be decoded as UTF-16 (true) or UTF-8 (false) code points when converting to App Inventor strings. Whenever a change is received, theStringsReceived
event will be run.Parameters:
-
Parameter:
scanPeriod
(number) — The amount of time to spend scanning, in milliseconds.
-
Parameters:
index
(number) — The index of the desired service, which must be between 1 and the length of the service list.
-
Parameters:
StopAdvertising
– Stops Bluetooth low energy advertisement from a previous call toStartAdvertising
.
SupportedCharacteristics
– Returns a list of supported characteristic for the connected device as a string.
-
Parameters:
WriteBytes
– Writes one or more 8-bit integer values to a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -128 and 127. Ifsigned
is false, the acceptable values are between 0 and 255.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the bytes as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteBytesWithResponse
– Writes one or more 8-bit integer values to a connected BluetoothLE device and waits for an acknowledgement via theBytesWritten
event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -128 and 127. Ifsigned
is false, the acceptable values are between 0 and 255.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the bytes as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteFloats
– Writes one or more IEEE 754 floating point numbers to a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. IfshortFloat
is true, then each numeric value will be compressed to fit into a 16-bit half-precision floating point value. IfshortFloat
is false, then each numeric value will be sent as a 32-bit single precision floating point value.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.shortFloat
(boolean) Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).values
(list) — A list of values to write to the device.
WriteFloatsWithResponse
– Writes one or more IEEE 754 floating point values to a connected BluetoothLE device and waits for an acknowledgement via theFloatsWritten
event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. IfshortFloat
is false, then each numeric value will be sent as a 32-bit single precision floating point value.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.shortFloat
(boolean) Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).values
(list) — A list of values to write to the device.
WriteIntegers
– Writes one or more 32-bit integer values to a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -2147483648 and 2147483647. Ifsigned
is false, the acceptable values are between 0 and 4294967295.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the integers as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteIntegersWithResponse
– Writes one or more 32-bit integer values to a connected BluetoothLE device and waits for an acknowledgement via theIntegersWritten
event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -2147483648 and 2147483647. Ifsigned
is false, the acceptable values are between 0 and 4294967295.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the integers as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteShorts
– Writes one or more 16-bit integer values to a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -32768 and 32767. Ifsigned
is false, the acceptable values are between 0 and 65535.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the shorts as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteShortsWithResponse
– Writes one or more 16-bit integer values to a connected BluetoothLE device and waits for an acknowledgement via theShortsWritten
event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsigned
is true, the acceptable values are between -32768 and 32767. Ifsigned
is false, the acceptable values are between 0 and 65535.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.signed
(boolean) Interpret the shorts as signed (true) or unsigned (false).values
(list) — A list of values to write to the device.
WriteStrings
– Writes one or more strings to a connected BluetoothLE device. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single string or a list of strings. Ifutf16
is true, the string(s) will be sent using UTF-16 little endian encoding. Ifutf16
is false, the string(s) will be sent using UTF-8 encoding.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.utf16
(boolean) Send the string encoded as UTF-16 little endian (true) or UTF-8 (false) code points.values
(list) — A list of values to write to the device.
WriteStringsWithResponse
– Writes one or more strings to a connected BluetoothLE device and waits for an acknowledgement via theStringsWritten
event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single string or a list of values. Ifutf16
is true, the string(s) will be sent using UTF-16 little endian encoding. Ifutf16
is false, the string(s) will be sent using UTF-8 encoding.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.utf16
(boolean) Send the string encoded as UTF-16 little endian (true) or UTF-8 (false) code points.values
(list) — A list of values to write to the device.
Events
BytesReceived
– TheBytesReceived
event is run when one or more byte values are received from a connected Bluetooth device. Depending on thesign
parameter of the last call toReadBytes
orRegisterForBytes
for the givenserviceUuid
andcharacteristicUuid
, thebyteValues
list will contain numbers ranging from -128 to 127 (signed = true
) or 0 to 255 (signed = false
).Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.byteValues
(list) — A list of values read from the device. The range of each value will depend on thesign
flag previously specified in the call to read or register.
BytesWritten
– TheBytesWritten
event is run when one or more byte values are written to a connected Bluetooth device.byteValues
will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 23 bytes).Parameters:
Connected
– TheConnected
event is run after the application successfully connects to a Bluetooth low energy device. This can be the result of a call toConnect
orConnectWithAddress
, or as a result of an automatic reconnect if theAutoReconnect
property was true at the time a connection was requested.
ConnectionFailed
– TheConnectionFailed
event is run when an attempt to connect to a device does not succeed. If a reason is provided by the Bluetooth low energy stack it will be reported via thereason
parameter.Parameters:reason
(text) — The reason the connection failed, if known.
Disconnected
– TheDisconnected
event is run when a Bluetooth low energy device is disconnected. This can be caused by a call toDisconnect
orDisconnectWithAddress
, or after a device is moved away or reset such that a loss of connection occurs.
FloatsReceived
– TheFloatsReceived
event is run when one or more IEEE 754 floating point values are received from a connected Bluetooth device. Depending on theshortFloat
parameter of the last call toReadFloats
orRegisterForFloats
for the givenserviceUuid
andcharacteristicUuid
, thefloatValues
list will contain numbers ranging from -65504.0 to 65504.0 (shortFloat = true
) or -3.402823466E38 to 3.402823466E38 (shortFloat = false
).Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.floatValues
(list) — A list of values read from the device. The range of each value will depend on thesign
flag previously specified in the call to read or register.
FloatsWritten
– TheFloatsWritten
event is run when one or more IEEE 754 floating point values are written to a connected Bluetooth device.floatValues
will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 11 short floats or 5 regular floats).Parameters:
IntegersReceived
– TheIntegersReceived
event is run when one or more 32-bit integer values are received from a connected Bluetooth device. Depending on thesign
parameter of the last call toReadIntegers
orRegisterForIntegers
for the givenserviceUuid
andcharacteristicUuid
, theintValues
list will contain numbers ranging from -2147483648 to 2147483647 (signed = true
) or 0 to 4294967296 (signed = false
).Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.intValues
(list) — A list of values read from the device. The range of each value will depend on thesign
flag previously specified in the call to read or register.
IntegersWritten
– TheIntegersWritten
event is run when one or more 32-bit integers values are written to a connected Bluetooth device.intValues
will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 5 integers).Parameters:
RssiChanged
– Trigger event when RSSI (Received Signal Strength Indicator) of found BluetoothLE device changes
ShortsReceived
– TheShortsReceived
event is run when one or more short integer values are received from a connected Bluetooth device. Depending on thesign
parameter of the last call toReadShorts
orRegisterForShorts
for the givenserviceUuid
andcharacteristicUuid
, theshortValues
list will contain numbers ranging from -32768 to 32767 (signed = true
) or 0 to 65535 (signed = false
).Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.shortValues
(list) — A list of values read from the device. The range of each value will depend on thesign
flag previously specified in the call to read or register.
ShortsWritten
– TheShortsWritten
event is run when one or more short integers values are written to a connected Bluetooth device.shortValues
will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 11 shorts).Parameters:
StringsReceived
– TheStringsReceived
event is run when one or more strings are received from a connected Bluetooth device. Depending on theutf16
parameter of the last call toReadStrings
orRegisterForStrings
for the givenserviceUuid
andcharacteristicUuid
, thestringValues
list will contain either a UTF-16 little endian decoded (utf16 = true
) or UTF-8 decoded (utf16 = false
) strings. The string length is limited by the maximum transmission unit (MTU) of the Bluetooth device, which is typically 23 bytes.Parameters:serviceUuid
(text) — The unique identifier of the service passed in the read or register call.characteristicUuid
(text) — The unique identifier of the characteristic in the read or register call.stringValues
(list) — A list of values read from the device. The strings will be decoded as UTF-16 or UTF-8 based on theutf16
flag previously specified in the call to read or register.
StringsWritten
– TheStringsWritten
event is run when one or more strings are written to a connected Bluetooth device.stringValues
will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 22 bytes).Parameters:
WHAT IS INDEX?
답글삭제refer to: http://ai2inventor.blogspot.kr/2017/07/arduino-101-demo-using-grove-kit-for.html
삭제How to "StartAdvertising"?
답글삭제I can't find any advertisement after "StartAdvertising".