Ionic framework 将字符串命令发送到Ionic中的BLE
我是爱奥尼亚的新手,现在我正试图发送一个字符串形式的“代码”。 其中字符串由几个十六进制数据包组成。 例如V1-FC03-2ED1-FE01 V1是序列,然后在第一个之后-是第一个数据包“FC03” 该代码使用pc上的串行监视器成功发送到我的arduino。 现在我想用离子束把它发送出去。 我遵循github上的示例来执行BLE。 如果发送1或0,它将工作 以下是按下按钮后将发送给arduino的离子代码中的函数Ionic framework 将字符串命令发送到Ionic中的BLE,ionic-framework,bluetooth-lowenergy,Ionic Framework,Bluetooth Lowenergy,我是爱奥尼亚的新手,现在我正试图发送一个字符串形式的“代码”。 其中字符串由几个十六进制数据包组成。 例如V1-FC03-2ED1-FE01 V1是序列,然后在第一个之后-是第一个数据包“FC03” 该代码使用pc上的串行监视器成功发送到我的arduino。 现在我想用离子束把它发送出去。 我遵循github上的示例来执行BLE。 如果发送1或0,它将工作 以下是按下按钮后将发送给arduino的离子代码中的函数 onPowerSwitchChange(event) { console.log
onPowerSwitchChange(event) {
console.log('onPowerSwitchChange');
let value = this.power ? 1 : 0;
let buffer = new Uint8Array([value]).buffer;
console.log('Power Switch Property ' + this.power);
this.ble.write(this.peripheral.id, LIGHTBULB_SERVICE, SWITCH_CHARACTERISTIC, buffer).then(
() => this.setStatus('Light is ' + (this.power ? 'on' : 'off')),
e => this.showAlert('Unexpected Error', 'Error updating power switch')
);
}
在这里,我试图改变
let value = this.power ? 1 : 0;
到
但编译时,出现了错误
Argument of type 'string[]' is not assignable to parameter of type 'ArrayBuffer'. Property 'byteLength' is
missing in type 'string[]'.
L68: let value = "V1-FC03-2ED1-FE01";
L69: let buffer = new Uint8Array([value]).buffer;
L70: console.log('Power Switch Property ' + this.power);
希望有人能在这个问题上帮我不确定这是否能帮到你,因为我不是一个程序员。。。但我想发送一个“2”作为字符串,结果我不得不这样做:
var data = new Uint8Array(1);
data[0] = 50;
其中50为UINT8阵列,相当于2
目前,我正试图从BLE中读取相反方向的内容,但没有效果,因此请随时向我们通报您的进度。可能的副本
var data = new Uint8Array(1);
data[0] = 50;