本日、obniz.js 3.5.0をリリースしました。
新たに20種類のBLEデバイスをサポート。合わせてBLE接続の安定化とタイムアウト機能の追加など、いくつかの改善を加えました。
コンテンツ
New Support Devices
以下のBLEデバイスをサポートしました。
BLE
- ENERTALK
- iBS01
- iBS01RG
- iBS01T
- iBS02IR
- iBS02PIR
- iBS03_iBS04
- iBS03T
- iBS03TP
- iBS04i
- LogttaAccel
- LogttaAD
- LogttaCO2
- LogttaTemp
- MINEW_S1
- REX_BTPM25V
- RS_SEEK3
- scbtgaaac
- uprism
- cir415a
- tm530
- tm551
Improvements
Common
- async / await 関数は、obnizがオフラインまたはタイムアウト秒数を超えるとエラーを返します。
await obniz.spi0.writeWait([0x00]); // => will throw if obniz gone to offline or timeout occure.
- i2cエラーが発生したときにエラーを返します。
const arr = await obniz.i2c0.readWait(0x11, 0x03); // => will throw if target is not connected or NAK responded.
BLE
- ble.scan.start()とble.scan.end()は非推奨になりました。今後はstartWait()および endWait()を使用します。
- ble.scan.onfinish()は、スキャンが何らかの理由で失敗したときにエラーを受け取ります。
obniz.ble.initWait(); // will throw error if fails.
obniz.ble.scan.onfind = (peripheral) => {
}
obniz.ble.scan.onfinish = (peripherals, error) => {
if (error) {
// some thing error occured like obniz went to offline.
}
}
await obniz.ble.scan.startWait(); // will throw error if start fails
- peripheral.ondisconnect now pass
reasonarugument. - key phrase pairing をサポートしました。
await obniz.ble.initWait({});
obniz.ble.scan.onfind = function(peripheral){
if(peripheral.localName == "my peripheral"){
peripheral.onconnect = async function(){
console.log("success");
let passkeyCallback = await ()=>{
//HTML prompt
let number = prompt("Please type passkey code.");
return number;
}
// pairing with user input passkey.
await peripheral.pairingWait({passkeyCallback});
}
await peripheral.connectWait();
}
}
obniz.ble.scan.start();
