浇花器
This commit is contained in:
parent
c283b869b7
commit
b8741c148b
|
@ -21,7 +21,7 @@ const install = (Vue, vm) => {
|
|||
// });
|
||||
Vue.prototype.$u.http.setConfig({
|
||||
baseUrl: 'https://yxd.ccttiot.com/prod-api',
|
||||
// baseUrl: 'https://znb.ccttiot.com',
|
||||
// baseUrl: 'http://192.168.2.56:8081',
|
||||
loadingText: '努力加载中~',
|
||||
loadingTime: 800,
|
||||
// 设置自定义头部content-type
|
||||
|
|
|
@ -118,7 +118,7 @@ function string2buffer(str) {
|
|||
}
|
||||
af += s;
|
||||
var n1 = parseInt('110' + af.substring(0, 5), 2);
|
||||
var n2 = parseInt('110' + af.substring(5), 2);
|
||||
var n2 = parseInt('110' + af.slice(-12), 2);
|
||||
if (n1 > 127) n1 -= 256;
|
||||
if (n2 > 127) n2 -= 256;
|
||||
bytes.push(n1);
|
||||
|
@ -1099,6 +1099,7 @@ function init() {
|
|||
};
|
||||
mDeviceEvent.notifyDeviceMsgEvent(obj);
|
||||
});
|
||||
console.log("初始化!!!!!!!!!!!!")
|
||||
mDeviceEvent.listenStartDiscoverBle(true, function (options) {
|
||||
if (options.isStart) {
|
||||
//第一步检查蓝牙适配器是否可用
|
||||
|
@ -1109,12 +1110,12 @@ function init() {
|
|||
uni.closeBluetoothAdapter({
|
||||
complete: function (res)
|
||||
{
|
||||
// console.log("这里蓝牙数据")
|
||||
uni.openBluetoothAdapter({
|
||||
console.log("这里蓝牙数据")
|
||||
wx.openBluetoothAdapter({
|
||||
success: function (res) {
|
||||
uni.getBluetoothAdapterState({
|
||||
success: function (res) {
|
||||
// console.log("这里蓝牙数据222")
|
||||
console.log("这里蓝牙数据222")
|
||||
{
|
||||
let devicesList = [];
|
||||
let countsTimes = 0;
|
||||
|
@ -1146,7 +1147,8 @@ function init() {
|
|||
// && devices.devices[0].name != 'SMART_R2XS'
|
||||
// )
|
||||
if (devices.devices[0].name.indexOf("WATER") != -1){
|
||||
// console.log("跳过",devices.devices[0].name)
|
||||
// if ( devices.devices[0].name.indexOf("gjkg") != -1 ){
|
||||
// console.log("跳过",devices.devices[0].name)
|
||||
// isnotexist = false;
|
||||
isnotexist = true;
|
||||
}
|
||||
|
@ -1170,6 +1172,13 @@ function init() {
|
|||
|
||||
if (isnotexist) {
|
||||
devicesList.push(devices.devices[0]);
|
||||
console.log("devicesList",devicesList);
|
||||
// let obj = {
|
||||
// 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
|
||||
// 'result': true,
|
||||
// 'data': devicesList
|
||||
// };
|
||||
// mDeviceEvent.notifyDeviceMsgEvent(obj);
|
||||
}
|
||||
} else if (devices[0]) {
|
||||
if (devices[0].advertisData) {
|
||||
|
@ -1186,6 +1195,13 @@ function init() {
|
|||
|
||||
if (isnotexist) {
|
||||
devicesList.push(devices[0]);
|
||||
console.log("devicesList",devicesList);
|
||||
// let obj = {
|
||||
// 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
|
||||
// 'result': true,
|
||||
// 'data': devicesList
|
||||
// };
|
||||
// mDeviceEvent.notifyDeviceMsgEvent(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ function initXBlufi(type) {
|
|||
break;
|
||||
|
||||
case XMQTT_SYSTEM.WeChat:
|
||||
console.log("初始化@@@@@@@!!!!!!!!!!!!")
|
||||
if(once==0)
|
||||
{
|
||||
once = 1;
|
||||
|
@ -175,8 +176,8 @@ function listenSendRouterSsidAndPassword(isSetListener, funtion) {
|
|||
|
||||
|
||||
function notifySendCustomData(options) {
|
||||
// console.log("设备数据",options)
|
||||
mOnFire.fire(OnFireEvent.EVENT_NOFITY_SEND_CUSTON_DATA, options);
|
||||
console.log("设备数据",options)
|
||||
mOnFire.fire(OnFireEvent.EVENT_NOFITY_SEND_CUSTON_DATA, options);
|
||||
}
|
||||
/**
|
||||
* 发送自定义数据
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<view class="mask" style="z-index: 9999;" v-if="kgflag"></view>
|
||||
</view>
|
||||
<view class="" style="width: 100%;padding-top: 80rpx;text-align: center;color: #000;font-size: 36rpx;">
|
||||
设备未连接
|
||||
没有更多定时浇水啦...
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
@ -69,7 +69,6 @@
|
|||
flag:false,
|
||||
checked:false,
|
||||
timeflag:false,
|
||||
|
||||
show: false,
|
||||
params: {
|
||||
year: false,
|
||||
|
@ -119,47 +118,33 @@
|
|||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
// this.list = JSON.parse(option.list)
|
||||
// for (let key in this.list) {
|
||||
// if (this.list.hasOwnProperty(key)) {
|
||||
// // 获取当前数组
|
||||
// let arr = this.list[key];
|
||||
// // 判断数组的最后一个元素,并进行替换
|
||||
// if (arr[arr.length - 1] === 0) {
|
||||
// arr[arr.length - 1] = false;
|
||||
// } else if (arr[arr.length - 1] === 1) {
|
||||
// arr[arr.length - 1] = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// console.log(this.list);
|
||||
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
|
||||
if(option.list){ //判断有无数据 有数据直接拿 无数据则发送命令获取数据
|
||||
this.list = JSON.parse(option.list)
|
||||
for (let key in this.list) {
|
||||
if (this.list.hasOwnProperty(key)) {
|
||||
// 获取当前数组
|
||||
let arr = this.list[key];
|
||||
// 判断数组的最后一个元素,并进行替换
|
||||
if (arr[arr.length - 1] === 0) {
|
||||
arr[arr.length - 1] = false;
|
||||
} else if (arr[arr.length - 1] === 1) {
|
||||
arr[arr.length - 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(this.list)
|
||||
}else{
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
xBlufi.initXBlufi(1)
|
||||
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
|
||||
uni.getNetworkType({
|
||||
success(res) {
|
||||
if (res.networkType !== 'none') {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
success(res) {
|
||||
setTimeout(()=> {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
},1000)
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('手机未连接网络')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
methods:{
|
||||
// 点击开关
|
||||
// 点击开关是否开启
|
||||
btnchange(key,index,values){
|
||||
this.kgflag = true
|
||||
this.btnitem(key,index,values)
|
||||
|
@ -181,30 +166,15 @@
|
|||
}
|
||||
}
|
||||
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'
|
||||
uni.getNetworkType({
|
||||
success(res) {
|
||||
if (res.networkType !== 'none') {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
success(res) {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: cucun
|
||||
})
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('手机未连接网络')
|
||||
}
|
||||
}
|
||||
})
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: cucun
|
||||
})
|
||||
setTimeout(()=>{
|
||||
this.kgflag = false
|
||||
},1000)
|
||||
},
|
||||
|
||||
// 点击定时
|
||||
// 点击设置定时时间
|
||||
btnitem(key,index,values){
|
||||
this.deviceindex = index
|
||||
this.timeflag = true
|
||||
|
@ -242,7 +212,7 @@
|
|||
return `${minutes}分${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}秒`;
|
||||
},
|
||||
|
||||
// 取消选择定时
|
||||
// 取消选择设置定时时间
|
||||
btnqx(){
|
||||
this.timeflag = false
|
||||
this.hour = '--'
|
||||
|
@ -250,7 +220,7 @@
|
|||
this.minute = '--'
|
||||
this.second = '--'
|
||||
},
|
||||
// 确定选择定时
|
||||
// 确定选择设置定时时间
|
||||
btnqd(){
|
||||
this.timeflag = false
|
||||
this.hour = '--'
|
||||
|
@ -258,29 +228,14 @@
|
|||
this.minute = '--'
|
||||
this.second = '--'
|
||||
let cucun = '11num' + this.deviceindex + '@' + this.devicehour + '@' + this.deviceminute + '@' + this.devicemiao + '@' + this.deviceflag + '@'
|
||||
uni.getNetworkType({
|
||||
success(res) {
|
||||
if (res.networkType !== 'none') {
|
||||
uni.getConnectedBluetoothDevices({
|
||||
success(res) {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: cucun
|
||||
})
|
||||
setTimeout(()=> {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
},1000)
|
||||
},
|
||||
fail(err) {
|
||||
console.error('获取已连接蓝牙设备信息失败:',err)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('手机未连接网络')
|
||||
}
|
||||
}
|
||||
})
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: cucun
|
||||
})
|
||||
setTimeout(()=> {
|
||||
xBlufi.notifySendCustomData({
|
||||
customData: "11get"
|
||||
})
|
||||
},1000)
|
||||
},
|
||||
// 定时浇水时间
|
||||
confirm(e){
|
||||
|
@ -294,23 +249,14 @@
|
|||
this.minute = e.minute
|
||||
this.second = e.second
|
||||
this.devicemiao = Number(this.minute) * 60 + Number(this.second)
|
||||
console.log(this.devicemiao);
|
||||
console.log(this.devicemiao)
|
||||
},
|
||||
|
||||
funListenDeviceMsgEvent: function(options) {
|
||||
switch (options.type) {
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
||||
if (!options.result) {
|
||||
// uni.showModal({
|
||||
// title: '很抱歉提醒你!',
|
||||
// content: '小程序与设备异常断开',
|
||||
// showCancel: false,
|
||||
// //是否显示取消按钮
|
||||
// success: function(res) {
|
||||
// uni.hideLoading()
|
||||
// uni.removeStorage({key:'device_key'})
|
||||
// }
|
||||
// })
|
||||
|
||||
}
|
||||
break;
|
||||
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||
|
@ -321,11 +267,11 @@
|
|||
const showObject = {}
|
||||
const pSetObjects = {}
|
||||
pairs.forEach(pair => {
|
||||
const [key, value] = pair.split(':');
|
||||
const [key, value] = pair.split(':')
|
||||
if (key === 'show') {
|
||||
showObject.showArray = value.split(',').map(Number);
|
||||
showObject.showArray = value.split(',').map(Number)
|
||||
} else if (key.startsWith('p_set')) {
|
||||
const numbers = value.split(',').map(Number);
|
||||
const numbers = value.split(',').map(Number)
|
||||
pSetObjects[key] = numbers
|
||||
}
|
||||
})
|
||||
|
@ -333,51 +279,51 @@
|
|||
|
||||
const ver_Data = this.list
|
||||
function secondsToMinutesAndSeconds(seconds) {
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const remainingSeconds = seconds % 60;
|
||||
return `${minutes}分${remainingSeconds}秒`;
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const remainingSeconds = seconds % 60
|
||||
return `${minutes}分${remainingSeconds}秒`
|
||||
}
|
||||
// 获取当前时间
|
||||
const now = new Date();
|
||||
const now = new Date()
|
||||
// 辅助函数:将时间数组转换为 Date 对象
|
||||
function timeArrayToDate(timeArray) {
|
||||
const [hour, minute, second] = timeArray.slice(0, 3);
|
||||
const date = new Date();
|
||||
date.setHours(hour, minute, second, 0); // 毫秒设为0
|
||||
return date;
|
||||
const [hour, minute, second] = timeArray.slice(0, 3)
|
||||
const date = new Date()
|
||||
date.setHours(hour, minute, second, 0) // 毫秒设为0
|
||||
return date
|
||||
}
|
||||
// 辅助函数:计算两个时间之间的差值(以小时和分钟表示)
|
||||
function timeDifference(date1, date2) {
|
||||
const diffMs = Math.abs(date1 - date2);
|
||||
const diffSeconds = Math.floor(diffMs / 1000);
|
||||
const diffMinutes = Math.floor(diffSeconds / 60);
|
||||
const diffHours = Math.floor(diffMinutes / 60);
|
||||
const remainingMinutes = diffMinutes % 60;
|
||||
return { hours: diffHours, minutes: remainingMinutes };
|
||||
const diffMs = Math.abs(date1 - date2)
|
||||
const diffSeconds = Math.floor(diffMs / 1000)
|
||||
const diffMinutes = Math.floor(diffSeconds / 60)
|
||||
const diffHours = Math.floor(diffMinutes / 60)
|
||||
const remainingMinutes = diffMinutes % 60
|
||||
return { hours: diffHours, minutes: remainingMinutes }
|
||||
}
|
||||
// 遍历 ver_Data 对象
|
||||
let nextTimeDiff = null;
|
||||
let nextTime = null;
|
||||
let prevTimeDiff = null;
|
||||
let prevTime = null;
|
||||
let nextWaterDuration = null; // 用于存储下次浇水时长
|
||||
let nextTimeDiff = null
|
||||
let nextTime = null
|
||||
let prevTimeDiff = null
|
||||
let prevTime = null
|
||||
let nextWaterDuration = null // 用于存储下次浇水时长
|
||||
for (const key in ver_Data) {
|
||||
if (ver_Data.hasOwnProperty(key) && ver_Data[key][3] === 1) {
|
||||
const timeArray = ver_Data[key];
|
||||
const timeDate = timeArrayToDate(timeArray);
|
||||
const timeArray = ver_Data[key]
|
||||
const timeDate = timeArrayToDate(timeArray)
|
||||
// 计算与当前时间的差值
|
||||
const diff = timeDifference(timeDate, now);
|
||||
const diff = timeDifference(timeDate, now)
|
||||
// 判断是下一次时间还是上一次时间
|
||||
if (timeDate > now) {
|
||||
if (!nextTime || diff.hours * 60 + diff.minutes < nextTimeDiff.hours * 60 + nextTimeDiff.minutes) {
|
||||
nextTimeDiff = diff;
|
||||
nextTime = timeDate;
|
||||
nextWaterDuration = secondsToMinutesAndSeconds(timeArray[2]); // 获取并转换浇水时长
|
||||
nextTimeDiff = diff
|
||||
nextTime = timeDate
|
||||
nextWaterDuration = secondsToMinutesAndSeconds(timeArray[2]) // 获取并转换浇水时长
|
||||
}
|
||||
} else {
|
||||
if (!prevTime || (now.getTime() - timeDate.getTime()) < (now.getTime() - prevTime.getTime())) {
|
||||
prevTimeDiff = timeDifference(now, timeDate); // 注意这里要反过来算
|
||||
prevTime = timeDate;
|
||||
prevTimeDiff = timeDifference(now, timeDate) // 注意这里要反过来算
|
||||
prevTime = timeDate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -387,20 +333,18 @@
|
|||
for (let key in this.list) {
|
||||
if (this.list.hasOwnProperty(key)) {
|
||||
// 获取当前数组
|
||||
let arr = this.list[key];
|
||||
let arr = this.list[key]
|
||||
// 判断数组的最后一个元素,并进行替换
|
||||
if (arr[arr.length - 1] === 0) {
|
||||
arr[arr.length - 1] = false;
|
||||
arr[arr.length - 1] = false
|
||||
} else if (arr[arr.length - 1] === 1) {
|
||||
arr[arr.length - 1] = true;
|
||||
arr[arr.length - 1] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -87,25 +87,7 @@
|
|||
},
|
||||
onLoad() {
|
||||
this.getinfo()
|
||||
|
||||
let that = this
|
||||
xBlufi.initXBlufi(1);
|
||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
})
|
||||
setTimeout(() => {
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': false
|
||||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
// xBlufi.notifyConnectBle({
|
||||
// isStart: true,
|
||||
// deviceId: that.deviceId,
|
||||
// name: that.name
|
||||
// })
|
||||
}
|
||||
}, 5000)
|
||||
this.btnss()
|
||||
},
|
||||
methods:{
|
||||
// 获取用户信息
|
||||
|
@ -123,7 +105,7 @@
|
|||
// 点击添加添加绑定设备
|
||||
btnadd(e){
|
||||
console.log(e,'0101');
|
||||
let mac = e.slice(5, 17)
|
||||
let mac = e.slice(-12)
|
||||
let data = {
|
||||
mac:mac,
|
||||
userId:this.userid
|
||||
|
@ -154,7 +136,6 @@
|
|||
})
|
||||
this.flag = false
|
||||
let that = this
|
||||
xBlufi.initXBlufi(1);
|
||||
xBlufi.listenDeviceMsgEvent(true, that.funListenDeviceMsgEvent)
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
|
@ -165,11 +146,6 @@
|
|||
})
|
||||
if (that.devicesList.length > 0) {
|
||||
that.flags = true
|
||||
// xBlufi.notifyConnectBle({
|
||||
// isStart: true,
|
||||
// deviceId: that.deviceId,
|
||||
// name: that.name
|
||||
// })
|
||||
}else{
|
||||
that.flags = false
|
||||
}
|
||||
|
@ -201,7 +177,7 @@
|
|||
if (options.result) {
|
||||
let devicesarr = options.data
|
||||
this.devicesList = devicesarr
|
||||
console.log(devicesarr,'111');
|
||||
// console.log(devicesarr,'111');
|
||||
// devicesarr.forEach(device => {
|
||||
// const mac = device.name.substring(4);
|
||||
// if (device.name.slice(5, 17) == this.mac) {
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
btnxq(plantId){
|
||||
if(plantId == null || plantId == ''){
|
||||
uni.showToast({
|
||||
title: '无该非植物信息',
|
||||
title: '暂无非植物信息',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
|
|
|
@ -209,7 +209,6 @@
|
|||
.title {
|
||||
margin-top: 23rpx;
|
||||
font-size: 80rpx;
|
||||
// font-weight: 400;
|
||||
letter-spacing: 0rpx;
|
||||
line-height: 88rpx;
|
||||
color: rgba(80, 86, 90, 1);
|
||||
|
@ -233,13 +232,10 @@
|
|||
.cont_left {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
// margin-right: 40rpx;
|
||||
// align-items: baseline;
|
||||
width: 50%;
|
||||
|
||||
.cont_left_tit {
|
||||
font-size: 28rpx;
|
||||
// font-weight: 400;
|
||||
letter-spacing: 0.56rpx;
|
||||
line-height: 36rpx;
|
||||
color: #3D3D3D;
|
||||
|
@ -249,7 +245,6 @@
|
|||
margin-top: 10rpx;
|
||||
width: 294rpx;
|
||||
font-size: 32rpx;
|
||||
// font-weight: 600;
|
||||
letter-spacing: 0.64rpx;
|
||||
line-height: 40rpx;
|
||||
color: #50565A;
|
||||
|
@ -289,7 +284,6 @@
|
|||
}
|
||||
|
||||
.txt {
|
||||
// margin-top: 24rpx;
|
||||
width: 100%;
|
||||
margin-top: 12rpx;
|
||||
font-size: 32rpx;
|
||||
|
|
|
@ -17,11 +17,6 @@
|
|||
<text class="one" style="margin-right: 124rpx;">MAC</text>
|
||||
<text>{{user.mac == undefined ? '--' : user.mac}}</text>
|
||||
</view>
|
||||
<!-- <view class="wifi">
|
||||
<view class="">WIFI</view>
|
||||
<view class="flex">ChangteA-5G <image src="https://api.ccttiot.com/smartmeter/img/static/uiTIUYnR3ClrmqOTyF8F" mode=""></image>
|
||||
</view>
|
||||
</view> -->
|
||||
<view class="wifi" style="margin-top: 78rpx;" @click="xpshow = true">
|
||||
<view class="">息屏</view>
|
||||
<view class="flex">{{xptxt}}
|
||||
|
@ -139,8 +134,10 @@
|
|||
duration: 2000
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 2000)
|
||||
uni.reLaunch({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
}, 1000)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -331,7 +331,6 @@
|
|||
uni.showLoading({
|
||||
title: '请稍后...'
|
||||
})
|
||||
xBlufi.initXBlufi(1);
|
||||
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
|
|
|
@ -364,7 +364,6 @@
|
|||
uni.showLoading({
|
||||
title: '连接中..'
|
||||
})
|
||||
xBlufi.initXBlufi(1);
|
||||
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
||||
xBlufi.notifyStartDiscoverBle({
|
||||
'isStart': true
|
||||
|
|
Loading…
Reference in New Issue
Block a user