obniz to be used
Optional extendedOptional onThis is a callback function used when an external device gets connected or disconnected.
await obniz.ble.initWait();
obniz.ble.onUpdatePhy = ((txPhy, rxPhy) => {
console.log("txPhy "+txPhy+" rxPhy "+rxPhy);
});
Optional handler: numberRsponse waiting timeout in milliseconds
Static prefixedInitialized status.
// Javascript Example
obniz.ble.isInitialized; // => false
await obniz.ble.initWait();
obniz.ble.isInitialized; // => true
Connect to peripheral without scanning. Returns a peripheral instance, but the advertisement information such as localName is null because it has not been scanned.
// Javascript Example
await obniz.ble.initWait();
var peripheral = obniz.ble.directConnect("e4b9efb29218","random");
peripheral.onconnect = ()=>{
console.log("connected");
}
peripheral device address
"random" or "public"
Optional connectionSetting: BleConnectSettingreplaced by #directConnectWait()
Connect to peripheral without scanning, and wait to finish connecting.
It throws when connection establish failed. Returns a peripheral instance, but the advertisement information such as localName is null because it has not been scanned.
// Javascript Example
await obniz.ble.initWait();
try {
var peripheral = await obniz.ble.directConnectWait("e4b9efb29218","random");
console.log("connected");
} catch(e) {
console.log("can't connect");
}
peripheral device address
"random" or "public"
Optional connectionSetting: BleConnectSettingReturn connected peripherals.
// Javascript Example
await obniz.ble.initWait();
let target = {
localName: "Blank"
};
var peripheral = await obniz.ble.scan.startOneWait(target);
if(peripheral) {
try {
await peripheral.connectWait();
} catch(e) {
console.error(e);
}
}
console.log(obniz.ble.getConnectedPeripherals());
connected peripherals
Initialize BLE module. You need call this first everything before. This throws if device is not supported device.
esp32 C3 or esp32 S3 Put true in the argument when not using the BLE5.0 extended advertise
// Javascript Example
await obniz.ble.initWait();
Generated using TypeDoc
Use a obniz device as a BLE device. Peripheral and Central mode are supported