微信小程序功耗蓝牙界面不响应

微信小程序功耗蓝牙界面不响应,第1张

题主是否想询问“微信小程序功耗蓝牙界面不响应解决方法”方法如下:

1、蓝牙连接失败:是因为设备未打开蓝牙或蓝牙信号不稳定等问题导致连接失败。可以尝试重新连接,或者检查设备是否支持蓝牙连接,并检查设备蓝牙设置。

2、小程序代码问题:是因为小程序代码存在错误或者逻辑问题导致蓝牙连接界面不响应。可以检查小程序代码,找出问题所在,并进行修复。

3、小程序权限问题:是因为小程序未被授予使用蓝牙的权限,或者未获得足够的系统权限,导致无法连接蓝牙设备。可以检查小程序权限设置,并确保已经授权使用蓝牙。

可参考以下无法连接蓝牙设备处理步骤:1、确认蓝牙设备电量与连接范围确认蓝牙设备电量充足,蓝牙连接有效距离一般为10米左右,如果双方设备距离较远或中间存在障碍物,则可能搜索不到蓝牙设备。2、确认蓝牙设备连接状态确保没有其他手机连接此蓝牙设备。3、重新配对蓝牙设备请参考蓝牙设备说明书 *** 作,确保设备处于可配对状态,并重新配对设备。4、进行对比测试同时使用两个无配对记录的手机搜索,如果其他手机也不能搜索到设备,则可能是蓝牙设备故障。5、重置网络设置进入设置--系统管理--备份与重置--重置网络设置--重置设置,再使用查看。6、升级系统版本请您将手机升级至最新版本使用查看。

重新连接。

有时候在显示过程中打开蓝牙,小程序未能及时接收到信息,从而出现打开仍旧提醒的情况。

具体步骤:设置---权限管理--微信--开启蓝牙--允许“。

//indexjs

//获取应用实例

const app = getApp()

const util = require('//utils/utiljs')

const bletool = require('//utils/bletooljs')

