最新版拓展下载:
edu.mit.appinventor.ble-20230728.aix
低功耗蓝牙,也称为蓝牙 LE 或简称 BLE,是一种类似于经典蓝牙的新通信协议,不同之处在于它旨在消耗更少的功耗,同时保持可比的功能。
因此,低功耗蓝牙是与耗电资源有限的物联网设备进行通信的首选。BluetoothLE 扩展需要 Android 5.0 或更高版本。
2种通信方式:扫描和广播
扫描
详细接入步骤:
开始扫描 -> 获取BLE设备列表 -> 连接指定设备(也可指定MAC地址连接)-> 设备指定服务uuid和特征uuid 发送 / 接收 数据。
广播
现在常规便宜芯片并无蓝牙协议栈,只能通过人工拼包用最简单的蓝牙广播方式通信,可以做到手机与设备进行简单的交互。
- 无连接的
- 是单向的,可以向任何人或者接收器发送数据。
- 使用广播方式通信没有任何安全措施,任何监听设备都能收到,因此它可能不适合于敏感数据,除非在广播数据中采用某种加密方法。
详细接入步骤:
设置广播扫描周期 -> 广播扫描 -> 获取广播设备列表 -> 获取设备服务uuids列表 -> 设备指定服务uuid 发送 / 接收 广播数据。
更深入的通信原理请参考:《BLE协议—广播和扫描》。
属性
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.
-
NoLocationNeeded
– Enable this option to assert that your app does not use Bluetooth to derive location data. If enabled, ACCESS_FINE_LOCATION permission will not be needed by the compiled app nor will the extension attempt to request permission. -
NullTerminateStrings
– Instructs the BluetoothLE component to terminate strings with a null byte (true) or not (false) when sending string data to a connected device.
方法
Parameters:
* <code>deviceAddress</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The Media Access Control (MAC) address of the target Bluetooth low energy device.
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the advertised service.
Parameters:
* <code>deviceName</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The advertised name of the target Bluetooth low energy device.
Parameters:
* <code>deviceAddress</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The Media Access Control (MAC) address of the target Bluetooth low energy device.
Parameters:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service to test for read capability.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic to test for read capability.
CanRegisterForCharacteristic
– Tests whether the given characteristic can be used to register for notifications.
Parameters:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service to test for notification capability.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic to test for notification capability.
Parameters:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service to test for write capability.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic to test for write capability.
CanWriteCharacteristicWithResponse
– Tests whether the given characteristic can be written with an acknowledgement by the device.
Parameters:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service to test for write with response capability.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic to test for write with response capability.
CharacteristicByIndex
– Returns Unique ID of selected characteristic with index. Index specified by list of supported characteristics for a connected device, starting from 1.
Parameters:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
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:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
The index of the target device, which must be between 1 and the length of the list.
ConnectToDeviceType
– Connects to the first device found advertising with the givenname
and the service UUID associated withdevice
.
Parameters:
device
(component) — A component block that represents a Bluetooth Low Energy devicename
(a href=”“>name</a>) — The name advertised by the desired device,
ConnectToDeviceWithServiceAndName
– Connects to the first device found advertising with the givenname
and the service UUID associated withdevice
.
Parameters:
serviceUuid
(text) — The unique identifier of the service being broadcast by the device(s) of interest.name
(a href=”“>name</a>) — The name advertised by the desired device,
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:
* <code>address</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string" target="_blank">_text_</a>) —
The MAC address of the target device, of the form "12:34:56:78:90:ab"
Parameters:
* <code>address</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string" target="_blank">_text_</a>) —
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:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
The index of the desired device, which must be between 1 and the length of the device list.
Parameter:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
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:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the bytes as signed (true) or unsigned (false).
ReadConnectedRssi
– Initiates a read of the connected device’s Received Signal Strength Indicator (RSSI). The resulting value will be reported via the RssiChanged event.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortFloat</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the integers as signed (true) or unsigned (false).
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the shorts as signed (true) or unsigned (false).
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>utf16</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the string content as UTF-16 (true) or UTF-8 (false) code points.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the bytes as signed (true) or unsigned (false).
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortFloat</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the integers as signed (true) or unsigned (false).
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the shorts as signed (true) or unsigned (false).
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>utf16</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the string content as UTF-16 (true) or UTF-8 (false) code points.
RequestMTU
– Requests a new minimum transmission unit (MUT) for the BluetoothLE connection. This feature is only supported when both devices support Bluetooth 4.2 or higher. If the MTU is changed successfully, the MTUChanged event will be run. The default MTU is 20.
This block is intended for advanced apps that need to change the size of the messages sent between the BLE devices. Most developers will not need to adjust this value.
Parameters:
bytes
(number) — The desired MTU size.
Parameter:
* <code>scanPeriod</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
The amount of time to spend scanning, in milliseconds.
ScanForDevice
– Scans for a particular type of device. The device component must implement the BLEDevice interface in order for this method to work.
Parameters:
param
(component) — A component block that expects a particular service.
Parameters:
serviceUuid
(text) — The unique identifier of the service being broadcast by the device(s) of interest.
Parameters:
* <code>index</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/math.html#number">_number_</a>) —
The index of the desired service, which must be between 1 and the length of the service list.
Parameters:
* <code>inData</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The data to be included in the service advertisement.
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the bytes as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the bytes as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortFloat</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortFloat</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the floats as 16-bit half-precision (true) or 32-bit single-precision (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the integers as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the integers as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the shorts as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>signed</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Interpret the shorts as signed (true) or unsigned (false).
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>utf16</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Send the string encoded as UTF-16 little endian (true) or UTF-8 (false) code points.
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>utf16</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/logic.html#true" target="_blank">_boolean_</a>)
Send the string encoded as UTF-16 little endian (true) or UTF-8 (false) code points.
* <code>values</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values to write to the device.
事件
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>byteValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/listsU.html#makealist">_list_</a>) —
A list of values read from the device. The range of each value will depend on the <code>sign</code> 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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>byteValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values written to the device.
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:
* <code>reason</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string" target="_blank">_text_</a>) —
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>floatValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values read from the device. The range of each value will depend on the <code>sign</code> 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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>floatValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values written to the device.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>intValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values read from the device. The range of each value will depend on the <code>sign</code> 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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>intValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values written to the device.
MTUChanged
– The MTUChanged event is run when the two BluetoothLE devices have successfully changed their maximum transmission unit (MTU) to a different value. This event will only run in response to a call to the method block RequestMTU.
Parameters:
bytes
(number) — The new size, in bytes, of the new MTU.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values read from the device. The range of each value will depend on the <code>sign</code> 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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>shortValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values written to the device.
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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>stringValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values read from the device. The strings will be decoded as UTF-16 or UTF-8 based on the <code>utf16</code> 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:
* <code>serviceUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the service passed in the read or register call.
* <code>characteristicUuid</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/text.html#string">_text_</a>) —
The unique identifier of the characteristic in the read or register call.
* <code>stringValues</code> (<a href="http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html#makealist">_list_</a>) —
A list of values written to the device.
官方英文原版文档点此。