添加全局蓝牙
11
App.vue
@ -1,8 +1,12 @@
|
||||
<script>
|
||||
import request from '@/utils/request.js';
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
|
||||
uni.clearStorageSync();
|
||||
var ble = bleTool.getBleTool();
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
@ -54,4 +58,9 @@
|
||||
.uni-picker-view-wrapper{
|
||||
background: rgba(42, 42, 42, 1);
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "PingFang SC";
|
||||
src: url("~@/static/fonts/PingFangSC.ttf") format("opentype");
|
||||
}
|
||||
</style>
|
||||
|
68
node_modules/paho-mqtt/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
# Contributing to Paho
|
||||
|
||||
Thanks for your interest in this project!
|
||||
|
||||
You can contribute bugfixes and new features by sending pull requests through GitHub.
|
||||
|
||||
## Legal
|
||||
|
||||
In order for your contribution to be accepted, it must comply with the Eclipse Foundation IP policy.
|
||||
|
||||
Please read the [Eclipse Foundation policy on accepting contributions via Git](http://wiki.eclipse.org/Development_Resources/Contributing_via_Git).
|
||||
|
||||
1. Sign the [Eclipse CLA](http://www.eclipse.org/legal/CLA.php)
|
||||
1. Register for an Eclipse Foundation User ID. You can register [here](https://dev.eclipse.org/site_login/createaccount.php).
|
||||
2. Log into the [Projects Portal](https://projects.eclipse.org/), and click on the '[Eclipse CLA](https://projects.eclipse.org/user/sign/cla)' link.
|
||||
2. Go to your [account settings](https://dev.eclipse.org/site_login/myaccount.php#open_tab_accountsettings) and add your GitHub username to your account.
|
||||
3. Make sure that you _sign-off_ your Git commits in the following format:
|
||||
``` Signed-off-by: John Smith <johnsmith@nowhere.com> ``` This is usually at the bottom of the commit message. You can automate this by adding the '-s' flag when you make the commits. e.g. ```git commit -s -m "Adding a cool feature"```
|
||||
4. Ensure that the email address that you make your commits with is the same one you used to sign up to the Eclipse Foundation website with.
|
||||
|
||||
## Contributing a change
|
||||
|
||||
## Contributing a change
|
||||
|
||||
1. [Fork the repository on GitHub](https://github.com/eclipse/paho.mqtt.javascript/fork)
|
||||
2. Clone the forked repository onto your computer: ``` git clone https://github.com/<your username>/paho.mqtt.javascript.git ```
|
||||
3. Create a new branch from the latest ```develop``` branch with ```git checkout -b YOUR_BRANCH_NAME origin/develop```
|
||||
4. Make your changes
|
||||
5. If developing a new feature, make sure to include JUnit tests.
|
||||
6. Ensure that all new and existing tests pass.
|
||||
7. Commit the changes into the branch: ``` git commit -s ``` Make sure that your commit message is meaningful and describes your changes correctly.
|
||||
8. If you have a lot of commits for the change, squash them into a single / few commits.
|
||||
9. Push the changes in your branch to your forked repository.
|
||||
10. Finally, go to [https://github.com/eclipse/paho.mqtt.javascript](https://github.com/eclipse/paho.mqtt.javascript) and create a pull request from your "YOUR_BRANCH_NAME" branch to the ```develop``` one to request review and merge of the commits in your pushed branch.
|
||||
|
||||
|
||||
What happens next depends on the content of the patch. If it is 100% authored
|
||||
by the contributor and is less than 1000 lines (and meets the needs of the
|
||||
project), then it can be pulled into the main repository. If not, more steps
|
||||
are required. These are detailed in the
|
||||
[legal process poster](http://www.eclipse.org/legal/EclipseLegalProcessPoster.pdf).
|
||||
|
||||
|
||||
|
||||
## Developer resources:
|
||||
|
||||
|
||||
Information regarding source code management, builds, coding standards, and more.
|
||||
|
||||
- [https://projects.eclipse.org/projects/iot.paho/developer](https://projects.eclipse.org/projects/iot.paho/developer)
|
||||
|
||||
Contact:
|
||||
--------
|
||||
|
||||
Contact the project developers via the project's development
|
||||
[mailing list](https://dev.eclipse.org/mailman/listinfo/paho-dev).
|
||||
|
||||
Search for bugs:
|
||||
----------------
|
||||
|
||||
This project uses GitHub Issues here: [github.com/eclipse/paho.mqtt.javascript/issues](https://github.com/eclipse/paho.mqtt.javascript/issues) to track ongoing development and issues.
|
||||
|
||||
Create a new bug:
|
||||
-----------------
|
||||
|
||||
Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome!
|
||||
|
||||
- [Create new Paho bug](https://github.com/eclipse/paho.mqtt.javascript/issues/new)
|
@ -1061,14 +1061,14 @@
|
||||
|
||||
.eq .bigTxt {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.eq .smallTxt {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
}
|
||||
@ -1097,7 +1097,7 @@
|
||||
|
||||
.eqinfo .lbl {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1107,7 +1107,7 @@
|
||||
|
||||
.eqinfo .value {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1177,7 +1177,7 @@
|
||||
|
||||
.mode .bigTxt {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1187,7 +1187,7 @@
|
||||
|
||||
.mode .smallTxt {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1205,7 +1205,7 @@
|
||||
|
||||
.usrtitle {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
height: 40rpx;
|
||||
@ -1220,7 +1220,7 @@
|
||||
width: 82rpx;
|
||||
height: 40rpx;
|
||||
color: rgba(35, 35, 35, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 20rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.07px;
|
||||
@ -1253,7 +1253,7 @@
|
||||
text-align: right;
|
||||
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1271,7 +1271,7 @@
|
||||
|
||||
.usrinfo .value .uni-input-input {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
|
||||
@ -1282,7 +1282,7 @@
|
||||
|
||||
.usrplace {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.07px;
|
||||
@ -1322,7 +1322,7 @@
|
||||
|
||||
.proinfo .item .txt {
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
margin-top: 20rpx;
|
||||
|
@ -410,9 +410,8 @@
|
||||
var these = this;
|
||||
|
||||
|
||||
var parseData = (
|
||||
bytes) => {
|
||||
|
||||
var parseData = () => {
|
||||
let bytes=receive.bytes;
|
||||
if (bytes[0] == 0x55) {
|
||||
try {
|
||||
let staticLevelByte = bytes[1];
|
||||
@ -483,14 +482,13 @@
|
||||
} catch (error) {
|
||||
console.error('数据解析错误:', error);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if(receive.str)
|
||||
{
|
||||
try {
|
||||
let uint8Array = new Uint8Array(receive.value);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
|
||||
let str = receive.str;
|
||||
|
||||
if (str.indexOf('mac address:') == 0) {
|
||||
these.formData.macAddress = str.split(':')[1];
|
||||
console.log("收到mac地址:", )
|
||||
|
@ -5,12 +5,23 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
var these=null;
|
||||
var eventChannel =null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
these=this;
|
||||
eventChannel= this.getOpenerEventChannel();
|
||||
|
||||
eventChannel.on('LinkItem', function(data) {
|
||||
console.log("收到父页面的参数了,",data)
|
||||
eventChannel.emit("Linked",data);
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
||||
}
|
||||
|
@ -85,9 +85,10 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ble from '../../../api/6155/BlueHelper.js';
|
||||
import request from '../../../utils/request.js';
|
||||
|
||||
import bleTool from '@/utils/BleHelper.js';
|
||||
import request from '@/utils/request.js';
|
||||
var ble = null;
|
||||
var these = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -130,69 +131,57 @@
|
||||
},
|
||||
onBackPress: (e) => {
|
||||
ble.StopSearch();
|
||||
ble.disconnectDevice();
|
||||
},
|
||||
|
||||
onShow: function() {
|
||||
// return;
|
||||
var these = this;
|
||||
uni.getStorage({
|
||||
key: "linkedDevices",
|
||||
success: (res) => {
|
||||
this.PairEquip = JSON.parse(res.data);
|
||||
},
|
||||
fail: (ex) => {
|
||||
this.PairEquip = [];
|
||||
},
|
||||
onLoad() {
|
||||
these = this;
|
||||
ble = bleTool.getBleTool();
|
||||
ble.addDeviceFound((arr) => {
|
||||
console.log("发现新设备"+JSON.stringify(arr));
|
||||
arr = arr.devices;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
|
||||
arr[i].linkStatu = false;
|
||||
let f = these.EquipMents.find(function(v) {
|
||||
return v.deviceId == arr[i].deviceId;
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
|
||||
these.EquipMents.push(arr[i]);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.UNI_PLATFORM == 'mp-weixin' ||
|
||||
process.env.UNI_PLATFORM == 'mp-alipay' ||
|
||||
process.env.UNI_PLATFORM == 'app-plus' ||
|
||||
process.env.UNI_PLATFORM == 'app'
|
||||
|
||||
) {
|
||||
//打开蓝牙开始搜索设备
|
||||
ble.OpenBlue(true, () => {
|
||||
ble.StartSearch(function(arr) {
|
||||
|
||||
arr = arr.devices;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
|
||||
arr[i].linkStatu = false;
|
||||
let f = these.EquipMents.find(function(v) {
|
||||
return v.deviceId == arr[i].deviceId;
|
||||
});
|
||||
|
||||
if (!f) {
|
||||
these.EquipMents.push(arr[i]);
|
||||
}
|
||||
ble.addReceiveCallback((receivData) => {
|
||||
console.log("收到数据了:", receivData);//数据格式:{bytes:[109,97],str:"",hexs:"FA 01"}
|
||||
console.log("LinkedList=",ble.data.LinkedList);
|
||||
let data=uni.getStorageSync(ble.StorageKey);
|
||||
console.log("data=",data);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
console.log("设备列表:" + JSON.stringify(these.EquipMents));
|
||||
});
|
||||
},
|
||||
() => {
|
||||
these.showOpenSetting();
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log('当前环境:' + process.env.UNI_PLATFORM + '不支持蓝牙');
|
||||
}
|
||||
},
|
||||
onShow: function() {
|
||||
console.log("222222");
|
||||
ble.StartSearch().catch((ex) => {
|
||||
if (ex.code == 10001) {
|
||||
these.showOpenSetting();
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
methods: {
|
||||
isItemLink: function(item, index) {
|
||||
let src = '/static/images/BLEAdd/noLink.png';
|
||||
if (this.PairEquip && this.PairEquip instanceof Array) {
|
||||
|
||||
if (this.PairEquip && this.PairEquip.length) {
|
||||
if (this.PairEquip.length > 0) {
|
||||
let f = this.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
@ -236,84 +225,51 @@
|
||||
},
|
||||
gotoSetting: function() {
|
||||
this.Status.BottomMenu.show = false;
|
||||
ble.showBluetoothGuide(false);
|
||||
ble.showBlueSetting(false);
|
||||
},
|
||||
Link: function(item, index) {
|
||||
var these = this;
|
||||
if (process.env.UNI_PLATFORM == 'mp-weixin' ||
|
||||
process.env.UNI_PLATFORM == 'mp-alipay' ||
|
||||
process.env.UNI_PLATFORM == 'app-plus' ||
|
||||
process.env.UNI_PLATFORM == 'app'
|
||||
) {
|
||||
|
||||
uni.showLoading({
|
||||
title: "正在连接",
|
||||
mask: true
|
||||
});
|
||||
setTimeout(() => {
|
||||
|
||||
|
||||
ble.LinkBlue(item.deviceId, function() {
|
||||
let c = these.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
});
|
||||
if (!c) {
|
||||
these.PairEquip.push(item);
|
||||
uni.setStorage({
|
||||
key: 'linkedDevices',
|
||||
data: JSON.stringify(these.PairEquip),
|
||||
success: () => {}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 调用绑定设备接口
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: item.deviceId,
|
||||
communicationMode: '1', //0是4g,1是蓝牙
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
if (res.code == 0) {
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: res.data,
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
});
|
||||
}
|
||||
}).catch((ex) => {
|
||||
|
||||
uni.showToast({
|
||||
title: '出现了未知的异常,操作失败',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}, (ex) => {
|
||||
uni.hideLoading();
|
||||
ble.StopSearch();
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/LinkBle",
|
||||
events:{
|
||||
Linked:function(data ){
|
||||
console.log("收到数据了",data);
|
||||
}
|
||||
},
|
||||
success(res) {
|
||||
res.eventChannel.emit('LinkItem', item)
|
||||
}
|
||||
});
|
||||
return;
|
||||
uni.showLoading({
|
||||
title: "正在连接",
|
||||
mask: true
|
||||
});
|
||||
setTimeout(() => {
|
||||
let serviceid=null;
|
||||
if(item.advertisServiceUUIDs.length>0){
|
||||
serviceid=item.advertisServiceUUIDs[0];
|
||||
}
|
||||
ble.LinkBlue(item.deviceId,serviceid).then((res) => {
|
||||
let c = these.PairEquip.find(function(v) {
|
||||
return v.deviceId == item.deviceId;
|
||||
});
|
||||
}, 0);
|
||||
if (!c) {
|
||||
|
||||
these.PairEquip.push(item);
|
||||
}
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("ex=",ex)
|
||||
uni.showModal({
|
||||
content:"连接失败:"+ex.msg
|
||||
});
|
||||
}).finally(()=>{
|
||||
uni.hideLoading();
|
||||
});
|
||||
}, 0);
|
||||
|
||||
|
||||
} else {
|
||||
these.alert("提示", "当前平台不支持蓝牙");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -451,7 +407,7 @@
|
||||
|
||||
.mainContent .lblTitle {
|
||||
color: #ffffffde;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
text-align: left;
|
||||
@ -516,7 +472,7 @@
|
||||
|
||||
.list .item .name {
|
||||
color: #ffffffde;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 26rpx;
|
||||
font-weight: 400;
|
||||
line-height: 50rpx;
|
||||
@ -525,7 +481,7 @@
|
||||
|
||||
.list .item .id {
|
||||
color: #ffffff99;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24rpx;
|
||||
font-weight: 400;
|
||||
line-height: 30rpx;
|
||||
@ -547,7 +503,7 @@
|
||||
|
||||
.openBlue .txt {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 0.14rpx;
|
||||
@ -572,7 +528,7 @@
|
||||
width: 25%;
|
||||
height: 60rpx;
|
||||
text-align: center;
|
||||
font-family: PingFang SC;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 28rpx;
|
||||
letter-spacing: 12rpx;
|
||||
display: flex !important;
|
||||
@ -584,10 +540,12 @@
|
||||
justify-content: center;
|
||||
|
||||
}
|
||||
|
||||
.openBlue .cancel {
|
||||
border: 1px solid rgba(255, 255, 255, 1);
|
||||
color: rgba(255, 255, 255, 1);
|
||||
}
|
||||
|
||||
.openBlue .ok {
|
||||
background-color: #BBE600;
|
||||
color: #232323;
|
||||
|
@ -60,7 +60,7 @@
|
||||
data() {
|
||||
return {
|
||||
showView: false,
|
||||
phone: '13800138002', //手机号码
|
||||
phone: '17671332251', //手机号码
|
||||
code: "123456", //验证码
|
||||
agreed: false,
|
||||
isCounting: false,
|
||||
|
BIN
static/fonts/PingFangSC.ttf
Normal file
BIN
static/images/add.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
static/images/bip.6.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
static/images/bluetooth.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
static/images/bs.png
Normal file
After Width: | Height: | Size: 463 B |
BIN
static/images/cires.png
Normal file
After Width: | Height: | Size: 171 B |
BIN
static/images/cp.png
Normal file
After Width: | Height: | Size: 489 B |
BIN
static/images/delel.png
Normal file
After Width: | Height: | Size: 486 B |
BIN
static/images/delete-icon.png
Normal file
After Width: | Height: | Size: 605 B |
BIN
static/images/delete.png
Normal file
After Width: | Height: | Size: 766 B |
BIN
static/images/dell.png
Normal file
After Width: | Height: | Size: 324 B |
BIN
static/images/dl.png
Normal file
After Width: | Height: | Size: 512 B |
BIN
static/images/fg.png
Normal file
After Width: | Height: | Size: 264 B |
BIN
static/images/gprs.png
Normal file
After Width: | Height: | Size: 250 B |
BIN
static/images/jg.png
Normal file
After Width: | Height: | Size: 331 B |
BIN
static/images/login.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
static/images/logo.png
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
static/images/more.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
static/images/nz.png
Normal file
After Width: | Height: | Size: 901 B |
BIN
static/images/path1.png
Normal file
After Width: | Height: | Size: 246 B |
BIN
static/images/path2.png
Normal file
After Width: | Height: | Size: 587 B |
BIN
static/images/path7.png
Normal file
After Width: | Height: | Size: 357 B |
BIN
static/images/scan.png
Normal file
After Width: | Height: | Size: 563 B |
BIN
static/images/scane.png
Normal file
After Width: | Height: | Size: 228 B |
BIN
static/images/sendSucc.png
Normal file
After Width: | Height: | Size: 500 B |
BIN
static/images/set.png
Normal file
After Width: | Height: | Size: 799 B |
BIN
static/images/sett.png
Normal file
After Width: | Height: | Size: 927 B |
BIN
static/images/settt.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
static/images/shape.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
static/images/share.png
Normal file
After Width: | Height: | Size: 226 B |
BIN
static/images/sm.png
Normal file
After Width: | Height: | Size: 457 B |
BIN
static/images/sp.png
Normal file
After Width: | Height: | Size: 320 B |
BIN
static/images/success.png
Normal file
After Width: | Height: | Size: 510 B |
BIN
static/images/svg.png
Normal file
After Width: | Height: | Size: 475 B |
BIN
static/images/type.png
Normal file
After Width: | Height: | Size: 209 B |
BIN
static/images/upload.png
Normal file
After Width: | Height: | Size: 740 B |
BIN
static/images/upload_ax.png
Normal file
After Width: | Height: | Size: 446 B |
BIN
static/images/user.png
Normal file
After Width: | Height: | Size: 654 B |
BIN
static/images/video.png
Normal file
After Width: | Height: | Size: 691 B |
BIN
static/images/wm.png
Normal file
After Width: | Height: | Size: 509 B |
BIN
static/images/xy.png
Normal file
After Width: | Height: | Size: 385 B |
BIN
static/images/ys.png
Normal file
After Width: | Height: | Size: 489 B |
BIN
static/zj.png
Normal file
After Width: | Height: | Size: 296 KiB |
BIN
static/zjlogo.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
@ -12,18 +12,16 @@ class BleHelper {
|
||||
});
|
||||
var linkedDevices = [];
|
||||
if (f) {
|
||||
var str = uni.getStorageSync(key);
|
||||
////console.log(str);
|
||||
if (str) {
|
||||
linkedDevices = str;
|
||||
} else {
|
||||
linkedDevices = [];
|
||||
}
|
||||
linkedDevices = uni.getStorageSync(key);
|
||||
}
|
||||
linkedDevices.filter((v) => {
|
||||
v.Linked = false;
|
||||
v.notifyState = false;
|
||||
});
|
||||
if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) {
|
||||
console.log("111111", linkedDevices);
|
||||
linkedDevices.filter((v) => {
|
||||
v.Linked = false;
|
||||
v.notifyState = false;
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.linkAllDevices();
|
||||
}, 10);
|
||||
@ -349,8 +347,8 @@ class BleHelper {
|
||||
|
||||
|
||||
var bytesToHexString = (bytes) => {
|
||||
return bytes.map(byte => byte.toString(16).padStart(2, '0'))
|
||||
.join(' ');
|
||||
return bytes.map(byte => byte.toString(16).padStart(2,
|
||||
'0'));
|
||||
}
|
||||
|
||||
uni.onBluetoothAdapterStateChange((state) => {
|
||||
@ -428,7 +426,17 @@ class BleHelper {
|
||||
// 将每个字节转换为对应的字符
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
|
||||
let header="mac address:";
|
||||
if (str.indexOf(header) == 0) {
|
||||
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == receive.deviceId) {
|
||||
v.macAddress = str.replace(header,"");
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
.LinkedList);
|
||||
}
|
||||
//////console.log("收到的字符串:", str)
|
||||
|
||||
} catch (ex) {
|
||||
@ -514,6 +522,7 @@ class BleHelper {
|
||||
var these = this;
|
||||
//开始搜索
|
||||
var Search = () => {
|
||||
console.log("Search........");
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.startBluetoothDevicesDiscovery({
|
||||
services: [],
|
||||
@ -524,7 +533,7 @@ class BleHelper {
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
//console.log(`搜索蓝牙设备失败:`, err);
|
||||
console.log(`搜索蓝牙设备失败:`, err);
|
||||
|
||||
reject(this.getError(err));
|
||||
}
|
||||
@ -537,8 +546,8 @@ class BleHelper {
|
||||
|
||||
|
||||
return this.OpenBlue().then((res) => {
|
||||
//console.log("蓝牙适配器状态", res)
|
||||
this.StopSearch();
|
||||
console.log("蓝牙适配器状态", res)
|
||||
|
||||
return Search();
|
||||
});
|
||||
|
||||
@ -598,31 +607,71 @@ class BleHelper {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//console.log("开始订阅消息");
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
deviceId: deviceId,
|
||||
serviceId: c.notifyServiceid,
|
||||
characteristicId: c.notifyCharactId,
|
||||
state: state,
|
||||
success: (res) => {
|
||||
if (state) {
|
||||
console.log("订阅消息成功", res);
|
||||
} else {
|
||||
console.log("取消订阅成功", res);
|
||||
}
|
||||
console.log("c=", c);
|
||||
let startSubScribe = (id, serviceId, characteristicId) => {
|
||||
console.log("id, serviceId, characteristicId=" + id + "," + serviceId +
|
||||
"," + characteristicId);
|
||||
return new Promise((succ, err) => {
|
||||
uni.notifyBLECharacteristicValueChange({
|
||||
deviceId: id,
|
||||
serviceId: serviceId,
|
||||
characteristicId: characteristicId,
|
||||
state: state,
|
||||
success: (res) => {
|
||||
if (state) {
|
||||
console.log("订阅消息成功", res);
|
||||
} else {
|
||||
console.log("取消订阅成功", res);
|
||||
}
|
||||
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == deviceId) {
|
||||
v.notifyState = state;
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == deviceId) {
|
||||
v.notifyState = state;
|
||||
}
|
||||
});
|
||||
succ();
|
||||
},
|
||||
fail: (ex) => {
|
||||
console.log("deviceId=", id);
|
||||
console.log("serviceId=", serviceId);
|
||||
console.log("characteristicId=",
|
||||
characteristicId);
|
||||
err(this.getError(ex));
|
||||
}
|
||||
});
|
||||
resolve();
|
||||
},
|
||||
fail: (ex) => {
|
||||
});
|
||||
}
|
||||
let promies = new Array();
|
||||
for (var i = 0; i < c.Characteristics.length; i++) {
|
||||
let item = c.Characteristics[i];
|
||||
let serviceId = item.serviceId;
|
||||
let characteristicId = item.uuid;
|
||||
|
||||
reject(this.getError(ex));
|
||||
if (item.properties.notify) {
|
||||
promies.push(startSubScribe(deviceId, serviceId, characteristicId));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (promies.length > 0) {
|
||||
Promise.allSettled(promies).then((results) => {
|
||||
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === "fulfilled") {
|
||||
console.log(`操作${index + 1}成功:`, result.value);
|
||||
} else {
|
||||
console.log(`操作${index + 1}失败:`, result.reason
|
||||
.message);
|
||||
}
|
||||
});
|
||||
|
||||
resolve();
|
||||
}).catch((ex) => {
|
||||
reject(ex);
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}, 20);
|
||||
|
||||
@ -631,17 +680,19 @@ class BleHelper {
|
||||
|
||||
//获取服务
|
||||
getService(id, targetServiceId, writeCharId, notifyCharId) {
|
||||
|
||||
if (!targetServiceId) {
|
||||
targetServiceId = "FFE0";
|
||||
targetServiceId = "xx"; // "FFE0";
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
var repeatCnt = 0;
|
||||
var startgetService = () => {
|
||||
|
||||
uni.getBLEDeviceServices({
|
||||
deviceId: id,
|
||||
success: (res) => {
|
||||
if (res.services && res.services.length > 0) {
|
||||
////console.log("获取到服务:" + JSON.stringify(res));
|
||||
console.log("获取到服务:" + JSON.stringify(res));
|
||||
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == id) {
|
||||
@ -650,27 +701,44 @@ class BleHelper {
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey,
|
||||
this.data.LinkedList);
|
||||
|
||||
var promises = [];
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
let service = res.services[i];
|
||||
if (service.uuid.indexOf(targetServiceId) > -1) {
|
||||
let se = res.services.find((v) => {
|
||||
return v.uuid.indexOf(targetServiceId) > -1;
|
||||
});
|
||||
if (se) {
|
||||
promises.push(this.getFeatrus(id, se.uuid, writeCharId,
|
||||
notifyCharId));
|
||||
} else {
|
||||
for (var i = 0; i < res.services.length; i++) {
|
||||
let service = res.services[i];
|
||||
promises.push(this.getFeatrus(id, service.uuid,
|
||||
writeCharId, notifyCharId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (promises.length == 0) {
|
||||
console.log("未找到主服务");
|
||||
reject({
|
||||
msg: "未找到主服务",
|
||||
code: -1
|
||||
});
|
||||
} else {
|
||||
|
||||
Promise.all(promises)
|
||||
.then(results => {
|
||||
////console.log('所有操作成功完成', results);
|
||||
|
||||
return this.subScribe(id, true);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('所有操作成功完成', res);
|
||||
console.log("LinkedList=", this.data
|
||||
.LinkedList);
|
||||
resolve();
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("errrr", error);
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
@ -712,25 +780,50 @@ class BleHelper {
|
||||
deviceId: id,
|
||||
serviceId: serviceId,
|
||||
success: (res) => {
|
||||
////console.log("获取到特征:" + JSON.stringify(res));
|
||||
|
||||
console.log("获取到特征:" + JSON.stringify(res));
|
||||
res.characteristics.forEach((v) => {
|
||||
v.serviceId = serviceId;
|
||||
});
|
||||
//写特征
|
||||
let writeChar = res.characteristics.find(char =>
|
||||
char.uuid.indexOf(writeCharId) > -1
|
||||
);
|
||||
let writeChar = res.characteristics.find(char => {
|
||||
return char.uuid.indexOf(writeCharId) > -1
|
||||
});
|
||||
if (!writeChar) {
|
||||
writeChar = res.characteristics.find(char => {
|
||||
return char.properties.write;
|
||||
});
|
||||
}
|
||||
//通知特征
|
||||
let notiChar = res.characteristics.find(char =>
|
||||
char.uuid.indexOf(notifyCharId) > -1
|
||||
);
|
||||
|
||||
let notiChar = res.characteristics.find(char => {
|
||||
return char.uuid.indexOf(notifyCharId) > -1;
|
||||
});
|
||||
if (!notiChar) {
|
||||
notiChar = res.characteristics.find(char => {
|
||||
return char.properties.notify;
|
||||
});
|
||||
}
|
||||
this.data.LinkedList.find(function(v) {
|
||||
if (v.deviceId == id) {
|
||||
if (!v.Characteristics) {
|
||||
v.Characteristics = [];
|
||||
}
|
||||
v.Characteristics = v.Characteristics.concat(res
|
||||
.characteristics);
|
||||
|
||||
for (var i = 0; i < res.characteristics.length; i++) {
|
||||
let item = res.characteristics[i];
|
||||
let flag = false;
|
||||
for (var j = 0; j < v.Characteristics.length; j++) {
|
||||
let charact = v.Characteristics[j];
|
||||
if (charact.uuid == item.uuid) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
v.Characteristics.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (writeChar) {
|
||||
v.writeServiceId = serviceId;
|
||||
v.wirteCharactId = writeChar.uuid;
|
||||
@ -740,10 +833,12 @@ class BleHelper {
|
||||
v.notifyServiceid = serviceId;
|
||||
v.notifyCharactId = notiChar.uuid;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
this.subScribe(id, true);
|
||||
|
||||
|
||||
uni.setStorageSync(this.StorageKey, this.data.LinkedList);
|
||||
resolve(res);
|
||||
@ -762,10 +857,10 @@ class BleHelper {
|
||||
this.StopSearch();
|
||||
|
||||
if (!writeCharId) {
|
||||
writeCharId = "FFE1";
|
||||
writeCharId = "xxxx"; // "FFE1";
|
||||
}
|
||||
if (!notifyCharId) {
|
||||
notifyCharId = "FFE2";
|
||||
notifyCharId = "xxxxx"; // "FFE2";
|
||||
}
|
||||
|
||||
|
||||
@ -788,7 +883,7 @@ class BleHelper {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (fIndex > -1 && f?.Linked) {
|
||||
////console.log("当前已连接,跳过其他步骤")
|
||||
console.log("当前已连接,跳过其他步骤")
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
@ -798,7 +893,7 @@ class BleHelper {
|
||||
timeout: 5000,
|
||||
success: (info) => {
|
||||
|
||||
console.log("新连接成功");
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
this.getLinkBlue().then((arr) => {
|
||||
let cr = arr.devices.find(c => {
|
||||
if (c.deviceId == deviceId) {
|
||||
@ -860,7 +955,7 @@ class BleHelper {
|
||||
}).then((res) => {
|
||||
////console.log("11111111");
|
||||
if (res) { //新连接
|
||||
////console.log("开始获取服务")
|
||||
console.log("开始获取服务")
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId); //获取服务
|
||||
} else { //已连接过,直接订阅消息
|
||||
@ -1058,20 +1153,20 @@ class BleHelper {
|
||||
//将点阵数据转换成RGB565
|
||||
convertToRGB565(pixels, type) {
|
||||
const result = new Uint16Array(pixels.length / 4);
|
||||
let index = 0;
|
||||
let index = 0;
|
||||
for (let i = 0; i < pixels.length; i += 4) {
|
||||
let r = pixels[i];
|
||||
let g = pixels[i + 1];
|
||||
let b = pixels[i + 2];
|
||||
|
||||
|
||||
let rgb565 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
let bgr565 = (b >> 3) | ((g & 0xFC) << 3) | ((r & 0xF8) << 8);
|
||||
if(type=='bgr'){
|
||||
if (type == 'bgr') {
|
||||
result[index++] = bgr565;
|
||||
}else{
|
||||
} else {
|
||||
result[index++] = rgb565;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const BASE_URL = 'http://192.168.110.54:8000';
|
||||
const BASE_URL = 'http://192.168.110.169:8000';
|
||||
const request = (options) => {
|
||||
console.log("options"+JSON.stringify(options))
|
||||
return new Promise((resolve, reject) => {
|
||||
|