Home > Web Front-end > JS Tutorial > body text

WeChat applet Bluetooth device code and error sorting

小云云
Release: 2018-02-03 14:58:14
Original
5207 people have browsed it

The WeChat applet is generally very good. The Bluetooth interface is indeed a "hole". The programmers on the "network side" do the "hardware interface". This article mainly shares with you the WeChat applet Bluetooth device code and error sorting. I hope it can Help everyone.

Some troublesome things

Many Bluetooth devices will jam the phone. The company can scan 200+ devices and directly jam the WeChat of iPhone 5S.

There must be a delay between each hardware operation, 100ms is recommended, such as between "turn on Bluetooth" and "start scanning", "connection successful" and "get service", etc. Failure to use delay may cause inexplicable errors, which are more common on the Android side.

Pay attention to the asynchronous and concurrency characteristics of JS, especially the characteristics under polling service. The mini program does not yet support async and await (these two keywords are included in the code completion, but they cannot be compiled).

Bluetooth data reading and writing, advertisesData type is ArrayBuffer, (note when quoting the applet: vConsole cannot print out ArrayBuffer type data). Guys, please understand binary arrays and hexadecimal strings first. There are conversion methods in the code (copied from github).

Initialize the Bluetooth adapter (wx.openBluetoothAdapter(OBJECT)) and obtain the status of the local Bluetooth adapter (wx.getBluetoothAdapterState(OBJECT)). It is difficult to say which of these two functions should be called first. You can play it yourself. See the instructions below. .

Some BUG

1. During the Bluetooth scanning process, obtain the local Bluetooth adapter status (wx.getBluetoothAdapterState(OBJECT)). (Exclusive to Android, Huawei Honor 8, VIVO 7plus, 6.5.13)

available\Boolean\Whether the Bluetooth adapter is available, the value is true.

discovering\Boolean\Whether the device is being searched for, the value is false.

https://github.com/FFiot/WX_Bluetooth/issues/1

2. During the Bluetooth scanning process, start scanning again wx.startBluetoothDevicesDiscovery(OBJECT): fail, errCode=10008 . (Exclusive to Android, Huawei Honor 8, VIVO 7plus, 6.5.13) BUG: Query Bluetooth status during Bluetooth scanning · Issue #1 · FFiot/WX_Bluetoothgithub.com During Bluetooth scanning, start scanning again wx.startBluetoothDevicesDiscovery(OBJECT): fail,errCode=10008. (Exclusive to Android, Huawei Honor 8, VIVO 7plus, 6.5.13)

https://github.com/FFiot/WX_Bluetooth/issues/2

errorCode is mixed with errMsg. (Exclusive to IOS, IPHONE5s, WeChat 6.5.15)

https://github.com/FFiot/WX_Bluetooth/issues/3

3. When Bluetooth is scanning characters under service, if If there are multiple services, only the character under the first service can be obtained normally. The chara obtained by other services is the same as that of the first service. (Unique to IOS, IPHONE5s, WeChat 6.5.15)

There are two states for mobile device Bluetooth to be turned on and off, triggering the wx.onBluetoothAdapterStateChange callback

1, wx.getBluetoothAdapterState(OBJECT)

Close status returns: drrCode:10000,errMsg:"getBluetoothAdapterState:fail". Turn on Bluetooth at this time: wx.onBluetoothAdapterStateChange(CALLBACK) has no callback.

Open status returns: drrCode:10000,errMsg:"getBluetoothAdapterState:fail". Turn off Bluetooth at this time: wx.onBluetoothAdapterStateChange(CALLBACK) has no callback.

2. wx.getBluetoothAdapterState(OBJECT)

Close status returns: drrCode:10001,errMsg:"openBluetoothAdapter:fail". Turn on Bluetooth at this time: wx.onBluetoothAdapterStateChange(CALLBACK) has a callback.

Open status returns: errMsg: "openBluetoothAdapter:ok". Turn on Bluetooth at this time: wx.onBluetoothAdapterStateChange(CALLBACK) has a callback.

Related recommendations:

Code for WeChat applet to implement Bluetooth link

##Example sharing of how WeChat applet implements Bluetooth

WeChat Mini Program--Ble Bluetooth

The above is the detailed content of WeChat applet Bluetooth device code and error sorting. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!