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 theDisconnectmethod. Such disconnects will need to be reconnected via a call toConnectorConnectWithAddress.
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 toConnectorConnectWithAddress. If a connection is not established in the given amount of time, the attempt will be aborted and theConnectionFailedevent 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 theConnectmethod 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 theConnectWithAddressmethod 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, theConnectionFailedevent will be run. Otherwise, if a connection is successful theConnectedevent 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. Thesignedparameter indicates whether the bytes should be interpreted as signed values or not when being converted into App Inventor numbers. After the bytes are read, theBytesReceivedevent 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. TheshortFloatparameter 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, theFloatsReceivedevent 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. Thesignedparameter indicates whether the integers should be interpreted as signed values or not when being converted into App Inventor numbers. After the integers are read, theIntegersReceivedevent 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. Thesignedparameter indicates whether the shorts should be interpreted as signed values or not when being converted into App Inventor numbers. After the shorts are read, theShortsReceivedevent 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. Theutf16parameter 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, theStringsReceivedevent 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. Thesignedparameter indicates whether the bytes should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theBytesReceivedevent 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. TheshortFloatparameter 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, theFloatsReceivedevent 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. Thesignedparameter indicates whether the integers should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theIntegersReceivedevent 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. Thesignedparameter indicates whether the shorts should be interpreted as signed values or not when being converted into App Inventor numbers. Whenever a change is received, theShortsReceivedevent 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. Theutf16parameter 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, theStringsReceivedevent 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. Ifsignedis true, the acceptable values are between -128 and 127. Ifsignedis 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 theBytesWrittenevent. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsignedis true, the acceptable values are between -128 and 127. Ifsignedis 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. IfshortFloatis true, then each numeric value will be compressed to fit into a 16-bit half-precision floating point value. IfshortFloatis 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 theFloatsWrittenevent. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. IfshortFloatis 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. Ifsignedis true, the acceptable values are between -2147483648 and 2147483647. Ifsignedis 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 theIntegersWrittenevent. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsignedis true, the acceptable values are between -2147483648 and 2147483647. Ifsignedis 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. Ifsignedis true, the acceptable values are between -32768 and 32767. Ifsignedis 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 theShortsWrittenevent. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single numeric value or a list of values. Ifsignedis true, the acceptable values are between -32768 and 32767. Ifsignedis 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. Ifutf16is true, the string(s) will be sent using UTF-16 little endian encoding. Ifutf16is 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 theStringsWrittenevent. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single string or a list of values. Ifutf16is true, the string(s) will be sent using UTF-16 little endian encoding. Ifutf16is 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– TheBytesReceivedevent is run when one or more byte values are received from a connected Bluetooth device. Depending on thesignparameter of the last call toReadBytesorRegisterForBytesfor the givenserviceUuidandcharacteristicUuid, thebyteValueslist 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 thesignflag previously specified in the call to read or register.
BytesWritten– TheBytesWrittenevent is run when one or more byte values are written to a connected Bluetooth device.byteValueswill 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– TheConnectedevent is run after the application successfully connects to a Bluetooth low energy device. This can be the result of a call toConnectorConnectWithAddress, or as a result of an automatic reconnect if theAutoReconnectproperty was true at the time a connection was requested.
ConnectionFailed– TheConnectionFailedevent 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 thereasonparameter.Parameters:reason(text) — The reason the connection failed, if known.
Disconnected– TheDisconnectedevent is run when a Bluetooth low energy device is disconnected. This can be caused by a call toDisconnectorDisconnectWithAddress, or after a device is moved away or reset such that a loss of connection occurs.
FloatsReceived– TheFloatsReceivedevent is run when one or more IEEE 754 floating point values are received from a connected Bluetooth device. Depending on theshortFloatparameter of the last call toReadFloatsorRegisterForFloatsfor the givenserviceUuidandcharacteristicUuid, thefloatValueslist 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 thesignflag previously specified in the call to read or register.
FloatsWritten– TheFloatsWrittenevent is run when one or more IEEE 754 floating point values are written to a connected Bluetooth device.floatValueswill 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– TheIntegersReceivedevent is run when one or more 32-bit integer values are received from a connected Bluetooth device. Depending on thesignparameter of the last call toReadIntegersorRegisterForIntegersfor the givenserviceUuidandcharacteristicUuid, theintValueslist 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 thesignflag previously specified in the call to read or register.
IntegersWritten– TheIntegersWrittenevent is run when one or more 32-bit integers values are written to a connected Bluetooth device.intValueswill 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– TheShortsReceivedevent is run when one or more short integer values are received from a connected Bluetooth device. Depending on thesignparameter of the last call toReadShortsorRegisterForShortsfor the givenserviceUuidandcharacteristicUuid, theshortValueslist 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 thesignflag previously specified in the call to read or register.
ShortsWritten– TheShortsWrittenevent is run when one or more short integers values are written to a connected Bluetooth device.shortValueswill 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– TheStringsReceivedevent is run when one or more strings are received from a connected Bluetooth device. Depending on theutf16parameter of the last call toReadStringsorRegisterForStringsfor the givenserviceUuidandcharacteristicUuid, thestringValueslist 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 theutf16flag previously specified in the call to read or register.
StringsWritten– TheStringsWrittenevent is run when one or more strings are written to a connected Bluetooth device.stringValueswill 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".