1. 首先下载Script Engine
2. 确保电子秤连接到蓝牙
3.找到自动化
3.1新建一个JavaScript文件(设备id记得要修改)
on({id: 'ble.0.c8:47:8c:99:51:ec.services.181d', change: "ne", ack: true}, function (obj) {
var value = obj.state.val;
var oldValue = obj.oldState.val;
//console.log((['Weight: ',(obj.state ? obj.state.val: ""),'Service:',obj.id].join('')));
const buf = new Buffer(value,'hex');
console.log("buf: " + buf);
const buffer2 = new Uint8Array(buf);
console.log("buffer2: " + buffer2);
const myInt = buf.readIntLE(1, Buffer.byteLength(buffer2 .slice(0,2))) / 200;
console.log("your weight is: " + myInt + "KG");
const sequence = buf.readIntBE(1,Buffer.byteLength(buffer2 .slice(7,9)));
console.log("your sequence is: " + sequence);
setState("weight",{val:myInt,ack:true},function(){
var test = getState("weight").val;
});
setState("sequence",{val:sequence,ack:true},function(){
var test = getState("sequence").val;
});
'javascript.0.scriptEnabled.miscale'/*scriptEnabled miscale*/
});
3.2然后再新建一个JavaScript文件
createState('javascript.0.weight'),{
type:'number',
write:false,
read:true,
unit:'KG'
}
createState('javascript.0.sequence'),{
type:'number',
write:false,
read:true,
}
4. 在设备界面中的JavaScript.0中可以找到刚刚新建的两个state以及他们的值(sequence的值应该有误)