import Vnmf from '../../index' declare module '../../index' { namespace writeBLECharacteristicValue { interface Promised extends VnmfGeneral.BluetoothError { /** success :ok,mistake :details */ errMsg: string } interface Option { /** Bluetooth characteristic uuid */ characteristicId: string /** Bluetooth equipment id */ deviceId: string /** Bluetooth feature value corresponds to service uuid */ serviceId: string /** Binary value corresponding to the characteristic value of Bluetooth equipment */ value: ArrayBuffer /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: VnmfGeneral.BluetoothError) => void } } namespace setBLEMTU { type Promised = FailCallbackResult | SuccessCallbackResult interface Option { /** Bluetooth equipment id */ deviceId: string /** Maximum transmission unit 。The setting range is (22,512) Interval ,unit bytes */ mtu: number /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: Promised) => void /** Interface call failure recovery function */ fail?: (res: FailCallbackResult) => void /** Interface call successful callback function */ success?: (res: SuccessCallbackResult) => void } interface FailCallbackResult extends VnmfGeneral.BluetoothError { /** Final negotiation MTU value 。If the negotiation fails, there is no parameter 。Android client 8.0.9 Start support 。 */ mtu: string } interface SuccessCallbackResult extends VnmfGeneral.BluetoothError { /** Final negotiation MTU value ,Like the passing parameter 。Android client 8.0.9 Start support 。 */ mtu: string } } namespace readBLECharacteristicValue { interface Option { /** Bluetooth characteristic uuid */ characteristicId: string /** Bluetooth equipment id */ deviceId: string /** Bluetooth feature value corresponds to service uuid */ serviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: VnmfGeneral.BluetoothError) => void } } namespace onBLEMTUChange { interface CallbackResult { /** Bluetooth equipment ID */ deviceId: string /** Maximum transmission unit */ mtu: string } /** The recovery function of the largest transmission unit of Bluetooth low power consumption */ type Callback = ( result: CallbackResult, ) => void } namespace onBLEConnectionStateChange { interface CallbackResult { /** Whether it is in a connected state */ connected: boolean /** Bluetooth equipment ID */ deviceId: string } /** Low -power Bluetooth connection state changes to the event callback function */ type Callback = ( result: CallbackResult, ) => void } namespace onBLECharacteristicValueChange { /** The recovery function of the characteristic value change event of the low -power Bluetooth equipment */ type Callback = ( result: CallbackResult, ) => void interface CallbackResult { /** Bluetooth characteristic uuid */ characteristicId: string /** Bluetooth equipment id */ deviceId: string /** Bluetooth feature value corresponds to service uuid */ serviceId: string /** The latest value of feature value */ value: ArrayBuffer } } namespace notifyBLECharacteristicValueChange { interface Promised extends VnmfGeneral.BluetoothError { /** success :ok,mistake :details */ errMsg: string } interface Option { /** Bluetooth characteristic uuid */ characteristicId: string /** Bluetooth equipment id */ deviceId: string /** Bluetooth feature value corresponds to service uuid */ serviceId: string /** Whether to enable notify */ state: boolean /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: VnmfGeneral.BluetoothError) => void } } namespace getBLEMTU { interface Option { /** Bluetooth equipment id */ deviceId: string /** Writing mode (iOS Unique parameter ) * @default "write" */ writeType: keyof WriteType /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: ( result: SuccessCallbackResult, ) => void } interface SuccessCallbackResult extends VnmfGeneral.BluetoothError { /** Maximum transmission unit */ mtu: number } /** The legal value of the writing pattern */ interface WriteType { /** Have a reply to write */ write /** No reply */ writeNoResponse } } namespace getBLEDeviceServices { interface Option { /** Bluetooth equipment id */ deviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: ( result: SuccessCallbackResult, ) => void } interface SuccessCallbackResult extends VnmfGeneral.BluetoothError { /** List of equipment service */ services: BLEService[] /** success :ok,mistake :details */ errMsg: string } /** List of equipment service */ interface BLEService { /** Whether the service is the main service */ isPrimary: boolean /** Bluetooth equipment service uuid */ uuid: string } } namespace getBLEDeviceRSSI { interface Option { /** Bluetooth equipment id */ deviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: ( result: SuccessCallbackResult, ) => void } interface SuccessCallbackResult extends VnmfGeneral.BluetoothError { /** Signal intensity ,unit dBm */ RSSI: number } } namespace getBLEDeviceCharacteristics { interface Option { /** Bluetooth equipment id */ deviceId: string /** Bluetooth service uuid,Need to use `getBLEDeviceServices` Obtain */ serviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: SuccessCallbackResult) => void } interface SuccessCallbackResult extends VnmfGeneral.BluetoothError { /** Equipment feature value list */ characteristics: BLECharacteristic[] /** success :ok,mistake :details */ errMsg: string } /** Equipment feature value list */ interface BLECharacteristic { /** Operation type supported by this feature value */ properties: Properties /** Bluetooth equipment feature value uuid */ uuid: string } /** Operation type supported by this feature value */ interface Properties { /** Does this feature value support indicate operate */ indicate: boolean /** Does this feature value support notify operate */ notify: boolean /** Does this feature value support read operate */ read: boolean /** Does this feature value support write operate */ write: boolean } } namespace createBLEConnection { interface Promised extends VnmfGeneral.BluetoothError { /** success :ok,mistake :details */ errMsg: string } interface Option { /** Used to distinguish equipment id */ deviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: VnmfGeneral.BluetoothError) => void /** overtime time ,unit ms,If you don't fill it out, it will not take timeout */ timeout?: number } } namespace closeBLEConnection { interface Promised extends VnmfGeneral.BluetoothError { /** success :ok,mistake :details */ errMsg: string } interface Option { /** Used to distinguish equipment id */ deviceId: string /** The callback function of the interface call (Call success 、Failure will be executed ) */ complete?: (res: VnmfGeneral.BluetoothError) => void /** Interface call failure recovery function */ fail?: (res: VnmfGeneral.BluetoothError) => void /** Interface call successful callback function */ success?: (res: VnmfGeneral.BluetoothError) => void } } interface VnmfStatic { /** Write binary data to low -power Bluetooth equipment feature values 。Notice :The feature value support of the device write Only to successfully call 。 * * **Notice ** * - There will be many times the possibility of writing failure in parallel adjustment 。 * - The applet will not restrict the size of the data packet ,But the system and Bluetooth device will limit Bluetooth 4.0Data size transmission ,After exceeding the maximum number of bytes ,It is recommended not to exceed each time 20byte 。 * - If the data is written too long, it is too long ,iOS There will be no callbacks in the existence system (Including errors )。 * - On the Android platform ,Call `notifyBLECharacteristicValueChange` Call immediately after success `writeBLECharacteristicValue` interface ,It will happen on some models 10008 system error * @supported weapp * @example * ```tsx * // Send one to the Bluetooth equipment 0x00of 16Inlet data * let buffer = new ArrayBuffer(1) * let dataView = new DataView(buffer) * dataView.setUint8(0, 0) * Vnmf.writeBLECharacteristicValue({ * // here deviceId Need in getBluetoothDevices or onBluetoothDeviceFound Get in the interface * deviceId, * // here serviceId Need in getBLEDeviceServices Get in the interface * serviceId, * // here characteristicId Need in getBLEDeviceCharacteristics Get in the interface * characteristicId, * // here valueYes ArrayBuffertype * value: buffer, * success: function (res) { * console.log('writeBLECharacteristicValue success', res.errMsg) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.writeBLECharacteristicValue.html */ writeBLECharacteristicValue( option: writeBLECharacteristicValue.Option, ): Promise /** Negotiation setting the largest transmission unit of low -power consumption in Bluetooth (Maximum Transmission Unit, MTU) * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.setBLEMTU.html */ setBLEMTU( option: setBLEMTU.Option, ): Promise /** Read the binary data value of the characteristic value of low -power Bluetooth equipment 。Notice :The feature value support of the device read Only to successfully call 。 * * **Notice ** * - There will be many possibilities of reading failure in parallel adjustment 。 * - The information obtained by the interface needs to `onBLECharacteristicValueChange` Methods to get in the registered callback 。 * @supported weapp * @example * ```tsx * // It must be obtained here * Vnmf.onBLECharacteristicValueChange(function(characteristic) { * console.log('characteristic value comed:', characteristic) * }) * Vnmf.readBLECharacteristicValue({ * // here deviceId Need to pass createBLEConnection Create link with the corresponding device * deviceId, * // here serviceId Need in getBLEDeviceServices Get in the interface * serviceId, * // here characteristicId Need in getBLEDeviceCharacteristics Get in the interface * characteristicId, * success: function (res) { * console.log('readBLECharacteristicValue:', res.errCode) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.readBLECharacteristicValue.html */ readBLECharacteristicValue( option: readBLECharacteristicValue.Option, ): Promise /** Monitoring of the largest transmission unit of low power consumption in Bluetooth (Only Android trigger ) * @supported weapp * @example * ```tsx * Vnmf.onBLEMTUChange(function (res) { * console.log('bluetooth mtu is', res.mtu) * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLEMTUChange.html */ onBLEMTUChange( /** The recovery function of the largest transmission unit of Bluetooth low power consumption */ callback: onBLEMTUChange.Callback, ): void /** Monitor the change of low -power Bluetooth connection status 。Including developers actively connect or disconnect connection ,Device loss ,Connection abnormal disconnection and so on * @supported weapp * @example * ```tsx * Vnmf.onBLEConnectionStateChange(function (res) { * // This method can be used to handle abnormal conditions such as connection accident disconnection * console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`) * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLEConnectionStateChange.html */ onBLEConnectionStateChange( /** Low -power Bluetooth connection state changes to the event callback function */ callback: onBLEConnectionStateChange.Callback, ): void /** Surveillance of the characteristic value changes in the characteristic value of low power consumption Bluetooth equipment 。Must be enabled first `notifyBLECharacteristicValueChange` The interface can receive the device push notification。 * @supported weapp * @example * ```tsx * // ArrayBufferchange 16Example * function ab2hex(buffer) { * let hexArr = Array.prototype.map.call( * new Uint8Array(buffer), * function(bit) { * return ('00' + bit.toString(16)).slice(-2) * } * ) * return hexArr.join(''); * } * Vnmf.onBLECharacteristicValueChange(function (res) { * console.log(`characteristic ${res.characteristicId} has changed, now is ${res.value}`) * console.log(ab2hex(res.value)) * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.onBLECharacteristicValueChange.html */ onBLECharacteristicValueChange( /** The recovery function of the characteristic value change event of the low -power Bluetooth equipment */ callback: onBLECharacteristicValueChange.Callback, ): void /** Cancellation of the largest transmission unit of the low -power consumption of Bluetooth to listen to the low power consumption of Bluetooth * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.offBLEMTUChange.html */ offBLEMTUChange( /** The recovery function of the largest transmission unit of Bluetooth low power consumption */ callback: onBLEMTUChange.Callback, ): void /** Cancel the changes in monitoring Bluetooth low -power connection status * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.offBLEConnectionStateChange.html */ offBLEConnectionStateChange( /** Change the recovery function of the event of a low -power connection status of Bluetooth */ callback: onBLEMTUChange.Callback, ): void /** Cancel the characteristic value change of the characteristic value of the low -power equipment of the monitoring Bluetooth * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.offBLECharacteristicValueChange.html */ offBLECharacteristicValueChange( /** The recovery function of the characteristic value change event of the low -power Bluetooth equipment */ callback: onBLEMTUChange.Callback, ): void /** When the characteristic value of low -power Bluetooth equipment is enabled notify Function ,Subscribe to feature value 。Notice :The feature value support of the device notify or indicate Only to successfully call 。 * * in addition ,Must be enabled first `notifyBLECharacteristicValueChange` Only to monitor the device `characteristicValueChange` event * * **Notice ** * - After the subscription operation is successful, the device needs to actively update the feature value value,Only to trigger Vnmf.onBLECharacteristicValueChange Call back 。 * - On the Android platform ,Call `notifyBLECharacteristicValueChange` Call immediately after success `writeBLECharacteristicValue` interface ,It will happen on some models 10008 system error * @supported weapp * @example * ```tsx * Vnmf.notifyBLECharacteristicValueChange({ * state: true, // Open up notify Function * // here deviceId Need to pass createBLEConnection Create link with the corresponding device * deviceId, * // here serviceId Need in getBLEDeviceServices Get in the interface * serviceId, * // here characteristicId Need in getBLEDeviceCharacteristics Get in the interface * characteristicId, * success: function (res) { * console.log('notifyBLECharacteristicValueChange success', res.errMsg) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.notifyBLECharacteristicValueChange.html */ notifyBLECharacteristicValueChange( option: notifyBLECharacteristicValueChange.Option, ): Promise /** Get the largest transmission unit of low -power consumption of Bluetooth 。Need in [Vnmf.createBLEConnection](/docs/apis/device/bluetooth-ble/createBLEConnection) Call after the call is successful 。 * * Notice : * - Applet MTU for ATT_MTU,Include Op-Code and Attribute Handle length ,The length of the data that can be transmitted is ATT_MTU - 3 * - iOS In the system MTU For fixing ;In the Android system ,MTU Will change after the system negotiation is successful ,Suggestion [Vnmf.onBLEMTUChange](/docs/apis/device/bluetooth-ble/onBLEMTUChange) monitor 。 * @supported weapp * @example * ```tsx * Vnmf.getBLEMTU({ * deviceId: '', * writeType: 'write', * success (res) { * console.log(res) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEMTU.html */ getBLEMTU( option: getBLEMTU.Option, ): Promise /** Get all the services of Bluetooth equipment (service)。 * @supported weapp * @example * ```tsx * Vnmf.getBLEDeviceServices({ * // here deviceId Need to pass createBLEConnection Create link with the corresponding device * deviceId, * success: function (res) { * console.log('device services:', res.services) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceServices.html */ getBLEDeviceServices( option: getBLEDeviceServices.Option, ): Promise /** Get the signal strength of the Bluetooth low -power equipment (Received Signal Strength Indication, RSSI)。 * @supported weapp * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceRSSI.html */ getBLEDeviceRSSI( option: getBLEDeviceRSSI.Option, ): Promise /** Get all the feature values in a certain service in a Bluetooth device (characteristic)。 * @supported weapp * @example * ```tsx * Vnmf.getBLEDeviceCharacteristics({ * // here deviceId Need to pass createBLEConnection Create link with the corresponding device * deviceId, * // here serviceId Need in getBLEDeviceServices Get in the interface * serviceId, * success: function (res) { * console.log('device getBLEDeviceCharacteristics:', res.characteristics) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.getBLEDeviceCharacteristics.html */ getBLEDeviceCharacteristics( option: getBLEDeviceCharacteristics.Option, ): Promise /** Connect low power Bluetooth equipment 。 * * If the applet has searched a certain Bluetooth device before ,And successfully establish a connection ,Can be obtained directly before searching deviceId Try to connect to the device directly ,No search operation 。 * * **Notice ** * - Please ensure that the right call is as paired `createBLEConnection` and `closeBLEConnection` interface 。Android if you call multiple times `createBLEConnection` Create a connection ,It may cause the system to hold multiple connections of the same device to multiple connections ,Cause call `closeBLEConnection` When you do n’t really disconnect the connection with the device 。 * - Bluetooth connection may be disconnected at any time ,Suggest to monitor Vnmf.onBLEConnectionStateChange Callback ,When the Bluetooth device is disconnected * - If an unconnected device or a disconnected device calls the interface of the data read and write operation ,Will return 10006 mistake ,Suggestion re -connection operation 。 * @supported weapp * @example * ```tsx * Vnmf.createBLEConnection({ * // here deviceId Need to pass createBLEConnection Create link with the corresponding device * deviceId, * success: function (res) { * console.log(res) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.createBLEConnection.html */ createBLEConnection(option: createBLEConnection.Option): Promise /** Connection between disconnection and low -power Bluetooth equipment 。 * @supported weapp * @example * ```tsx * Vnmf.closeBLEConnection({ * deviceId, * success: function (res) { * console.log(res) * } * }) * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-ble/wx.closeBLEConnection.html */ closeBLEConnection(option: closeBLEConnection.Option): Promise } }