lecodeurdudimanche / php-bluetooth
使用PHP简单控制蓝牙设备的Bluez可执行程序
v0.5.1
2020-12-28 22:38 UTC
Requires
- php: >7.2
- lecodeurdudimanche/php-process-launcher: dev-master
- lecodeurdudimanche/php-unix-streams: dev-master
README
一个用于在Linux上使用PHP管理蓝牙连接的包
此包依赖于Bluez堆栈,使用bluetoothctl工具。
此包处于早期开发阶段
需求
此库依赖于BlueZ堆栈,因此您需要安装bluez和bluez-tools包。
PHP版本 >= 7.2
安装
composer require lecodeurdudimanche\php-bluetooth
基本用法
Manager类是这个库的入口点。
启动Manager并将蓝牙适配器设置为可发现状态,并接受配对
use lecodeurdudimanche\PHPBluetooth\Manager; $manager = new Manager($discoverable, $pairable);
接下来,您可以通过Manager管理蓝牙连接,请注意,所有命令(但不是所有方法)都是异步的
use lecodeurdudimanche\PHPBluetooth\Device; $manager->scanDevices(); //Initiate device scan $manager->setPairable(false); $manager->pairDevice(new Device($mac)); $manager->updateBluetoothInfo(); $data = $manager->getBluetoothInfo(); foreach($data->getAvailableDevices() as $device) { if (! $device->paired) $manager->blockDevice($device); } // Other methods are available, see Manager class
待办事项
- Add detection of discoverable and pairable status at startup
- Add support to exclude unscanned paired devices from scanned devices list
- Add detection of trusted and blocked devices
- Add I/O exception handling
许可证
MIT许可证