no-image

How to migrate to obniz 3.0.x

obniz.js / obnizOS 3 has various new features.

  • The startup screen looks cool!
  • BLE is easier to use!
  • To use the Sleep function!(Only obniz Board 1Y)

To use these new features, both firmware and program updates are required.

※How to update the firmware. See blow: Remote OS Update (OTA)

Change obniz.js version

Change the HTML tag [email protected] to 3.0.X.

Before

<script src="https://unpkg.com/[email protected]/obniz.js" crossorigin="anonymous"></script>

After

<script src="https://unpkg.com/[email protected]/obniz.js" crossorigin="anonymous"></script>

Added BLE initialization

If you are writing a program that uses BLE, you need to initialize BLE.

Call await obniz.ble.initWait() first.

Before

obniz.onconnect = async function () {
    obniz.ble.scan.start();
    .
    .
    .
}

After

obniz.onconnect = async function () {
    await obniz.ble.initWait();
    obniz.ble.scan.start();
    .
    .
    .
}

Delete BLE CCCD settings

In obniz 2.x.x, it was necessary to use CCCD Descriptor (0x2902) when using the BLE notify function.

Since obniz 3.0.0 they are created automatically. Therefore, delete about descriptors description completely.

Use obniz as a peripheral

Before

var characteristic = new obniz.ble.characteristic({
  uuid: 'FFF1',
  data: [0x0e, 0x00],
  properties : ["read","write","notify"],  // add notify properties
  descriptors: [
    {
      uuid: '2902', //CCCD
      data: [0x00, 0x00],  //2byte
    }, 
  ],
});

var service = new obniz.ble.service({
  uuid: 'FFF0',
  characteristics: [characteristic],
});
obniz.ble.peripheral.addService(service);


// after central connected
characteristic.notify();

After

var characteristic = new obniz.ble.characteristic({
  uuid: 'FFF1',
  data: [0x0e, 0x00],
  properties : ["read","write","notify"],  // add notify properties
  descriptors: [],  // CCCDはpropertiesをみて自動で付与されます
});

var service = new obniz.ble.service({
  uuid: 'FFF0',
  characteristics: [characteristic],
});
obniz.ble.peripheral.addService(service);


// after central connected
characteristic.notify();

Use obniz as Central

Before

var target = {
  localName: "obniz-notify"
};

var peripheral = await obniz.ble.scan.startOneWait(target);
var connected = await peripheral.connectWait();
if(connected){
  let char = peripheral.getService('fff0').getCharacteristic( 'fff1');
  let cccd = char.getDescriptor("2902");
  let result = await cccd.writeWait([0x01, 0x00]); // register cccd for remote peripheral 

  console.log(await cccd.readWait()); // check cccd 

  char.registerNotify( function(data){
    console.log("notify with data " + data.join(','));
  });

}

After

var target = {
  localName: "obniz-notify"
};

var peripheral = await obniz.ble.scan.startOneWait(target);
var connected = await peripheral.connectWait();
if(connected){
 let char = peripheral.getService('fff0').getCharacteristic( 'fff1');
 
 // delete cccd setting
  
 char.registerNotify( function(data){
    console.log("notify with data " + data.join(','));
  });

}

Delete BLE security settings

obniz 2.x.x had a function to set the security level of BLE.
Since obniz 3.0.0, security is automatically supported.

Before

obniz.ble.security.onerror = function() {
    console.error('security set params error');
    obniz.reboot();
};
security.setModeLevel(1, 2); //LE Security Mode 1, Level 2

After

// nothing todo

The migration is complete!
obniz 3.0.X includes Sleep function that can be used with 1Y, so please try it out.