增加手动上传,修改新蓝牙不稳定问题

This commit is contained in:
liuwu 2023-12-11 10:31:40 +08:00
parent e3bee41bf9
commit 8717e992a6
4 changed files with 24 additions and 9 deletions

View File

@ -529,6 +529,7 @@
document.getElementById('nextCowshed').setAttribute("class", 'btnc mui-btn-success flex'); document.getElementById('nextCowshed').setAttribute("class", 'btnc mui-btn-success flex');
connectTimes = 0; connectTimes = 0;
text = '设备已连接'; text = '设备已连接';
api.hideProgress();
console.log('主机端连接成功') console.log('主机端连接成功')
ble.setMtu({ ble.setMtu({
peripheralUUID: param.peripheralUUID, peripheralUUID: param.peripheralUUID,

View File

@ -186,6 +186,7 @@
var _outerRadius = 215; var _outerRadius = 215;
var _innerRadius = 185; var _innerRadius = 185;
var feedName; var feedName;
var remark = '手动上传';
var templateName; var templateName;
var templetType; var templetType;
var _pointerInnerRadius = 120; var _pointerInnerRadius = 120;

View File

@ -122,16 +122,22 @@ function connect(param) {
}); });
ble.connect(param, function (ret, err) { ble.connect(param, function (ret, err) {
if (ret.status) { if (ret.status) {
wifiDom.innerHTML = '已连接';
api.hideProgress();
connetcedStatus = true connetcedStatus = true
// 缓存蓝牙设备uuid方便自动连接 // 缓存蓝牙设备uuid方便自动连接
api.setPrefs({ api.setPrefs({
key: 'uuid', key: 'uuid',
value: param.peripheralUUID value: param.peripheralUUID
}); });
wifiDom.innerHTML = '已连接'; if (connectTimes>0){
addNotice(1,'#02a7f0',sbId + '主机端第'+connectTimes+'次重连成功');
}else {
addNotice(1,'#02a7f0',sbId + '主机端初始化连接成功');
}
connectTimes = 0; connectTimes = 0;
document.getElementById('text').innerHTML = '设备已连接'; document.getElementById('text').innerHTML = '设备已连接';
addNotice(1,'#02a7f0',sbId + '主机端连接成功'+uuid);
text = '设备已连接'; text = '设备已连接';
console.log('主机端连接成功') console.log('主机端连接成功')
ble.setMtu({ ble.setMtu({
@ -146,14 +152,17 @@ function connect(param) {
} }
}); });
}else { }else {
connetcedStatus = false
connectTimes ++;
console.log('主机端连接失败'+connectTimes+' '+uuid)
if(connectTimes%50 === 0 || connectTimes === 1){
addNotice(4,'red',sbId + '主机端连接失败'+connectTimes+'次 '+uuid);
}
wifiDom.innerHTML = '连接失败'; wifiDom.innerHTML = '连接失败';
api.hideProgress(); api.hideProgress();
connetcedStatus = false
if (connectTimes > 0){
if(connectTimes%10 === 0){
addNotice(4,'red',sbId + '主机端第'+connectTimes+'次重连失败');
}
}else {
addNotice(4,'red',sbId + '主机端连接失败,开始尝试重连');
}
connectTimes ++;
setTimeout(function (){ setTimeout(function (){
if (!connetcedStatus && uuid && feedStatus){ if (!connetcedStatus && uuid && feedStatus){
console.log("连接失败!尝试重连" + uuid); console.log("连接失败!尝试重连" + uuid);
@ -384,6 +393,7 @@ function discoverService(param) {
if (weightDataFilter.dataBuffer.length === weightSize) { if (weightDataFilter.dataBuffer.length === weightSize) {
console.log("重量稳定", currTimeFn(new Date())); console.log("重量稳定", currTimeFn(new Date()));
weightDataFilter.dataBuffer = [] weightDataFilter.dataBuffer = []
remark = '自动跳转'
document.getElementById('submitData').click(); document.getElementById('submitData').click();
} }
}else if(_feedNum > _planSum && (allowAuto || weightBeforefix === '1')){ }else if(_feedNum > _planSum && (allowAuto || weightBeforefix === '1')){
@ -393,6 +403,7 @@ function discoverService(param) {
if (weightDataFilter.dataBuffer.length === weightSize) { if (weightDataFilter.dataBuffer.length === weightSize) {
console.log("重量稳定", currTimeFn(new Date())); console.log("重量稳定", currTimeFn(new Date()));
weightDataFilter.dataBuffer = [] weightDataFilter.dataBuffer = []
remark = '自动跳转'
document.getElementById('submitData').click(); document.getElementById('submitData').click();
} }
} }
@ -451,7 +462,7 @@ function setNotify(param, callback) {
ble.setNotify(param, function (ret) { ble.setNotify(param, function (ret) {
var value = ret.characteristic.value; var value = ret.characteristic.value;
// if (ret && value.indexOf('ff01') !== -1) { // if (ret && value.indexOf('ff01') !== -1) {
if (ret && value.substr(0,4) === 'ff01') { if (ret && value.startsWith("ff01") && value.length > 8){
var wei = value.substr(8, value.length-8); var wei = value.substr(8, value.length-8);
// var wei = value.substr(12, 12); // var wei = value.substr(12, 12);
// wei = Math.round(Number(hex2a(wei))); // wei = Math.round(Number(hex2a(wei)));

View File

@ -44,6 +44,7 @@ function submitData() {
var param = { var param = {
dateOf: dateOf, dateOf: dateOf,
name: feedName, name: feedName,
remark: remark,
planWeight: Number(_planSum), planWeight: Number(_planSum),
rationCowAmount: feedList[feedIndex] ? feedList[feedIndex].cow : 0, rationCowAmount: feedList[feedIndex] ? feedList[feedIndex].cow : 0,
batchRation: feedList[feedIndex].batchRation, batchRation: feedList[feedIndex].batchRation,
@ -74,6 +75,7 @@ function submitData() {
}, function (ret, err) { }, function (ret, err) {
if (ret && ret.code == 200) { if (ret && ret.code == 200) {
mui.toast(param.name + " 已上传 " + param.feedWeight,{duration:3500,type:'div'}); mui.toast(param.name + " 已上传 " + param.feedWeight,{duration:3500,type:'div'});
remark = '手动上传'
beforeWeight = nowWeight; beforeWeight = nowWeight;
// document.getElementById('beforeWeight').innerHTML = '称实时/装料前:' + nowWeight + '/' + beforeWeight; // document.getElementById('beforeWeight').innerHTML = '称实时/装料前:' + nowWeight + '/' + beforeWeight;
feedIndex = feedIndex + 1; feedIndex = feedIndex + 1;