diff --git a/common/http.interceptor.js b/common/http.interceptor.js
index 7b57acb..daac3c7 100644
--- a/common/http.interceptor.js
+++ b/common/http.interceptor.js
@@ -21,7 +21,7 @@ const install = (Vue, vm) => {
// });
Vue.prototype.$u.http.setConfig({
baseUrl: 'https://yxd.ccttiot.com/prod-api',
- // baseUrl: 'http://192.168.1.3:8081',
+ // baseUrl: 'http://192.168.1.5:8081',
loadingText: '努力加载中~',
loadingTime: 800,
// 设置自定义头部content-type
diff --git a/components/blufi/xBlufi-wx-impl.js b/components/blufi/xBlufi-wx-impl.js
index c8b0c52..cbea81f 100644
--- a/components/blufi/xBlufi-wx-impl.js
+++ b/components/blufi/xBlufi-wx-impl.js
@@ -577,7 +577,7 @@ function write_cmd_program(deviceId, serviceId, characteristicId, data) {
var dv = 0;
let result;
console.log("更新122")
- const mtu = 212;
+ const mtu = 512;
uni.setBLEMTU({
deviceId: self
.data
@@ -664,7 +664,7 @@ function write_cmd_program_dd(deviceId, serviceId, characteristicId, data) {
var dv = 0;
let result;
console.log("更新122")
- const mtu = 212;
+ const mtu = 512;
uni.setBLEMTU({
deviceId: self
.data
@@ -752,7 +752,7 @@ function write_cmd_program_zy(deviceId, serviceId, characteristicId, data) {
var dv = 0;
let result;
console.log("更新122")
- const mtu = 212;
+ const mtu = 512;
uni.setBLEMTU({
deviceId: self
.data
@@ -839,7 +839,7 @@ function write_cmd_program_yk(deviceId, serviceId, characteristicId, data) {
var dv = 0;
let result;
console.log("更新122")
- const mtu = 212;
+ const mtu = 512;
uni.setBLEMTU({
deviceId: self
.data
@@ -927,7 +927,7 @@ function write_cmd_program_fg(web, deviceId, serviceId, characteristicId, data)
var dv = 0;
let result;
console.log("更新122")
- const mtu = 212;
+ const mtu = 512;
uni.setBLEMTU({
deviceId: self
.data
@@ -1130,24 +1130,24 @@ function writeRouterSsid(deviceId, serviceId, characteristicId, data) {
},
fail: function (res) { //console.log(257);
}
- });
+ })
}
function writeDevicePwd(deviceId, serviceId, characteristicId, data) {
- var obj = {},
+ var obj = {}
frameControl = 0;
sequenceControl = parseInt(sequenceControl) + 1;
if (!util._isEmpty(data)) {
- obj = util.isSubcontractor(data, self.data.isChecksum, sequenceControl, self.data.isEncrypt);
- frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+ obj = util.isSubcontractor(data, self.data.isChecksum, sequenceControl, self.data.isEncrypt)
+ frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag)
} else {
- var pwdData = getCharCodeat(self.data.password);
- obj = util.isSubcontractor(pwdData, self.data.isChecksum, sequenceControl, self.data.isEncrypt);
- frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+ var pwdData = getCharCodeat(self.data.password)
+ obj = util.isSubcontractor(pwdData, self.data.isChecksum, sequenceControl, self.data.isEncrypt)
+ frameControl = util.getFrameCTRLValue(self.data.isEncrypt, self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag)
}
- var defaultData = util.encrypt(aesjs, self.data.md5Key, sequenceControl, obj.lenData, true);
+ var defaultData = util.encrypt(aesjs, self.data.md5Key, sequenceControl, obj.lenData, true)
var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_SET_PWD, frameControl, sequenceControl, obj.len,
defaultData);
var typedArray = new Uint8Array(value);
@@ -1169,8 +1169,8 @@ function writeDevicePwd(deviceId, serviceId, characteristicId, data) {
function writeDeviceEnd(deviceId, serviceId, characteristicId) {
sequenceControl = parseInt(sequenceControl) + 1;
- var frameControl = util.getFrameCTRLValue(self.data.isEncrypt, false, util.DIRECTION_OUTPUT, false, false);
- var value = util.writeData(self.data.PACKAGE_CONTROL_VALUE, util.SUBTYPE_END, frameControl, sequenceControl, 0, null);
+ var frameControl = util.getFrameCTRLValue(self.data.isEncrypt, false, util.DIRECTION_OUTPUT, false, false)
+ var value = util.writeData(self.data.PACKAGE_CONTROL_VALUE, util.SUBTYPE_END, frameControl, sequenceControl, 0, null)
var typedArray = new Uint8Array(value);
uni.writeBLECharacteristicValue({
deviceId: deviceId,
@@ -1244,6 +1244,7 @@ function init() {
// && devices.devices[0].indexOf('TOOL') == -1
&& devices.devices[0].name.indexOf('WATE') == -1
&& devices.devices[0].name.indexOf('SMSJ') == -1
+ && devices.devices[0].name.indexOf('CCYK') == -1
// && devices.devices[0].name.indexOf('BBLE') == -1
// && devices.devices[0].name.indexOf('FXLE') == -1
// && devices.devices[0].name.indexOf('CCYK') == -1
@@ -1368,7 +1369,7 @@ function init() {
}
});
mDeviceEvent.listenConnectBle(true, function (options) {
- console.log("我要连接?", options.isStart);
+ console.log("我要连接?", options.isStart,options);
if (options.isStart) uni.createBLEConnection({
deviceId: options.deviceId,
success: function (res) {
@@ -1452,7 +1453,7 @@ function init() {
self.data.deviceId = options.deviceId;
mac_id = options.deviceId;
setTimeout(() => {
- var mtu = 212
+ var mtu = 512
uni.setBLEMTU({
deviceId: self
.data
@@ -1515,7 +1516,7 @@ setTimeout(() => {
success: function(res) {
console.log("成功", res)
writeCutomsData(self.data.deviceId, self.data.service_uuid, self.data.characteristic_write_uuid, "get_fw");
- const mtu = 212;
+ const mtu = 512;
uni.onBLECharacteristicValueChange(function(res) {
var my_str = Utf8ArrayToStr(res.value)
if(my_str.indexOf("wifi_ok") != -1)
diff --git a/page_user/dingshi.vue b/page_user/dingshi.vue
index 098fc3f..845afec 100644
--- a/page_user/dingshi.vue
+++ b/page_user/dingshi.vue
@@ -201,15 +201,15 @@
for (let key in this.list) {
if (this.list.hasOwnProperty(key)) {
// 获取当前数组
- let arr = this.list[key];
+ let arr = this.list[key]
// 只转换开关状态(values[3])为布尔值
- arr[3] = arr[3] === 1;
+ arr[3] = arr[3] === 1
}
}
console.log(this.list,'listlistlist')
} else {
this.csbobj = JSON.parse(option.list)
- console.log(this.csbobj,'chobjchobj');
+ console.log(this.csbobj,'chobjchobj')
this.shi = this.csbobj.hour
this.fen = this.csbobj.minute
this.miao = this.csbobj.second
@@ -231,13 +231,13 @@
this.$u.get(`/app/getDeviceInfo/${this.shebid}`).then(res => {
if (res.code == 200) {
if(this.pre != 'WATER'){
- this.shi = res.data.gatewayReturnParams.h.value
- this.fen = res.data.gatewayReturnParams.m.value < 10 ? '0' + res.data.gatewayReturnParams.m.value : res.data.gatewayReturnParams.m.value
- this.miao = res.data.gatewayReturnParams.t.value
- this.tian = res.data.gatewayReturnParams.d.value
+ this.shi = res.data.parameters.h.value
+ this.fen = res.data.parameters.m.value < 10 ? '0' + res.data.parameters.m.value : res.data.parameters.m.value
+ this.miao = res.data.parameters.t.value
+ this.tian = res.data.parameters.d.value
} else {
// 单阀 WATER,从后台字段 h1/m1/s1/o1...(以及可选 d1..d6) 组装展示结构
- const params = res.data.gatewayReturnParams
+ const params = res.data.parameters
const mapped = this.buildListFromBackend(params)
// u-switch 需要布尔值,已在构建阶段转换
this.list = mapped
@@ -276,44 +276,43 @@
},
// 点击选择浇水时长
btnshowtwo(){
- console.log(this.defaultTimeLength,this.minute,this.second,'111');
+ console.log(this.defaultTimeLength,this.minute,this.second,'111')
this.defaultTimeLength = '00' + ':' + this.minute + ':' + this.second
- console.log(this.defaultTimeLength,this.minute,this.second,'222');
+ console.log(this.defaultTimeLength,this.minute,this.second,'222')
this.shows = true
},
// 显示加载
showLoading() {
- this.isLoading = true;
+ this.isLoading = true
},
-
// 格式化间隔天数显示
formatInterval(days) {
- return days <= 1 ? '每天浇一次' : '每' + days + '天浇一次';
+ return days <= 1 ? '每天浇一次' : '每' + days + '天浇一次'
},
// 隐藏加载
hideLoading() {
- this.isLoading = false;
+ this.isLoading = false
setTimeout(() => {
- this.isLoading = false;
- }, 500);
+ this.isLoading = false
+ }, 500)
},
// 重试机制
async retryOperation() {
if (this.retryCount < this.maxRetries) {
- this.retryCount++;
- await this.delay(1000);
+ this.retryCount++
+ await this.delay(1000)
if (this.lastOperation) {
- this.lastOperation();
+ this.lastOperation()
}
} else {
- this.hideLoading();
+ this.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
- });
- this.retryCount = 0;
+ })
+ this.retryCount = 0
}
},
diff --git a/page_user/lanya.vue b/page_user/lanya.vue
index 69517a0..161b71f 100644
--- a/page_user/lanya.vue
+++ b/page_user/lanya.vue
@@ -26,8 +26,47 @@
MAC:{{item.mac == undefined ? item.name.slice(-12) : item.mac}}
-
- 信号:{{item.ssid == undefined ? '--' : item.ssid}}
+
+ 信号:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/page_user/upload.vue b/page_user/upload.vue
index d269e15..4432505 100644
--- a/page_user/upload.vue
+++ b/page_user/upload.vue
@@ -115,7 +115,8 @@
xctime:'--',
version:'',
xinpin:'',
- imgpic:''
+ imgpic:'',
+ varflag:''
}
},
// 分享到好友(会话)
@@ -134,6 +135,7 @@
}
},
onLoad(option) {
+ this.varflag = option.varflag
console.log(option,'0000');
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
xBlufi.notifySendCustomData({
@@ -141,8 +143,8 @@
})
this.deviceid = option.deviceid
this.imgpic = option.img
+ this.xinpin = option.xipin
if(option.xctime != '--'){
- // this.xinpin = option.xipin
if(option.xctime != '--' && option.ver){
this.ver = 'V' + option.ver.slice(3)
this.xctime = option.xctime
@@ -168,25 +170,51 @@
},
methods: {
btnxip(){
- if(this.xinpin == '' || this.xinpin == null){
- uni.showToast({
- title: '请先连接蓝牙拿取息屏时间',
- icon: 'none',
- duration: 2000
- })
- }else{
- this.xpshow = true
- }
+ this.xpshow = true
+ // if(this.xinpin == '' || this.xinpin == null){
+ // uni.showToast({
+ // title: '请先连接蓝牙拿取息屏时间',
+ // icon: 'none',
+ // duration: 2000
+ // })
+ // }else{
+ // }
},
// 设置息屏时间
confirm(e) {
this.xinpin = Number(e.minute * 60) + Number(e.second)
- xBlufi.notifySendCustomData({
- customData: '11sleep' + this.xinpin + '@'
- })
- xBlufi.notifySendCustomData({
- customData: '11get'
- })
+ if(this.varflag == 3){
+ xBlufi.notifySendCustomData({
+ customData: '11sleep' + this.xinpin + '@'
+ })
+ xBlufi.notifySendCustomData({
+ customData: '11get'
+ })
+ }else{
+ let parameters = {
+ time: this.xinpin
+ }
+ let data = {
+ deviceId:this.deviceid,
+ instructionKey:'sleep',
+ parameters:parameters
+ }
+ this.$u.post(`/app/sendCommandByGateway`,data).then(res => {
+ if (res.code == 200) {
+ uni.showToast({
+ title: '设置成功',
+ icon: 'success',
+ duration:2000
+ })
+ }else{
+ uni.showToast({
+ title: res.msg,
+ icon: 'none',
+ duration:2000
+ })
+ }
+ })
+ }
},
// 解绑设备按钮
btnjiebang() {
@@ -427,7 +455,7 @@
}
})
console.log(showObject,'showObjectshowObject');
- this.xinpin = showObject.showArray[showObject.showArray.length - 2]
+ this.xinpin = showObject.showArray[showObject.showArray.length - 1]
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 3832c99..34c1245 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -5,6 +5,14 @@
+
+
+
+
+
+ 正在加载中...
+
+
-
+
连接中
-
+
已连接
+
+ {{vatatxt}}
+
@@ -323,11 +334,11 @@
启动时间
-
+
{{csbobj.hour == undefined ? '--' : csbobj.hour + ':'}}{{csbobj.minute == undefined ? '' : csbobj.minute}}
- {{zaixianobj.h.value == undefined ? '-' : zaixianobj.h.value + ':'}}{{zaixianobj.m.value == undefined ? '-' : zaixianobj.m.value < 10 ? '0' + zaixianobj.m.value : zaixianobj.m.value}}
+ {{zaixianobj.h.value == undefined ? '-' : zaixianobj.h.value + ':'}}{{zaixianobj.m.value == undefined ? '-' : zaixianobj.m.value}}
@@ -335,7 +346,7 @@
工作时长
-
+
{{csbobj.second == undefined ? '--' : csbobj.second + '秒'}}
@@ -347,7 +358,7 @@
间隔天数
-
+
{{csbobj.day == undefined ? '--' : csbobj.day + '天'}}
@@ -424,9 +435,12 @@
- 距离下次:{{xctime}}
+
+
+ 上次浇水时长:{{jsobj.sprayingTime == undefined ? '--' : jsobj.sprayingTime + 's'}}
+ 上次浇水:{{jsobj.lastWaterTime == undefined ? '--' : jsobj.sprayingTime}}
@@ -482,11 +496,17 @@
-
+
+
+
@@ -496,6 +516,10 @@
data() {
return {
timeflag:false,
+ // 最近一次成功上传的时间戳(毫秒)
+ lastUploadTs: 0,
+ // 最近一次获取电量的时间戳(毫秒)
+ lastPowerTs: 0,
one: false,
ones: true,
two: false,
@@ -530,7 +554,6 @@
minute: '00',
second: '10',
hasShownVersionAlert: false,
- devicesList: [],
deviceId: '',
name: '',
mac: '',
@@ -562,7 +585,7 @@
disconnectTimer: null,
devicetime:'',
imgpic:'',
- xinp:'30',
+ xinp:'',
version:'',
jiance:false,
shibainum:0,
@@ -574,7 +597,10 @@
dianya:0,
sydl:'--',
zaixianobj:{},
- modelId:''
+ modelId:'',
+ jsobj:{},
+ isLoading: false ,// 设备请求加载状态
+ vatatxt:''
}
},
// 分享到好友(会话)
@@ -595,13 +621,12 @@
},
onLoad() {
xBlufi.initXBlufi(1)
- // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
- xBlufi.notifyStartDiscoverBle({
- 'isStart': true
- })
},
onShow() {
- xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
+ // xBlufi.notifyStartDiscoverBle({
+ // 'isStart': true
+ // })
+ // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
// 请求个人信息
this.getinfo()
this.getshuju() // 页面加载时启动定时器
@@ -626,19 +651,26 @@
getsj(){
this.$u.get(`/app/getDeviceInfo/${this.shebid}`).then(res => {
if (res.code == 200) {
- this.zaixianobj = res.data.gatewayReturnParams
+ this.zaixianobj = res.data.parameters
this.modelId = res.data.modelId
console.log(this.vardataflag,this.zaixianobj);
- if(res.data.gatewayReturnParams.yudi.value){
- this.yschecked = res.data.gatewayReturnParams.yudi.value == 0 ? true : false
- }
- if(res.data.gatewayReturnParams.lock.value){
- this.etchecked = res.data.gatewayReturnParams.lock.value == 0 ? true : false
- }
// 非蓝牙模式时,用后台数据组装渲染结构
if(this.pre === 'WATER' && this.vardataflag != 3){
this.ver_data = this.buildVerDataFromBackend(this.zaixianobj)
}
+ if(this.pre === 'pre' && this.vardataflag != 3){
+ this.ver_data = this.buildVerDataFromBackend(this.zaixianobj)
+ console.log(this.ver_data);
+ }
+ if (res.data && res.data.parameters && res.data.parameters.xinp !== undefined) {
+ this.xinp = res.data.parameters.xinp.value == undefined ? '--' : res.data.parameters.xinp.value
+ }
+ if (res.data && res.data.parameters && res.data.parameters.yudi !== undefined) {
+ this.yschecked = res.data.parameters.yudi.value == 0 ? true : false
+ }
+ if (res.data && res.data.parameters && res.data.parameters.lock !== undefined) {
+ this.etchecked = res.data.parameters.lock.value == 0 ? true : false
+ }
}
})
},
@@ -744,14 +776,18 @@
},
// 获取用户信息
getinfo() {
+ this.isLoading = true // 开始加载
this.$u.get(`/appVerify/profile`).then((res) => {
if (res.code == 200) {
this.userobj = res.data
// 根据用户id获取当前用户
this.getlist()
}else if(res.code == 401){
+ this.isLoading = false // 请求失败时隐藏加载状态
this.jmlogin()
}
+ }).catch(() => {
+ this.isLoading = false // 请求异常时隐藏加载状态
})
},
// 获取设备列表
@@ -763,104 +799,111 @@
this.devicelist = res.data
this.imgpic = res.data[0].modelPicture
this.mac = res.data[0].mac
- setTimeout(()=>{
- if(this.vardataflag == 1){
- this.btnlj()
- }
- },1000)
+ // setTimeout(()=>{
+ // if(this.vardataflag != 3){
+ // this.btnlj()
+ // }
+ // },1000)
this.pre = res.data[0].pre
- this.deviceId = res.data[0].mac.match(/.{2}/g).reverse().join(':')
+ // this.deviceId = res.data[0].mac.match(/.{2}/g).reverse().join(':')
this.user = res.data[0]
this.shebid = res.data[0].deviceId
this.getbanbens()
+ this.getscjsjl()
setTimeout(()=>{
this.getsj()
},1000)
}else{
this.bjflag = true
}
+ this.isLoading = false // 请求完成后隐藏加载状态
}
+ }).catch(() => {
+ this.isLoading = false // 请求异常时隐藏加载状态
})
},
// 点击连接蓝牙函数
btnlj() {
- if(this.jiance == true){
- xBlufi.initXBlufi(1)
- xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
- xBlufi.notifyStartDiscoverBle({
- 'isStart': true
- })
- this.vardataflag = 2
- this.findDevice()
- }else{
- xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
- this.vardataflag = 2
- this.findDevice()
- }
+ this.shibainum = 0
+ xBlufi.initXBlufi(1)
+ xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
+ xBlufi.notifyStartDiscoverBle({
+ 'isStart': true
+ })
+ this.vardataflag = 2
+ this.findDevice()
+ // if(this.jiance == true){
+ // xBlufi.initXBlufi(1)
+ // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
+ // xBlufi.notifyStartDiscoverBle({
+ // 'isStart': true
+ // })
+ // this.vardataflag = 2
+ // this.findDevice()
+ // }else{
+ // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
+ // xBlufi.notifyStartDiscoverBle({ 'isStart': true })
+ // this.vardataflag = 2
+ // this.findDevice()
+ // }
},
// ios递归函数匹配
findDevice() {
- // 使用 find 方法查找匹配的设备
- const matchedDevice = this.devicesarr.find(device => {
- console.log(device.name, this.mac, '111')
- return device.name.slice(-12) == this.mac.slice(-12)
- })
- if (matchedDevice) {
- // 找到匹配的设备
- xBlufi.notifyStartDiscoverBle({
- 'isStart': false
- })
- xBlufi.notifyConnectBle({
- isStart: true,
- deviceId: matchedDevice.deviceId,
- name: matchedDevice.name
- })
- this.deviceId = matchedDevice.deviceId
- this.name = matchedDevice.name
- console.log(this.deviceId, '11221')
- } else {
- console.log("未找到匹配的设备,继续查找...")
- setTimeout(this.findDevice.bind(this), 1000) // 使用 bind 保持 this 上下文
- }
- let that = this
- const findDevices = () => {
- that.ver_dataflag = 2
- const matchedDevice = that.devicesarr.find(device => {
- if (device.name) {
- return device.localName.slice(-12) == that.mac.slice(-12)
- }
- })
- if (matchedDevice) {
+ let that = this;
+ const findDevices = () => {
+ console.log(that.shibainum,'失败次数');
+ // 如果已经尝试了10次及以上,直接返回不执行
+ if (that.shibainum > 10) {
+ that.vardataflag = 1
xBlufi.notifyStartDiscoverBle({
- 'isStart': false
- })
- xBlufi.notifyConnectBle({
- isStart: true,
- deviceId: matchedDevice.deviceId,
- name: matchedDevice.name
- })
- that.deviceid = matchedDevice.deviceId
- that.devicename = matchedDevice.name
- setTimeout(() => {
- console.log(this.ver_dataflag, '连接状态2');
- if (that.ver_dataflag == 3) {
-
- } else {
- that.ver_dataflag = 1
- that.shibainum = 0
- }
- }, 4000)
- } else {
- if (that.shibainum < 3) {
- that.shibainum++
- that.findDeviceTimer = setTimeout(findDevices.bind(that), 1000) // 使用 bind 保持 this 上下文
- } else {
- that.ver_dataflag = 1
- that.shibainum = 0
- }
- }
- }
- findDevices()
+ 'isStart': false
+ });
+ // that.shibainum = 0;
+ return;
+ }
+ // that.vardataflag = 2
+ that.vatatxt = '设备查找中...';
+ const matchedDevice = that.devicesarr.find(device => {
+ if (device.name) {
+ return device.name.slice(-12) === that.mac.slice(-12);
+ }
+ });
+ if (matchedDevice) {
+ // 找到设备的处理逻辑...
+ that.vatatxt = '查找成功,配对中...';
+ xBlufi.notifyStartDiscoverBle({
+ 'isStart': false
+ });
+ console.log(matchedDevice, '找到匹配设备');
+ xBlufi.notifyConnectBle({
+ isStart: true,
+ deviceId: matchedDevice.deviceId,
+ name: matchedDevice.name
+ });
+ that.deviceId = matchedDevice.deviceId;
+ setTimeout(() => {
+ console.log(that.vardataflag, '连接状态2');
+ if (that.vardataflag !== 3) {
+ that.vardataflag = 1
+ that.shibainum = 0;
+ }
+ }, 4000);
+ } else {
+ // 未找到设备,递增计数器并继续尝试
+ that.shibainum++;
+ // 只有在还没到10次时才设置定时器继续查找
+ if (that.shibainum < 10) {
+ that.findDeviceTimer = setTimeout(findDevices, 1000);
+ } else {
+ // 达到3次尝试,重置状态
+ that.vardataflag = 1
+ that.shibainum = 0;
+ }
+ }
+ };
+ // 重置计数器后开始查找
+ // that.shibainum = 0;
+ findDevices();
},
// 获取附近蓝牙设备列表
funListenDeviceMsgEvent: function(options) {
@@ -870,11 +913,20 @@
this.vardataflag = 1
this.clearDisconnectTimer()
console.log('111111111','断断断');
+ // const pages = getCurrentPages();
+ // const currentPage = pages[pages.length - 1];
+
+ // console.log("当前页面路径:", currentPage.route);
+ // console.log("当前页面参数:", currentPage.options);
+ // wx.reLaunch({
+ // url: `/${currentPage.route}`
+ // });
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) {
this.devicesarr = options.data
+ // console.log('搜索的附近设备列表',this.devicesarr);
}
break;
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
@@ -888,14 +940,18 @@
this.vardataflag = 3
this.initDisconnectTimer()
this.datalist = ''
- this.startDataTimeoutTimer()
+ // this.startDataTimeoutTimer()
xBlufi.notifySendCustomData({
customData: "11get"
})
}else{
+ this.vatatxt = '蓝牙服务发现失败,请重试'
console.log('服务发现失败:', options.data);
- this.vardataflag = 1
this.clearDisconnectTimer()
+ this.jiance = true
+ setTimeout(()=>{
+ this.vardataflag = 1
+ },5000)
}
break
case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
@@ -1032,8 +1088,9 @@
title: '设置中...'
})
this.devicetime = this.getCurrentTime();
+ console.log(this.devicetime);
let parameters = {
- date:this.devicetime + ';'
+ date:this.devicetime + ';'
}
let data = {
deviceId:this.shebid,
@@ -1102,11 +1159,12 @@
const hours = padZero(now.getHours()); // 时 (00-23)
const minutes = padZero(now.getMinutes()); // 分 (00-59)
const seconds = padZero(now.getSeconds()); // 秒 (00-59)
- return `${hours}:${minutes}:${seconds}`;
+ return `${hours}:${minutes}`;
},
// 点击设置当前时间
confirmtime(e){
this.devicetime = e.hour + ':' + e.minute
+ console.log(this.devicetime);
if(this.vardataflag == 3){
this.$u.get(`/app/getModelCommand/${this.modelId}?instructionKey=date`).then(res =>{
if(res.code == 200){
@@ -1371,6 +1429,27 @@
format(template, params) {
return template.replace(/\{(\w+)\}/g, (_, k) => params[k] ?? '');
},
+ // 手动浇水记录
+ getjl(){
+ let that = this
+ let data = {
+ deviceId:that.shebid,
+ sprayingTime:that.jstime
+ }
+ that.$u.post(`/app/wateringRecord`,data).then(res =>{})
+ },
+ // 请求上次浇水记录
+ getscjsjl(){
+ this.$u.get(`/app/wateringRecord/last/${this.shebid}`).then(res =>{
+ if(res.code == 200){
+ if(res.data){
+ this.jsobj = res.data
+ }else{
+ this.jsobj = {}
+ }
+ }
+ })
+ },
// 确定选择时间
btnqd() {
this.handleUserAction()
@@ -1389,6 +1468,7 @@
xBlufi.notifySendCustomData({
customData: '11' + this.format(res.data, {time: this.jstime})
})
+ this.getjl()
uni.hideLoading()
this.startTimer(this.jstime)
this.sdjsflag = false
@@ -1417,6 +1497,7 @@
icon: 'success',
duration:2000
})
+ this.getjl()
uni.hideLoading()
this.startTimer(this.jstime)
this.sdjsflag = false
@@ -1536,32 +1617,36 @@
this.xctime = '111'
}
uni.navigateTo({
- url: '/page_user/upload?deviceid=' + this.shebid + '&ver=' + this.ver + '&xctime=' + this.xctime + '&xipin=' + this.xinp + '&img=' + this.imgpic
+ url: '/page_user/upload?deviceid=' + this.shebid + '&ver=' + this.ver + '&xctime=' + this.xctime + '&xipin=' + this.xinp + '&img=' + this.imgpic + '&varflag=' + this.vardataflag
})
},
// 选择设备
btnactive(deviceId,index) {
+ // wx.closeBLEConnection({
+ // deviceId: this.mac,
+ // })
+ // xBlufi.notifyConnectBle({
+ // isStart: false,
+ // deviceId: this.deviceId,
+ // name: this.name
+ // })
+ this.isLoading = true
this.shebid = deviceId
this.zaixianobj = {}
+ this.ver = ''
+ this.jsobj = {}
this.btnxuanze()
},
// 选择确定设备 shebid
btnxuanze() {
this.$u.put(`/app/toggleDevice?userId=${this.userobj.userId}&deviceId=${this.shebid}`).then(res => {
if(res.code == 200){
- wx.closeBLEConnection({
- deviceId: this.mac,
- })
- xBlufi.notifyConnectBle({
- isStart: false,
- deviceId: this.deviceId,
- name: this.name
- })
uni.showToast({
title: res.msg,
icon: 'success',
duration: 2000
})
+ this.csbobj = {}
this.datalist = ''
this.mac = ''
this.ver_data = {}
@@ -1576,6 +1661,7 @@
this.jskeds = false
this.getshebxq()
}else{
+ this.isLoading = false
uni.showToast({
title: res.msg,
icon: 'none',
@@ -1588,20 +1674,32 @@
getshebxq(){
this.$u.get(`/app/getDeviceInfo/${this.shebid}`).then(res => {
if(res.code == 200){
+ this.pre = res.data.pre
this.mac = res.data.mac
this.modelId = res.data.modelId
console.log(this.modelId,'00000');
- if(this.vardataflag == 1){
- setTimeout(()=>{
- this.btnlj()
- },1000)
- }
- this.pre = res.data.pre
+ // if(this.vardataflag == 1){
+ // setTimeout(()=>{
+ // this.btnlj()
+ // },1000)
+ // }
this.imgpic = res.data.modelPicture
- this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
+ // this.deviceId = res.data.mac.match(/.{2}/g).reverse().join(':')
this.user = res.data
- this.getbanbens()
- // this.btnlj()
+ // setTimeout(()=>{
+ // this.getsj()
+ // },1000)
+ const pages = getCurrentPages();
+ const currentPage = pages[pages.length - 1];
+ this.isLoading = false
+ console.log("当前页面路径:", currentPage.route);
+ console.log("当前页面参数:", currentPage.options);
+ wx.reLaunch({
+ url: `/${currentPage.route}`
+ });
+ // this.getbanbens()
+ }else{
+ this.isLoading = false
}
})
},
@@ -1630,9 +1728,7 @@
const that = this
that.intervalId = setInterval(() => {
if (that.vardataflag == 3) {
- // 发送前清空数据并开启5秒看门狗
that.datalist = ''
- that.startDataTimeoutTimer()
xBlufi.notifySendCustomData({
customData: "11get"
})
@@ -1651,20 +1747,16 @@
getcsbshuju() {
// 1. 获取原始数据
const inputString = this.datalist;
-
// 2. 先处理分号(替换为逗号)
const normalizedString = inputString.replace(/;/g, ',');
-
// 3. 分割版本信息和数据部分
const parts = normalizedString.split(':');
console.log('分割结果:', parts); // 应该输出 ["ver3@p_set0", "11,5,603,99,19,9,0,"]
-
// 4. 处理数据部分(移除末尾可能的多余逗号)
let dataPart = parts[1];
if (dataPart.endsWith(',')) {
dataPart = dataPart.slice(0, -1);
}
-
// 5. 重新组合为期望的格式
const result = [parts[0], dataPart];
console.log('最终结果:', result); // ["ver3@p_set0", "11,5,603,99,19,9,0"]
@@ -1674,26 +1766,74 @@
console.log(this.ver,'ververver');
// 6. 继续您原来的处理逻辑
const timeParts = dataPart.split(',');
-
+ console.log(timeParts,'timePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimePartstimeParts');
+ this.dianya = timeParts[timeParts.length - 1]
+ this.getdianliang()
this.csbobj = {
hour: String(timeParts[0]).padStart(2, '0'),
minute: String(timeParts[1]).padStart(2, '0'),
second: timeParts[2],
day: timeParts[3]
};
-
+ console.log(this.csbobj,'4564654654584654564654654654654654621654652165');
const hours = parseInt(timeParts[4]) || 0;
const minutes = parseInt(timeParts[5]) || 0;
this.devicetime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
- this.ver_data = {...this.csbobj};
+ this.ver_data = {...this.csbobj};
+ // 生成当前时间字符串 yyyy-MM-dd HH:mm:ss
+ const now = new Date();
+ const yyyy = now.getFullYear();
+ const MM = String(now.getMonth() + 1).padStart(2, '0');
+ const dd = String(now.getDate()).padStart(2, '0');
+ const HH = String(now.getHours()).padStart(2, '0');
+ const mm = String(now.getMinutes()).padStart(2, '0');
+ const ss = String(now.getSeconds()).padStart(2, '0');
+ const at = `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
+
+ // 仅在已连接(vardataflag==3)且距离上次上传≥60秒时推送
+ console.log(this.ver_data);
+ if(this.vardataflag == 3){
+ const nowTs = Date.now();
+ if(!this.lastUploadTs || (nowTs - this.lastUploadTs) >= 2000){
+ let data = {
+ mac: this.mac,
+ params: {
+ h: {
+ value: String(this.ver_data.hour),
+ at
+ },
+ m: {
+ value: String(this.ver_data.minute),
+ at
+ },
+ t: {
+ value: String(this.ver_data.second),
+ at
+ },
+ d: {
+ value: String(this.ver_data.day),
+ at
+ },
+ }
+ }
+ data.params.xinp = { value: String(this.xinp), at }
+ this.$u.put(`/app/updateDeviceParam`, data).then(res => {}) //上传数据
+ this.lastUploadTs = nowTs;
+ }
+ }
console.log('设备时间:', this.devicetime);
},
// 获取电量
getdianliang(){
+ const nowTs = Date.now();
+ if(this.lastPowerTs && (nowTs - this.lastPowerTs) < 20000){
+ return
+ }
this.$u.get(`/app/device/remainingPower/${this.shebid}?voltage=${this.dianya / 1000}`).then(res => {
if (res.code == 200) {
this.sydl = res.data
+ this.lastPowerTs = nowTs
}
})
},
@@ -1814,6 +1954,73 @@
this.dianya = this.showobj.showArray[this.showobj.showArray.length - 1]
console.log('息屏',this.xinp,'电压',this.dianya);
this.getdianliang()
+
+ // 非 WATER 情况也按 { value, at } 结构上传(大量字段统一包装)
+ if(this.vardataflag == 3){
+ const now = new Date();
+ const yyyy = now.getFullYear();
+ const MM = String(now.getMonth() + 1).padStart(2, '0');
+ const dd = String(now.getDate()).padStart(2, '0');
+ const HH = String(now.getHours()).padStart(2, '0');
+ const mm = String(now.getMinutes()).padStart(2, '0');
+ const ss = String(now.getSeconds()).padStart(2, '0');
+ const at = `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
+ const nowTs = Date.now();
+ if(!this.lastUploadTs || (nowTs - this.lastUploadTs) >= 2000){
+ const wrapParams = (obj) => {
+ const out = {};
+ if(!obj || typeof obj !== 'object') return out;
+ Object.keys(obj).forEach((key) => {
+ const raw = obj[key];
+ const value = (raw && typeof raw === 'object' && 'value' in raw) ? raw.value : raw;
+ out[key] = { value: String(value == null ? '' : value), at };
+ });
+ return out;
+ }
+ // 当后台参数对象为空时,从 BLE 解析的 ver_data 构造 h1/m1/s1/o1/d1 ...
+ const buildParamsFromState = () => {
+ const params = {}
+ if(this.ver_data && typeof this.ver_data === 'object'){
+ for(let i = 1; i <= 6; i++){
+ const arr = this.ver_data[`p_set${i}`]
+ if(Array.isArray(arr) && arr.length >= 5){
+ params[`h${i}`] = arr[0]
+ params[`m${i}`] = arr[1]
+ params[`s${i}`] = arr[2]
+ params[`o${i}`] = arr[3]
+ params[`d${i}`] = arr[4]
+ }
+ }
+ }
+ return params
+ }
+ // 在 BLE 已连接场景,优先使用当前解析的 ver_data(p_set1..p_set6)
+ const hasVerData = (() => {
+ if(!this.ver_data || typeof this.ver_data !== 'object') return false;
+ for(let i = 1; i <= 6; i++){
+ const arr = this.ver_data[`p_set${i}`]
+ if(Array.isArray(arr) && arr.length >= 2 && (arr[0] > 0 || arr[1] > 0 || arr[2] > 0 || arr[3] > 0)){
+ return true
+ }
+ }
+ return false
+ })()
+ const hasBackend = this.zaixianobj && Object.keys(this.zaixianobj).length > 0
+ const chosenParams = hasVerData ? buildParamsFromState() : (hasBackend ? this.zaixianobj : {})
+ // 合并额外状态字段:仅保留 yudi(雨水感应)、lock(儿童锁),
+ // 按你的要求直接使用布尔:开启=false,关闭=true
+ const mergedParams = { ...chosenParams }
+ mergedParams.yudi = this.yschecked ? 0 : 1
+ mergedParams.lock = this.etchecked ? 0 : 1
+ let data = {
+ mac: this.mac,
+ params: wrapParams(mergedParams)
+ }
+ data.params.xinp = { value: String(this.xinp), at }
+ this.$u.put(`/app/updateDeviceParam`, data).then(res => {})
+ this.lastUploadTs = nowTs;
+ }
+ }
// if(this.showobj.showArray[6] != '' && this.showobj.showArray[7] != ''){
// console.log('111111111111111111111111111111111111111111111111111111111111111');
// 显式转为字符串
@@ -1832,9 +2039,9 @@
initDisconnectTimer() {
this.clearDisconnectTimer()
this.disconnectTimer = setTimeout(() => {
- if(this.vardataflag === 3) {
- this.disconnectBluetooth()
- }
+ // if(this.vardataflag === 3) {
+ // this.disconnectBluetooth()
+ // }
}, 600000)
},
// 重置断开蓝牙定时器
@@ -1872,22 +2079,6 @@
})
}
},
- // 启动5秒数据看门狗
- startDataTimeoutTimer() {
- if (this.dataTimeoutTimer) {
- clearTimeout(this.dataTimeoutTimer)
- this.dataTimeoutTimer = null
- }
- this.dataTimeoutTimer = setTimeout(() => {
- if (this.vardataflag == 3 && !this.datalist) {
- console.log('5秒未收到数据,重连蓝牙')
- this.disconnectBluetooth()
- setTimeout(() => {
- this.btnlj()
- }, 1000)
- }
- }, 5000)
- },
// 清理5秒数据看门狗
clearDataTimeoutTimer() {
if (this.dataTimeoutTimer) {
@@ -2504,4 +2695,36 @@
}
}
}
+
+ /* 加载遮罩层样式 */
+ .loading-mask {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100vh;
+ background-color: rgba(255, 255, 255, 0.8);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 9999;
+ }
+
+ .loading-content {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ padding: 40rpx;
+ background-color: #fff;
+ border-radius: 20rpx;
+ box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
+ }
+
+ .loading-text {
+ margin-top: 20rpx;
+ font-size: 28rpx;
+ color: #666;
+ text-align: center;
+ }
\ No newline at end of file