This package relies on the Bluez stack, using the bluetoothctl
tool.
This package is in early development stage
This library relies on the BlueZ stack, so you need to install bluez
and bluez-tools
packages.
PHP version >= 7.2
composer require lecodeurdudimanche\php-bluetooth
The Manager
class is the entry point of this library.
To launch the Manager
and set the bluetooth adapter in a discoverable state and to accept paring :
use lecodeurdudimanche\PHPBluetooth\Manager;
$manager = new Manager($discoverable, $pairable);
Next you can manage the bluetooth connextion through the Manager
, keep in mind that all commands (but not all methods) are asynchronous :
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 License