Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Listen for newly discovered Bluetooth devices.
my.onBluetoothDeviceFound({ success: (res) => { res.devices.forEach(device => { console.log('Found:', device.name, device.deviceId); }); } });
Page({ data: { devices: [] }, onLoad() { my.openBluetoothAdapter({ success: () => { this.setupDeviceListener(); this.startScan(); } }); }, setupDeviceListener() { my.onBluetoothDeviceFound({ success: (res) => { const { devices } = this.data; res.devices.forEach(newDevice => { const exists = devices.find(d => d.deviceId === newDevice.deviceId); if (!exists && newDevice.name) { devices.push(newDevice); } }); this.setData({ devices }); } }); }, startScan() { my.startBluetoothDevicesDiscovery(); }, onUnload() { my.offBluetoothDeviceFound(); my.closeBluetoothAdapter(); } });
Page({ findDevice(targetName) { my.onBluetoothDeviceFound({ success: (res) => { const target = res.devices.find(d => d.name === targetName); if (target) { my.stopBluetoothDevicesDiscovery(); my.offBluetoothDeviceFound(); this.connectToDevice(target); } } }); my.startBluetoothDevicesDiscovery(); }, connectToDevice(device) { console.log('Connecting to:', device.name); } });
my.offBluetoothDeviceFound