WeChat applet calls the bluetooth function to control the parking lock

The first time I learned to use the WeChat applet, the project needs, I was forced to study it. The function is to call the Bluetooth function of the WeChat applet, connect to the smart parking lock, and control the lift. The approximate steps and the called applet interface API are as follows:

1. Open the Bluetooth module wx.openBluetoothAdapter(OBJECT)

2. Search for nearby Bluetooth devices wx.startBluetoothDevicesDiscovery(OBJECT)

3. Get all discovered bluetooth devices wx.getBluetoothDevices(OBJECT)

4. Connect to the bluetooth device wx.createBLEConnection(OBJECT)

5. Get all services of the device wx.getBLEDeviceServices(OBJECT)

6. Get all the characteristic values ​​in a service of the device, and write down the characteristic value that can write data wx.getBLEDeviceCharacteristics(OBJECT)

7. Send up/down command wx.writeBLECharacteristicValue(OBJECT) to bluetooth device

8. Close the bluetooth module wx.closeBLEConnection(OBJECT)


Matters needing attention: The manufacturer will give you a document of the communication protocol of the device, which states which command is sent to control up, which command is to control down, and which eigenvalue can send commands. There are multiple services under one device. , there are multiple eigenvalues ​​under each service, some of which cannot send commands, you can use the remote debugging in the WeChat applet development tool, console.log() to print them out one by one to see


Source code: https://coding.net/u/niunan/p/wxapp_bluesuo/git?public=true

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325170146&siteId=291194637