瀏覽代碼

兼容移远蓝牙

wzh 2 年之前
父節點
當前提交
a059a6b537
共有 3 個文件被更改,包括 40 次插入4 次删除
  1. 8 2
      pages/bluetooth/index/index.vue
  2. 31 1
      utils/ecBLE/ecBLEApp.js
  3. 1 1
      utils/weitiandi/device/device.js

+ 8 - 2
pages/bluetooth/index/index.vue

@@ -202,7 +202,7 @@ import i18 from '@/utils/i18.js'
           }else{
             let pwd =  data.real_data;
             let localPwd = self.getLocalPwd()
-            console.log("pwd:"+pwd);
+            console.log(pwd);
             console.log("localPwd:"+localPwd)
             self.rightPwd = pwd;
             if(pwd != localPwd){
@@ -267,11 +267,16 @@ import i18 from '@/utils/i18.js'
 				ecBLE.openBluetoothAdapter()
 			},
 			startBluetoothDevicesDiscovery() {
+        ecBLE.stopBluetoothDevicesDiscovery();
 				console.log('start search')
 				ecBLE.onBluetoothDeviceFound(res => {
 					// if(res.id==="EC:22:05:13:78:49")
 					// console.log(`id:${res.id},name:${res.name},rssi:${res.rssi}`)
-          if(!res.name.startsWith('BT_')){
+          let isRight = false;
+          if(res.name.startsWith('BT_') || res.name.startsWith('FC41D')){
+            isRight = true;
+          }
+          if(!isRight){
             return;
           }
 					for (const item of deviceListData) {
@@ -288,6 +293,7 @@ import i18 from '@/utils/i18.js'
 					if (res.name.length === 15 && res.name.startsWith('BT_')) {
 						manufacturer = 'eciot'
 					}
+          manufacturer = 'eciot'
 					deviceListData.push({
 						id: res.id,
 						name: res.name,

+ 31 - 1
utils/ecBLE/ecBLEApp.js

@@ -8,9 +8,14 @@ let ecDeviceId = ''
 let ecGattServerUUID = ''
 const ecGattServerUUIDOption1 = '0000FFF0-0000-1000-8000-00805F9B34FB'
 const ecGattServerUUIDOption2 = 'FFF0'
+const yiyuanUUIDOption1  = '0000F536-0000-1000-8000-00805F9B34FB';
+const yiyuanUUIDOption2 = 'F536';
 let ecGattCharacteristicWriteUUID = ''
 const ecGattCharacteristicWriteUUIDOption1 = '0000FFF2-0000-1000-8000-00805F9B34FB'
 const ecGattCharacteristicWriteUUIDOption2 = 'FFF2'
+const yiyuancharacterID1 = '0000FF15-0000-1000-8000-00805F9B34FB'
+const yiyuancharacterID2 = 'FF15'
+
 
 const log = data => {
 	if (logEnable) {
@@ -285,10 +290,21 @@ uni.onBLEConnectionStateChange(async res => {
 			return
 		}
 		for (const service of servicesResult.services) {
+			var isRightService = false;
 			if ((service.uuid.toUpperCase() === ecGattServerUUIDOption1) ||
 				(service.uuid.toUpperCase() === ecGattServerUUIDOption2)) {
 				ecGattServerUUID = service.uuid
+				isRightService = true;
+			}
+			if ((service.uuid.toUpperCase() === yiyuanUUIDOption1) ||
+				(service.uuid.toUpperCase() === yiyuanUUIDOption2)) {
+				ecGattServerUUID = service.uuid
+				isRightService = true;
 			}
+			if(!isRightService){
+				continue;
+			}
+			console.log("uuid:"+ecGattServerUUID)
 			const characteristicsResult = await getBLEDeviceCharacteristics(
 				service.uuid
 			)
@@ -297,6 +313,7 @@ uni.onBLEConnectionStateChange(async res => {
 				closeBLEConnection()
 				return
 			}
+			console.log(characteristicsResult)
 			for (const characteristic of characteristicsResult.characteristics) {
 				if (
 					characteristic.properties &&
@@ -317,13 +334,26 @@ uni.onBLEConnectionStateChange(async res => {
 						return
 					}
 				}
-
+				/**
+				 * 14:49:25.419 uuid:0000FFF0-0000-1000-8000-00805F9B34FB at utils/ecBLE/ecBLEApp.js:298
+				 * 14:49:25.427 characteristic.uuid:0000FFF2-0000-1000-8000-00805F9B34FB at utils/ecBLE/ecBLEApp.js:327
+				 * 14:49:25.443 characteristic.uuid:0000FFF1-0000-1000-8000-00805F9B34FB at utils/ecBLE/ecBLEApp.js:327
+				 */
+				console.log("characteristic.uuid:"+characteristic.uuid)
 				if ((characteristic.uuid.toUpperCase() ===
 						ecGattCharacteristicWriteUUIDOption1) ||
 					(characteristic.uuid.toUpperCase() ===
 						ecGattCharacteristicWriteUUIDOption2)) {
 					ecGattCharacteristicWriteUUID = characteristic.uuid
 				}
+
+				if ((characteristic.uuid.toUpperCase() ===
+						yiyuancharacterID1) ||
+					(characteristic.uuid.toUpperCase() ===
+						yiyuancharacterID2)) {
+					ecGattCharacteristicWriteUUID = characteristic.uuid
+				}
+				console.log("rghtCID:"+ecGattCharacteristicWriteUUID);
 			}
 		}
 		if (isAndroid) {

+ 1 - 1
utils/weitiandi/device/device.js

@@ -471,5 +471,5 @@ export function getUUID(){
 function test(){
    console.log( parseDataObj("AA AC 06 01 01 01 01 01 01 B8"))
 }
-test()
+//test()