Page({
data: {
displayData1: '0',
displayData2: '0',
displayData3: '0',
},
//接收消息监听
client.on('message', (topic, message) => {
let msg=message.toString();
const data=JSON.parse(msg);
const timestamp = new Date().toISOString().substr(0, 19).replace('T', ' ');
console.log('温度:', data.temperture, '湿度:', data.humidity,'纬度:',data.longitude,'经度',data.latitude,'x轴:',data.x,'y轴:',data.y,'z轴:',data.z);
let data1=data.x;
let data2=data.y;
let data3=data.z;
let roundedData1=Math.round(data1*1e3)/1e3;
let roundedData2=Math.round(data2*1e3)/1e3;
let roundedData3=Math.round(data3*1e3)/1e3;
// 设置数据
this.setData({
displayData1: roundedData1,
displayData2: roundedData2,
displayData3: roundedData3,
});
});
}
})