Page({

data: {

// lists: [{ 'order_no': '1111', 'car_no': '321', 'car_type': '尚好捷', 'order_date': '2018-01-02 08:00', 'order_money': '1600', 'order_time': '4' }],

car_no: '',

order_no: '',

lists: [],

bleList: [], //蓝牙设备数组

serviceId: '',//592B3370-3900-9A71-4535-35D4212D2837

serviceMac: '',//C9:9B:4C:E7:DE:10

service_psd: '',//855525B837253705595800000329

service_uuid: '',

deviceId:'',

characteristics:[] //特征值

},

onLoad: function (options) {

thisinitBle();

},

onReady: function () {

// 页面渲染完成

},

onShow: function () {

if (appglobalDatacar_nolength>0){

thisgetDeviceInfo();

}

},

onHide: function () {

// 页面隐藏

},

onUnload: function () {

// 页面关闭

appglobalDatacar_no=''

},

//蓝牙相关

//初始化蓝牙

initBle: function () {

var that = this;

wxonBluetoothAdapterStateChange(function (res) {

consolelog('adapterState changed, now is', res)

appglobalDatable_state = resavailable;

if (resavailable) {

thatinitBle();

} else {

utilshowToast('手机蓝牙已关闭');

appglobalDatable_isonnectting = false;

}

})

//打开蓝牙适配器

wxopenBluetoothAdapter({

success: function (res) {

consolelog('打开蓝牙适配器成功');

thatgetBluetoothAdapterState();

appglobalDatable_state = true;

thatonBluetoothDeviceFound();

},

fail: function (res) {

// fail

consolelog(res)

utilshowToast('请打开手机蓝牙');

},

complete: function (res) {

// complete

}

})

},

onBluetoothDeviceFound:function(){

var that = this;

//监听扫描

wxonBluetoothDeviceFound(function (res) {

// res电脑模拟器返回的为数组;手机返回的为蓝牙设备对象

consolelog('监听搜索新设备:', res);

thatupdateBleList([res])

})

},

getBluetoothAdapterState: function () {

var that = this;

wxgetBluetoothAdapterState({

success: function (res) {

var available = resavailable;

var discovering = resdiscovering;

if (!available) {

utilshowToast('蓝牙不可用');

} else {

if (!discovering) {

// thatstartBluetoothDevicesDiscovery();

}

}

}

})

},

startBluetoothDevicesDiscovery: function () {

var that = this;

var services = [];

servicespush(thisdataserviceId);

wxshowLoading({

title: '设备搜索中'

});

setTimeout(function () {

wxhideLoading();

if (appglobalDatadeviceIdlength==0){

utilshowModal('设备搜索失败,请重试');

}

}, 10000)

if(bletoolisIOS()){

wxstartBluetoothDevicesDiscovery({

services: services,

allowDuplicatesKey: true,

success: function (res) {

consolelog('ios搜索成功');

consolelog(res);

},

fail: function (err) {

consolelog(err);

}

});

}else{

wxstartBluetoothDevicesDiscovery({

// services: services,

allowDuplicatesKey: true,

success: function (res) {

consolelog('Android搜索成功');

consolelog(res);

},

fail: function (err) {

consolelog(err);

wxhideLoading();

thatstartBluetoothDevicesDiscovery();

// thatgetBluetoothAdapterState();

utilshowToast('搜索失败');

}

});

}

},

startConnectDevices: function (ltype, array) {

var that = this;

clearTimeout(thatgetConnectedTimer);

thatgetConnectedTimer = null;

wxstopBluetoothDevicesDiscovery({

success: function (res) {

// success

}

})

appglobalDatable_isonnectting = true;

consolelog('连接前:'+thatdeviceId);

wxcreateBLEConnection({

deviceId: thatdeviceId,

success: function (res) {

if (reserrCode == 0) {

consolelog('连接成功:');

thatgetService(thatdeviceId);

}

},

fail: function (err) {

consolelog('连接失败:', err);

wxhideLoading();

utilshowModal('设备连接失败,请重试');

// if (ltype == 'loop') {

// thatconnectDeviceIndex += 1;

// thatloopConnect(array);

// } else {

// thatstartBluetoothDevicesDiscovery();

// thatgetConnectedBluetoothDevices();

// }

appglobalDatable_isonnectting = false;

},

complete: function () {

}

});

},

getService: function (deviceId) {

var that = this;

// 监听蓝牙连接

wxonBLEConnectionStateChange(function (res) {

consolelog(res);

appglobalDatable_isonnectting = resconnected

if (!resconnected) {

utilshowToast('连接断开');

}

});

// 获取蓝牙设备service值

wxgetBLEDeviceServices({

deviceId: deviceId,

success: function (res) {

consolelog('获取蓝牙设备service值');

consolelog(res);

thatgetCharacter(deviceId, resservices);

}

})

},

getCharacter: function (deviceId, services) {

var that = this;

servicesforEach(function (value, index, array) {

if (valueisPrimary) {

thatsetData({

service_uuid: valueuuid,

deviceId: deviceId

})

appglobalDataservice_uuid= valueuuid;

appglobalDatadeviceId=deviceId;

}

});

//监听通知

wxonBLECharacteristicValueChange(function (res) {

// callback

consolelog('value change', res)

const hex = bletoolbuf2char(resvalue)

consolelog('返回的数据:', hex)

//配对密码

if (hexindexOf('855800000106') != -1) {

wxhideLoading();

var charact_write = thatdatacharacteristics[1]

bletoolwriteDataToDevice(thatdatadeviceId, thatdataservice_uuid, charact_write, thatdataservice_psd);

wxshowToast({

title: '设备已连接',

icon: 'success',

duration: 3000

})

setTimeout(function () {

bletoolwriteDataToDevice(thatdatadeviceId, thatdataservice_uuid, charact_write, '235525B837253705590400000273');

}, 2000)

} else if (hexindexOf('23040000') != -1) {

//启动成功

thatstarRenting();

}

})

wxgetBLEDeviceCharacteristics({

deviceId: deviceId,

serviceId: thatgetServiceUUID(),

success: function (res) {

wxgetBLEDeviceCharacteristics({

deviceId: deviceId,

serviceId: thatgetServiceUUID(),

success: function (res) {

consolelog('特征', res)

thatsetData({

characteristics:rescharacteristics

})

appglobalDatacharacteristics = rescharacteristics;

var charact_read = rescharacteristics[0]

},

loopConnect: function (devicesId) {

var that = this;

var listLen = devicesIdlength;

if (devicesId[thisconnectDeviceIndex]) {

thisdeviceId = devicesId[thisconnectDeviceIndex];

thisstartConnectDevices('loop', devicesId);

} else {

consolelog('已配对的设备小程序蓝牙连接失败');

thatstartBluetoothDevicesDiscovery();

thatgetConnectedBluetoothDevices();

}

},

//更新数据 devices为数组类型

updateBleList: function (devices) {

consolelog('设备数据:',devices);

var newData = thisdatableList

var that = this

var tempDevice = null;

for (var i = 0; i < deviceslength; i++) {

//ios设备

if (devices[i]devices != null) {

if (devices[i]deviceslength > 0) {

tempDevice = devices[i]devices[0];

}

else {

continue

}

}

//安卓

else {

tempDevice = devices[i];

}

if (!thisisExist(tempDevice)) {

newDatapush(tempDevice)

}

}

consolelog('数据:');

consolelog(newData)

thissetData({

bleList: newData

})

if (!appglobalDatable_isonnectting) {

var that = this;

thisdatableListforEach(function (value, index, array) {

//找到对应id的设备,ios判断服务id安卓判断mac地址

var deviceId = value['deviceId'];

if(bletoolisIOS()){

let advertisServiceUUID = value['advertisServiceUUIDs'][0];

if (advertisServiceUUID == thatdataserviceIdtoUpperCase()){

thatdeviceId = deviceId;

consolelog(thatdeviceId);

thatstartConnectDevices();

}

}else{

if (deviceId == thatdataserviceMac) {

thatdeviceId = deviceId;

consolelog(thatdeviceId);

thatstartConnectDevices();

}

}

});

}

},

//是否已存在 存在返回true 否则false

isExist: function (device) {

var tempData = thisdatableList

for (var i = 0; i < tempDatalength; i++) {

if (tempData[i]deviceId == devicedeviceId) {

return true

}

}

return false

},

//服务uuid

getServiceUUID: function () {

return bletoolstringTransition(thisdataservice_uuid);

},

getDeviceInfo: function () {

let car_no = appglobalDatacar_no;

var that = this;

wxrequest({

url: appglobalDataserverURL + 'c=car&a=getDeviceInfo&open_id=' + appglobalDataopen_id + '&car_no=' + car_no,

method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

header: { 'content-type': 'application/json' }, // 设置请求的 header

success: function (res) {

// success

var data = resdata;

consolelog(data);

if (dataresult == 1) {

appglobalDataserviceId = datadataservice_id;

appglobalDataserviceMac = datadataservice_mac,

appglobalDataservice_psd = '85' + datadataservice_psd + '5800000329';

thatsetData({

serviceId: datadataservice_id,

serviceMac: datadataservice_mac,

service_psd: '85' + datadataservice_psd+'5800000329',

})

appstartBluetoothDevicesDiscovery();

// thatonBLECharacteristicValueChange();

} else {

utilshowModal(datamsg);

}

},

fail: function () {

},

complete: function () {

// complete

}

});

},

})

以上就是关于微信小程序功耗蓝牙界面不响应全部的内容,包括:微信小程序功耗蓝牙界面不响应、小米手机微信小程序蓝牙连接不上、微信小程序说请打开蓝牙但开着蓝牙等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9484155.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存