当前位置: 首页 > article >正文

uniapp 实现低功耗蓝牙连接并读写数据实战指南

在物联网应用场景中,低功耗蓝牙(BLE)凭借其低能耗、连接便捷的特点,成为设备间数据交互的重要方式。Uniapp 作为一款跨平台开发框架,提供了丰富的 API 支持,使得在多个端实现低功耗蓝牙功能变得轻松高效。本文将结合示例代码,详细讲解如何在 Uniapp 中实现低功耗蓝牙的连接、数据读取与写入操作。

一、开发准备

在开始编码前,需确保开发环境已配置好 Uniapp 开发工具,同时要了解低功耗蓝牙的基本概念,如设备、服务、特征值等。设备是蓝牙连接的主体,服务是设备提供功能的集合,特征值则是具体的数据交互点,包含可读、可写等属性 。

二、初始化蓝牙模块

在 Uniapp 中,使用uni.openBluetoothAdapter方法初始化蓝牙模块,同时通过监听相关事件获取蓝牙状态变化和搜索到的设备信息。

const openBluetooth = () => {uni.openBluetoothAdapter({success: (e) => {console.log('蓝牙适配器打开成功');// 监听蓝牙适配器状态变化uni.onBluetoothAdapterStateChange((res) => {console.log('蓝牙适配器状态变化:', res);});// 监听搜索到新设备uni.onBluetoothDeviceFound((res) => {const devices = res.devices;console.log('搜索到新设备数量:', devices.length);// 处理搜索到的设备数据});},fail: (e) => {console.log('蓝牙适配器打开失败:', e);}});}

三、搜索蓝牙设备

调用uni.startBluetoothDevicesDiscovery方法开始搜索周围的蓝牙设备,可通过传入参数筛选特定设备。搜索完成后,及时调用uni.stopBluetoothDevicesDiscovery停止搜索,避免资源浪费。

const startDiscovery = () => {uni.startBluetoothDevicesDiscovery({success: (e) => {console.log('开始搜索蓝牙设备成功');},fail: (e) => {console.log('开始搜索蓝牙设备失败:', e);}});}const stopDiscovery = () => {uni.stopBluetoothDevicesDiscovery({success: (e) => {console.log('停止搜索蓝牙设备成功');},fail: (e) => {console.log('停止搜索蓝牙设备失败:', e);}});}

 

四、连接蓝牙设备

在获取到目标设备的deviceId后,使用uni.createBLEConnection方法连接设备,并监听连接状态变化。

const connectDevice = (deviceId) => {uni.createBLEConnection({deviceId: deviceId,success: (e) => {console.log('连接蓝牙设备成功');},fail: (e) => {console.log('连接蓝牙设备失败:', e);}});// 监听连接状态变化uni.onBLEConnectionStateChange((res) => {if (res.connected) {console.log('蓝牙设备已连接');} else {console.log('蓝牙设备已断开');}});}

五、获取设备服务与特征值

连接设备后,通过uni.getBLEDeviceServices获取设备服务列表,再利用uni.getBLEDeviceCharacteristics获取指定服务的特征值列表,区分出可读和可写的特征值。

const getServices = (deviceId) => {uni.getBLEDeviceServices({deviceId: deviceId,success: (res) => {const services = res.services;console.log('获取服务成功,服务数量:', services.length);// 处理服务数据},fail: (e) => {console.log('获取服务失败:', e);}});}const getCharacteristics = (deviceId, serviceId) => {uni.getBLEDeviceCharacteristics({deviceId: deviceId,serviceId: serviceId,success: (res) => {const characteristics = res.characteristics;console.log('获取特征值成功,特征值数量:', characteristics.length);// 处理特征值数据,区分可读可写},fail: (e) => {console.log('获取特征值失败:', e);}});}

六、数据读取与写入

6.1 读取数据

获取到可读特征值的characteristicId后,调用uni.readBLECharacteristicValue读取数据。

const readValue = (deviceId, serviceId, characteristicId) => {uni.readBLECharacteristicValue({deviceId: deviceId,serviceId: serviceId,characteristicId: characteristicId,success: (res) => {const data = res.value;console.log('读取数据成功:', data);},fail: (e) => {console.log('读取数据失败:', e);}});}

6.2 写入数据

对于可写特征值,将数据转换为合适格式后,使用uni.writeBLECharacteristicValue写入。

const writeValue = (deviceId, serviceId, characteristicId, data) => {// 数据格式转换,如将字符串转换为ArrayBufferconst buffer = new TextEncoder('utf - 8').encode(data);uni.writeBLECharacteristicValue({deviceId: deviceId,serviceId: serviceId,characteristicId: characteristicId,value: buffer,success: (res) => {console.log('写入数据成功');},fail: (e) => {console.log('写入数据失败:', e);}});}

七、断开连接与关闭蓝牙

使用uni.closeBLEConnection断开与设备的连接,通过uni.closeBluetoothAdapter关闭蓝牙模块。

const disconnectDevice = (deviceId) => {uni.closeBLEConnection({deviceId: deviceId,success: (e) => {console.log('断开蓝牙设备连接成功');},fail: (e) => {console.log('断开蓝牙设备连接失败:', e);}});}const closeBluetooth = () => {uni.closeBluetoothAdapter({success: (e) => {console.log('关闭蓝牙适配器成功');},fail: (e) => {console.log('关闭蓝牙适配器失败:', e);}});}

八、完整代码

<template><view class="container"><button @click="openBluetooth">初始化蓝牙模块</button><button @click="startDiscovery">开始搜索蓝牙设备</button><button @click="stopDiscovery">停止搜索蓝牙设备</button><view class="input-group"><text>设备:</text><input v-model="selectedDeviceName" disabled /><button @click="selectDevice">选择设备</button></view><button @click="connectDevice">连接蓝牙设备</button><button @click="getServices">获取设备服务</button><view class="input-group"><text>服务:</text><input v-model="selectedServiceId" disabled /><button @click="selectService">选择服务</button></view><button @click="getCharacteristics">获取服务的特征值</button><view class="input-group"><text>读取特征值:</text><input v-model="selectedCharacteristicId" disabled /><button @click="selectCharacteristic">选择</button></view><button @click="readValue">读取特征值数据</button><view class="input-group"><text>读取数据:</text><input v-model="readValueData" disabled style="width:60%" /></view><hr /><view class="input-group"><text>写入特征值:</text><input v-model="selectedWCharacteristicId" disabled /><button @click="selectwCharacteristic">选择</button></view><button @click="writeValue">写入特征值数据</button><view class="input-group"><text>写入数据:</text><input v-model="writeValueData" style="width:60%" /></view><button @click="disconnectDevice">断开蓝牙设备</button><button @click="closeBluetooth">关闭蓝牙模块</button><view class="output"><text>{{ outputText }}</text></view></view>
</template><script setup>import {ref} from 'vue'import {onLoad,onUnload} from '@dcloudio/uni-app'// 数据状态const bds = ref([]) // 可连接设备列表const deviceId = ref(null)const bconnect = ref(false)const bss = ref([]) // 连接设备服务列表const serviceId = ref(null)const bscs = ref([]) // 连接设备服务对应的特征值列表const characteristicId = ref(null)const bscws = ref([]) // 可写特征值列表const wcharacteristicId = ref(null)// UI绑定数据const selectedDeviceName = ref('')const selectedServiceId = ref('')const selectedCharacteristicId = ref('')const selectedWCharacteristicId = ref('')const readValueData = ref('')const writeValueData = ref('test')const outputText = ref('Bluetooth用于管理蓝牙设备,搜索附近蓝牙设备、连接实现数据通信等。')// 工具函数const buffer2hex = (value) => {let t = ''if (value) {const v = new Uint8Array(value)for (const i in v) {t += '0x' + v[i].toString(16) + ' '}} else {t = '无效值'}return t}const str2ArrayBuffer = (s, f) => {const b = new Blob([s], {type: 'text/plain'})const r = new FileReader()r.readAsArrayBuffer(b)r.onload = () => {if (f) f.call(null, r.result)}}// 重设数据const resetDevices = (d, s) => {if (!d) {bds.value = []deviceId.value = nullselectedDeviceName.value = ''}if (!s) {bss.value = []serviceId.value = nullselectedServiceId.value = ''}bscs.value = []bscws.value = []characteristicId.value = nullwcharacteristicId.value = nullselectedCharacteristicId.value = ''selectedWCharacteristicId.value = ''}// 输出日志const outLine = (text) => {outputText.value += '\n' + text}const outSet = (text) => {outputText.value = text}// 蓝牙操作函数const openBluetooth = () => {outSet('打开蓝牙适配器:')uni.openBluetoothAdapter({success: (e) => {outLine('打开成功!')// 监听蓝牙适配器状态变化uni.onBluetoothAdapterStateChange((res) => {outLine('onBluetoothAdapterStateChange: ' + JSON.stringify(res))})// 监听搜索到新设备uni.onBluetoothDeviceFound((res) => {const devices = res.devicesoutLine('onBluetoothDeviceFound: ' + devices.length)for (const i in devices) {outLine(JSON.stringify(devices[i]))const device = devices[i]if (device.deviceId) {bds.value.push(device)}}if (!bconnect.value && bds.value.length > 0) {const n = bds.value[bds.value.length - 1].nameselectedDeviceName.value = n || bds.value[bds.value.length - 1].deviceIddeviceId.value = bds.value[bds.value.length - 1].deviceId}})// 监听低功耗蓝牙设备连接状态变化uni.onBLEConnectionStateChange((res) => {outLine('onBLEConnectionStateChange: ' + JSON.stringify(res))if (deviceId.value === res.deviceId) {bconnect.value = res.connected}})// 监听低功耗蓝牙设备的特征值变化uni.onBLECharacteristicValueChange((res) => {outLine('onBLECharacteristicValueChange: ' + JSON.stringify(res))const value = buffer2hex(res.value)console.log(value)outLine('value(hex) = ' + value)if (characteristicId.value === res.characteristicId) {readValueData.value = value} else if (wcharacteristicId.value === res.characteristicId) {uni.showToast({title: value,icon: 'none'})}})},fail: (e) => {outLine('打开失败! ' + JSON.stringify(e))}})}const startDiscovery = () => {outSet('开始搜索蓝牙设备:')resetDevices()uni.startBluetoothDevicesDiscovery({success: (e) => {outLine('开始搜索成功!')},fail: (e) => {outLine('开始搜索失败! ' + JSON.stringify(e))}})}const stopDiscovery = () => {outSet('停止搜索蓝牙设备:')uni.stopBluetoothDevicesDiscovery({success: (e) => {outLine('停止搜索成功!')},fail: (e) => {outLine('停止搜索失败! ' + JSON.stringify(e))}})}const selectDevice = () => {if (bds.value.length <= 0) {uni.showToast({title: '未搜索到有效蓝牙设备!',icon: 'none'})return}const buttons = bds.value.map(device => {return device.name || device.deviceId})uni.showActionSheet({title: '选择蓝牙设备',itemList: buttons,success: (res) => {selectedDeviceName.value = bds.value[res.tapIndex].name || bds.value[res.tapIndex].deviceIddeviceId.value = bds.value[res.tapIndex].deviceIdoutLine('选择了"' + (bds.value[res.tapIndex].name || bds.value[res.tapIndex].deviceId) + '"')}})}const connectDevice = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}outSet('连接设备: ' + deviceId.value)uni.createBLEConnection({deviceId: deviceId.value,success: (e) => {outLine('连接成功!')},fail: (e) => {outLine('连接失败! ' + JSON.stringify(e))}})}const getServices = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}if (!bconnect.value) {uni.showToast({title: '未连接蓝牙设备!',icon: 'none'})return}resetDevices(true)outSet('获取蓝牙设备服务:')uni.getBLEDeviceServices({deviceId: deviceId.value,success: (e) => {const services = e.servicesoutLine('获取服务成功! ' + services.length)if (services.length > 0) {bss.value = servicesfor (const i in services) {outLine(JSON.stringify(services[i]))}if (bss.value.length > 0) {selectedServiceId.value = serviceId.value = bss.value[bss.value.length - 1].uuid}} else {outLine('获取服务列表为空?')}},fail: (e) => {outLine('获取服务失败! ' + JSON.stringify(e))}})}const selectService = () => {if (bss.value.length <= 0) {uni.showToast({title: '未获取到有效蓝牙服务!',icon: 'none'})return}const buttons = bss.value.map(service => service.uuid)uni.showActionSheet({title: '选择服务',itemList: buttons,success: (res) => {selectedServiceId.value = serviceId.value = bss.value[res.tapIndex].uuidoutLine('选择了服务: "' + serviceId.value + '"')}})}const getCharacteristics = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}if (!bconnect.value) {uni.showToast({title: '未连接蓝牙设备!',icon: 'none'})return}if (!serviceId.value) {uni.showToast({title: '未选择服务!',icon: 'none'})return}resetDevices(true, true)outSet('获取蓝牙设备指定服务的特征值:')uni.getBLEDeviceCharacteristics({deviceId: deviceId.value,serviceId: serviceId.value,success: (e) => {const characteristics = e.characteristicsoutLine('获取特征值成功! ' + characteristics.length)if (characteristics.length > 0) {bscs.value = []bscws.value = []for (const i in characteristics) {const characteristic = characteristics[i]outLine(JSON.stringify(characteristic))if (characteristic.properties) {if (characteristic.properties.read) {bscs.value.push(characteristic)}if (characteristic.properties.write) {bscws.value.push(characteristic)if (characteristic.properties.notify || characteristic.properties.indicate) {uni.notifyBLECharacteristicValueChange({deviceId: deviceId.value,serviceId: serviceId.value,characteristicId: characteristic.uuid,state: true,success: (e) => {outLine('notifyBLECharacteristicValueChange ' +characteristic.uuid + ' success.')},fail: (e) => {outLine('notifyBLECharacteristicValueChange ' +characteristic.uuid + ' failed! ' + JSON.stringify(e))}})}}}}if (bscs.value.length > 0) {selectedCharacteristicId.value = characteristicId.value = bscs.value[bscs.value.length - 1].uuid}if (bscws.value.length > 0) {selectedWCharacteristicId.value = wcharacteristicId.value = bscws.value[bscws.value.length - 1].uuid}} else {outLine('获取特征值列表为空?')}},fail: (e) => {outLine('获取特征值失败! ' + JSON.stringify(e))}})}const selectCharacteristic = () => {if (bscs.value.length <= 0) {uni.showToast({title: '未获取到有效可读特征值!',icon: 'none'})return}const buttons = bscs.value.map(char => char.uuid)uni.showActionSheet({title: '选择特征值',itemList: buttons,success: (res) => {selectedCharacteristicId.value = characteristicId.value = bscs.value[res.tapIndex].uuidoutLine('选择了特征值: "' + characteristicId.value + '"')}})}let readInterval = nullconst readValue = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}if (!bconnect.value) {uni.showToast({title: '未连接蓝牙设备!',icon: 'none'})return}if (!serviceId.value) {uni.showToast({title: '未选择服务!',icon: 'none'})return}if (!characteristicId.value) {uni.showToast({title: '未选择读取的特征值!',icon: 'none'})return}outSet('读取蓝牙设备的特征值数据: ')uni.readBLECharacteristicValue({deviceId: deviceId.value,serviceId: serviceId.value,characteristicId: characteristicId.value,success: (e) => {outLine('读取数据成功!')},fail: (e) => {outLine('读取数据失败! ' + JSON.stringify(e))}})}const selectwCharacteristic = () => {if (bscws.value.length <= 0) {uni.showToast({title: '未获取到有效可写特征值!',icon: 'none'})return}const buttons = bscws.value.map(char => char.uuid)uni.showActionSheet({title: '选择特征值',itemList: buttons,success: (res) => {selectedWCharacteristicId.value = wcharacteristicId.value = bscws.value[res.tapIndex].uuidoutLine('选择了特征值: "' + wcharacteristicId.value + '"')}})}const writeValue = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}if (!bconnect.value) {uni.showToast({title: '未连接蓝牙设备!',icon: 'none'})return}if (!serviceId.value) {uni.showToast({title: '未选择服务!',icon: 'none'})return}if (!wcharacteristicId.value) {uni.showToast({title: '未选择写入的特征值!',icon: 'none'})return}if (!writeValueData.value || writeValueData.value === '') {uni.showToast({title: '请输入需要写入的数据',icon: 'none'})return}str2ArrayBuffer(writeValueData.value, (buffer) => {outSet('写入蓝牙设备的特征值数据: ')uni.writeBLECharacteristicValue({deviceId: deviceId.value,serviceId: serviceId.value,characteristicId: wcharacteristicId.value,value: buffer,success: (e) => {outLine('写入数据成功!')},fail: (e) => {outLine('写入数据失败! ' + JSON.stringify(e))}})})}const disconnectDevice = () => {if (!deviceId.value) {uni.showToast({title: '未选择设备!',icon: 'none'})return}resetDevices(true)outSet('断开蓝牙设备连接:')uni.closeBLEConnection({deviceId: deviceId.value,success: (e) => {outLine('断开连接成功!')},fail: (e) => {outLine('断开连接失败! ' + JSON.stringify(e))}})}const closeBluetooth = () => {outSet('关闭蓝牙适配器:')resetDevices()uni.closeBluetoothAdapter({success: (e) => {outLine('关闭成功!')bconnect.value = false},fail: (e) => {outLine('关闭失败! ' + JSON.stringify(e))}})}
</script><style>.container {padding: 20px;}button {margin: 10px 0;padding: 10px;background-color: #007aff;color: white;border-radius: 5px;border: none;}.input-group {display: flex;align-items: center;margin: 10px 0;}.input-group input {flex: 1;border: 1px solid #ccc;padding: 5px;margin: 0 5px;}.input-group button {margin: 0;padding: 5px 10px;}.output {margin-top: 20px;padding: 10px;background-color: #f5f5f5;border: 1px solid #ddd;white-space: pre-wrap;max-height: 200px;overflow-y: auto;}
</style>

 

九、注意事项

      1、权限问题:在不同平台上,需确保应用已获取蓝牙相关权限。例如在 Android 平台,需在AndroidManifest.xml中添加蓝牙权限声明。

      2、兼容性:不同设备的蓝牙服务和特征值 UUID 可能不同,需根据实际设备文档进行适配。

      3、错误处理:完善各 API 调用的错误处理逻辑,及时向用户反馈操作结果。

以上就是在 Uniapp 中实现低功耗蓝牙连接并读写数据的完整流程。若你在实践中有优化需求或遇到问题,欢迎随时分享,我们一起探讨解决。

 

相关文章:

uniapp 实现低功耗蓝牙连接并读写数据实战指南

在物联网应用场景中&#xff0c;低功耗蓝牙&#xff08;BLE&#xff09;凭借其低能耗、连接便捷的特点&#xff0c;成为设备间数据交互的重要方式。Uniapp 作为一款跨平台开发框架&#xff0c;提供了丰富的 API 支持&#xff0c;使得在多个端实现低功耗蓝牙功能变得轻松高效。本…...

【Java学习笔记】递归

递归&#xff08;recursion&#xff09; 思想&#xff1a;把一个复杂的问题拆分成一个简单问题和子问题&#xff0c;子问题又是更小规模的复杂问题&#xff0c;循环往复 本质&#xff1a;栈的使用 递归的注意事项 &#xff08;1&#xff09;需要有递归出口&#xff0c;否者就…...

DigitalOcean推出Valkey托管缓存服务

今天我们激动地宣布推出DigitalOcean的Valkey托管缓存服务&#xff0c;这是我们全新的托管数据库服务&#xff0c;能够无缝替换托管缓存&#xff08;此前称为托管Redis&#xff09;。Valkey托管缓存服务在你一直依赖的功能基础上&#xff0c;还提供了增强工具来支持你的开发需求…...

ASP.NET MVC​ 入门指南四

21. 高级路由配置 21.1 自定义路由约束 除了使用默认的路由约束&#xff0c;你还可以创建自定义路由约束。自定义路由约束允许你根据特定的业务逻辑来决定一个路由是否匹配。例如&#xff0c;创建一个只允许特定年份的路由约束&#xff1a; csharp public class YearRouteCo…...

使用vue的插值表达式渲染变量,格式均正确,但无法渲染

如图&#xff0c;作者遇到的问题为&#xff0c;输入以下代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><…...

leetcode 977. Squares of a Sorted Array

题目描述 双指针法一 用right表示原数组中负数和非负数的分界线。 nums[0,right-1]的是负数&#xff0c;nums[right,nums.size()-1]是非负数。 然后用合并两个有序数组的方法。合并即可。 class Solution { public:vector<int> sortedSquares(vector<int>&…...

Mysql常用函数解析

字符串函数 CONCAT(str1, str2, …) 将多个字符串连接成一个字符串。 SELECT CONCAT(Hello, , World); -- 输出: Hello World​​SUBSTRING(str, start, length) 截取字符串的子串&#xff08;起始位置从1开始&#xff09;。 SELECT SUBSTRING(MySQL, 3, 2); -- 输出: SQ…...

llamafactory-cli webui启动报错TypeError: argument of type ‘bool‘ is not iterable

一、问题 在阿里云NoteBook上启动llamafactory-cli webui报错TypeError: argument of type ‘bool’ is not iterable This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run gradio deploy from the terminal in the working directory t…...

智能电子白板的设计与实现:从硬件选型到软件编程

摘要:本文围绕智能电子白板展开,详述其从硬件芯片与模块选型、接线布局,到软件流程图规划及关键代码编写等方面的设计与实现过程,旨在打造满足现代教育与商务会议需求的多功能智能设备。 注:有想法可在评论区或者看我个人简介。 一、引言 在现代教育与商务场景中,智能…...

机器学习——特征选择

特征选择算法总结应用 特征选择概述 注&#xff1a;关于详细的特征选择算法介绍详见收藏夹。...

Spring - 简单实现一个 Spring 应用

一、为什么需要学习Spring框架&#xff1f; 1.企业级开发标配 超过60%的Java项目都使用Spring生态&#xff08;数据来源&#xff1a;JetBrains开发者报告&#xff09;。 2.简化复杂问题 通过IoC和DI&#xff0c;告别new关键字满天飞的代码。 3.职业竞争力 几乎所有Java岗…...

css 数字从0开始增加的动画效果

项目场景&#xff1a; 提示&#xff1a;这里简述项目相关背景&#xff1a; 在有些时候比如在做C端项目的时候&#xff0c;页面一般需要一些炫酷效果&#xff0c;比如数字会从小值自动加到数据返回的值 css 数字从0开始增加的动画效果 分析&#xff1a; 提示&#xff1a;这里填…...

第十六届蓝桥杯 2025 C/C++组 旗帜

目录 题目&#xff1a; 题目描述&#xff1a; 题目链接&#xff1a; 思路&#xff1a; 思路详解&#xff1a; 代码&#xff1a; 代码详解&#xff1a; 题目&#xff1a; 题目描述&#xff1a; 题目链接&#xff1a; P12340 [蓝桥杯 2025 省 AB/Python B 第二场] 旗帜 -…...

利用无事务方式插入数据库解决并发插入问题

一、背景 由于项目中同一个网元&#xff0c;可能会被多个不同用户操作&#xff0c;而且操作大部分都是以异步子任务形式进行执行&#xff0c;这样就会带来并发写数据问题&#xff0c;本文通过利用无事务方式插入数据库解决并发插入问题&#xff0c;算是解决问题的一种思路&…...

云计算市场的重新分类研究

云计算市场传统分类方式&#xff0c;比如按服务类型分为IaaS、PaaS、SaaS&#xff0c;或者按部署模式分为公有云、私有云、混合云。主要提供计算资源、存储和网络等基础设施。 但随着AI大模型的出现&#xff0c;云计算市场可以分为计算云和智算云&#xff0c;智算云主要是AI模…...

【C语言练习】014. 使用数组作为函数参数

014. 使用数组作为函数参数 014. 使用数组作为函数参数示例1&#xff1a;使用数组作为函数参数并修改数组元素函数定义输出结果 示例2&#xff1a;使用数组作为函数参数并计算数组的平均值函数定义输出结果 示例3&#xff1a;使用二维数组作为函数参数函数定义输出结果 示例4&a…...

Java关键字解析

Java关键字是编程语言中具有特殊含义的保留字&#xff0c;不能用作标识符&#xff08;如变量名、类名等&#xff09;。Java共有50多个关键字&#xff08;不同版本略有差异&#xff09;&#xff0c;下面我将分类详细介绍这些关键字及其使用方式。 一、数据类型相关关键字 1. 基…...

突破zero-RL 困境!LUFFY 如何借离线策略指引提升推理能力?

在大模型推理能力不断取得突破的今天&#xff0c;强化学习成为提升模型能力的关键手段。然而&#xff0c;现有zero-RL方法存在局限。论文提出的LUFFY框架&#xff0c;创新性地融合离线策略推理轨迹&#xff0c;在多个数学基准测试中表现卓越&#xff0c;为训练通用推理模型开辟…...

React Native本地存储方案总结

1. AsyncStorage&#xff08;键值对存储&#xff09; 适用场景&#xff1a;简单键值对存储&#xff08;如用户配置、Token、缓存数据&#xff09;。特点&#xff1a;异步、轻量、API 简单&#xff0c;但性能一般&#xff0c;不推荐存储大量数据。安装&#xff1a;npm install …...

基于Redis实现-附近商铺查询

基于Redis实现-附近查询 这个功能将使用到Redis中的GEO这种数据结构来实现。 1.GEO相关命令 GEO就是Geolocation的简写形式&#xff0c;代表地理坐标。Redis在3.2版本中加入到了对GEO的支持&#xff0c;允许存储地理坐标信息&#xff0c;帮助我们根据经纬度来检索数据&#…...

【java WEB】恢复补充说明

Server 出现javax.servlet.http.HttpServlet", according to the project’s Dynamic Web Module facet version (3.0), was not found on the Java Build Path. 右键项目 > Properties > Project Facets。Dynamic Web Module facet version选4.0即可 还需要在serv…...

安川机器人常见故障报警及解决办法

机器人权限设置 操作权限设置(如果密码不对,就证明密码被人修改) 编辑模式密码:无(一把钥匙,默认) 管理模式密码:999999999(9个9,二把钥匙) 安全模式密码:555555555(9个5,三把钥匙,权限最高,有的型号机器人,没有此模式,但最高密码为安全模式密码) 示教器…...

tiktok web X-Bogus X-Gnarly 分析

声明 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;抓包内容、敏感网址、数据接口等均已做脱敏处理&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01; 逆向过程 部分python代码 import req…...

kes监控组件安装

环境准备 创建监控用户 useradd -m -s /bin/bash -d /home/kmonitor kmonitor passwd k_monitor usermod –a –G kingbase kmonitor 检查java版本 java –version [kmonitorkingbase node_exporter]$ java -version java version "1.8.0_341" Java(TM) SE …...

React-Native Android 多行被截断

1. 问题描述&#xff1a; 如图所示&#xff1a; 2. 问题解决灵感&#xff1a; 使用相同的react-native代码&#xff0c;运行在两个APP&#xff08;demo 和 project&#xff09;上。demo 展示正常&#xff0c;project 展示不正常。 对两个页面截图&#xff0c;对比如下。 得出…...

深度学习【Logistic回归模型】

回归和分类 回归问题得到的结果都是连续的&#xff0c;比如通过学习时间预测成绩 分类问题是将数据分成几类&#xff0c;比如根据邮件信息将邮件分成垃圾邮件和有效邮件两类。 相比于基础的线性回归其实就是增加了一个sigmod函数。 代码 import matplotlib.pyplot as plt i…...

数据科学与计算

1.设计目标与安装 Seaborn 是一个建立在 Matplotlib 基础之上的 Python 数据可视化库&#xff0c;专注于绘制各种统计图形&#xff0c;以便更轻松地呈现和理解数据。Seaborn 的设计目标是简化统计数据可视化的过程&#xff0c;提供高级接口和美观的默认主题&#xff0c;使得用…...

Swift与iOS内存管理机制深度剖析

前言 内存管理是每一位 iOS 开发者都绕不开的话题。虽然 Swift 的 ARC&#xff08;自动引用计数&#xff09;极大简化了开发者的工作&#xff0c;但只有深入理解其底层实现&#xff0c;才能写出高效、健壮的代码&#xff0c;避免各种隐蔽的内存问题。本文将从底层原理出发&…...

怎样给MP3音频重命名?是时候管理下电脑中的音频文件名了

在处理大量音频文件时&#xff0c;给这些文件起一个有意义的名字可以帮助我们更高效地管理和查找所需的内容。通过使用专业的文件重命名工具如简鹿文件批量重命名工具&#xff0c;可以极大地简化这一过程。本文将详细介绍如何利用该工具对 MP3 音频文件进行重命名。 步骤一&am…...

当AI浏览器和AI搜索替代掉传统搜索份额时,老牌的搜索引擎市场何去何从。

AI搜索与传统搜索优劣势分析 AI搜索优势 理解和处理查询方式更智能&#xff1a;利用自然语言处理&#xff08;NLP&#xff09;和机器学习技术&#xff0c;能够更好地理解用户的意图和上下文&#xff0c;处理复杂的问答、长尾问题以及多轮对话&#xff0c;提供更为精准和相关的…...