浇花器

This commit is contained in:
吴鹏 2025-10-25 15:53:10 +08:00
parent 42d9dbc722
commit a08bf3321e
6 changed files with 504 additions and 214 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
}
},

View File

@ -26,8 +26,47 @@
<view class="devmac">
MAC{{item.mac == undefined ? item.name.slice(-12) : item.mac}}
</view>
<view class="devmac">
信号{{item.ssid == undefined ? '--' : item.ssid}}
<view class="devmac" style="display: flex;align-items: center;">
信号
<!-- 最强信号-50 及以上-1 -50 -->
<image
style="width: 30rpx;height: 20rpx;"
v-if="item.ssid >= -50"
src="https://api.ccttiot.com/smartmeter/img/static/ueeDGk0mVPLUd0DHxrWj"
mode=""
></image>
<!-- 较强信号-51 -60 -->
<image
style="width: 30rpx;height: 20rpx;"
v-else-if="item.ssid >= -60 && item.ssid <= -51"
src="https://api.ccttiot.com/smartmeter/img/static/uM1obZ76ittglMRKXWLq"
mode=""
></image>
<!-- 中等信号-61 -70 -->
<image
style="width: 30rpx;height: 20rpx;"
v-else-if="item.ssid >= -70 && item.ssid <= -61"
src="https://api.ccttiot.com/smartmeter/img/static/ujO9AZIuUSQvHcCBKqc4"
mode=""
></image>
<!-- 较弱信号-71 -80 -->
<image
style="width: 30rpx;height: 20rpx;"
v-else-if="item.ssid >= -80 && item.ssid <= -71"
src="https://api.ccttiot.com/smartmeter/img/static/uCSlbXZvho808NMCkIQP"
mode=""
></image>
<!-- 最弱信号-81 -100 -->
<image
style="width: 30rpx;height: 20rpx;"
v-else-if="item.ssid >= -100 && item.ssid <= -81"
src="https://api.ccttiot.com/smartmeter/img/static/u8bj3ZNi8Zssunk69HWc"
mode=""
></image>
</view>
</view>
<view class="add" style="color: #ccc;border: 1px solid #ccc;" v-if="item.userId">

View File

@ -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:

View File

@ -5,6 +5,14 @@
<view class="title">
<image src="https://api.ccttiot.com/smartmeter/img/static/uhRjXxrVaNwOCld2fYUl" mode=""></image>
</view>
<!-- 加载状态遮罩层 -->
<view class="loading-mask" v-if="isLoading">
<view class="loading-content">
<u-loading mode="circle" size="60" color="#7FAD76"></u-loading>
<text class="loading-text">正在加载中...</text>
</view>
</view>
<!-- 背景图 -->
<!-- 没设备时展示 -->
<image class="bjimg" v-if="bjflag" src="https://api.ccttiot.com/smartmeter/img/static/uz8MR6BuZW2qRANnYgLu"
@ -30,12 +38,15 @@
<view style="margin-left: 10rpx;" @click="btnlj" v-if="vardataflag == 1">
<image style="width: 158rpx;height: 40rpx;vertical-align: sub;" src="https://api.ccttiot.com/smartmeter/img/static/uIkBDnclZIqgUbWom2Aw" mode=""></image>
</view>
<view class="lj" @click="btnlj" v-if="vardataflag == 2">
<view class="lj" v-if="vardataflag == 2">
连接中
</view>
<view class="lj" style="color: #15C55D;border: 1px solid #15C55D;" @click="btnlj" v-if="vardataflag == 3">
<view class="lj" style="color: #15C55D;border: 1px solid #15C55D;" v-if="vardataflag == 3">
已连接
</view>
<view class="" style="font-weight: 400;font-size: 24rpx;color: #ccc;margin-left: 10rpx;" v-if="vardataflag == 2">
{{vatatxt}}
</view>
</view>
<view class="selectshezhi" style="display: flex;">
<image @click="btnsz" src="https://api.ccttiot.com/smartmeter/img/static/uvCJ8ro0MpfGZd53vypJ" mode=""></image>
@ -323,11 +334,11 @@
<image style="width:32rpx;height:32rpx;margin-right: 8rpx;" src="https://api.ccttiot.com/smartmeter/img/static/uhyYG0TLfWi9XUhTQz7D" mode=""></image>
启动时间
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="vardataflag == 3">
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="csbobj.hour">
{{csbobj.hour == undefined ? '--' : csbobj.hour + ':'}}{{csbobj.minute == undefined ? '' : csbobj.minute}}
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-else>
{{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}}
</view>
</view>
<view class="" style="font-size: 24rpx;color: #50565A;margin-top: 10rpx;text-align: center;">
@ -335,7 +346,7 @@
<image style="width:32rpx;height:32rpx;margin-right: 8rpx;font-size: 36rpx;font-weight: 600;" src="https://api.ccttiot.com/smartmeter/img/static/uuQaK98cmdQQnPWus27Z" mode=""></image>
工作时长
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="vardataflag == 3">
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="csbobj.second">
{{csbobj.second == undefined ? '--' : csbobj.second + '秒'}}
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-else>
@ -347,7 +358,7 @@
<image style="width:32rpx;height:32rpx;margin-right: 8rpx;font-size: 36rpx;font-weight: 600;" src="https://api.ccttiot.com/smartmeter/img/static/uM6Yz4xVqFwzW6xlTRph" mode=""></image>
间隔天数
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="vardataflag == 3">
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-if="csbobj.day">
{{csbobj.day == undefined ? '--' : csbobj.day + '天'}}
</view>
<view class="" style="margin-top:10rpx;font-size: 36rpx;font-weight: 600;" v-else>
@ -424,9 +435,12 @@
</view>
<view class="wateringlogbd">
<view class="lt" >
<view class="">距离下次{{xctime}}</view>
<!-- <view class="">距离下次{{xctime}}</view>
<view class="">下次浇水时长{{xctimesc}}</view>
<view class="">上次浇水{{sctimejs}}</view>
<view class="">上次浇水{{sctimejs}}</view> -->
<!-- <view class="">距离下次{{xctime}}</view> -->
<view class="">上次浇水时长{{jsobj.sprayingTime == undefined ? '--' : jsobj.sprayingTime + 's'}}</view>
<view class="">上次浇水{{jsobj.lastWaterTime == undefined ? '--' : jsobj.sprayingTime}}</view>
</view>
<view class="rt">
<image src="https://api.ccttiot.com/smartmeter/img/static/uagx3wGa7RYvqKqoSymy" mode=""></image>
@ -482,11 +496,17 @@
</view>
<view class="manualmask" v-if="sdjsflag"></view>
<!-- 选择浇水时间-->
<u-picker v-model="showjs" mode="time" :default-time="00" :params="params" @confirm="confirm"></u-picker>
<u-picker v-model="showjs" mode="time" :default-time="0" :params="params" @confirm="confirm"></u-picker>
<!-- 设置当前时间 -->
<u-picker v-model="timeflag" mode="time" :params="paramss" @confirm="confirmtime"></u-picker>
<tab-bar :indexs='0'></tab-bar>
<!-- <view class="">
<view class="" v-for="(item,index) in devicesarr" :key="index">
{{item.name}}
</view>
</view> -->
</view>
</template>
@ -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==360
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_datap_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 : {})
// yudilock
// 使=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;
}
</style>