obniz.js 3.5.0 Released

This release includes adding 20 BLE device support and more robust communication with obniz device.

GitHub

New Support Devices

BLE

Improvements

Common

  • async/await response waiting functions now throw errors when obniz gone to offline or over timeout secs.
await obniz.spi0.writeWait([0x00]); // => will throw if obniz gone to offline or timeout occure.
  • i2c now throw error on i2c error occured.
const arr = await obniz.i2c0.readWait(0x11, 0x03); // => will throw if target is not connected or NAK responded.

BLE

  • ble.scan.start() and ble.scan.end() is now deprecated. Use startWait() and endWait()
  • ble.scan.onfinish() receive error object when scan fails some reason
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
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();