btlib 0.0.1 copy "btlib: ^0.0.1" to clipboard
btlib: ^0.0.1 copied to clipboard

outdated

A bluetooth driver plugin project.

Btlib #

A bluetooth driver plugin project, using a easy event-driven way.

Getting Started #

class BTUUID { static const String TX_SERV = "1802"; static const String TX_CHAR = "2a06"; static const String RX_SERV = "180f"; static const String RX_CHAR = "2a19"; static const String NOTIFY_SERV = "ffe0"; static const String NOTIFY_CHAR = "ffe1"; }

main() { Btlib driver = Btlib(); StreamSubscription subscription; subscription = driver.listen(onEvent); driver.startScan(); /// wait scan result... driver.stopScan(); driver.connect(address); driver.writeCharacteristic( address, BTUUID.TX_SERV, BTUUID.TX_CHAR, Uint8List.fromList([0,1,2,3])); driver.readCharacteristic( address, BTUUID.RX_SERV, BTUUID.RX_CHAR); driver.setCharacteristicNotification( address, BTUUID.NOTIFY_SERV, BTUUID.NOTIFY_CHAR, true); driver.getRSSI(address); driver.disconnect(address); }

/* events: BTEvent.BLE_START_SCAN
BTEvent.BLE_STOP_SCAN
BTEvent.BLE_SCAN_RESULT /// return name,address,rssi
BTEvent.BLE_CONNECTED /// return address BTEvent.BLE_DISCONNECTED /// return address BTEvent.BLE_SERVICES_CHARACTERISTICS /// return address,service,characteristic BTEvent.BLE_DATA_AVAILABLE /// return address,service,characteristic,data BTEvent.BLE_RSSI /// return address,rssi
*/ void onEvent(Object event) { HashMap<String, Object> map = HashMap.from(event); print(map); if (map["event"] == BTEvent.BLE_START_SCAN) { print( "start scan" ); } else if (map["event"] == BTEvent.BLE_STOP_SCAN) { print( "stop scan" ); } else if (map["event"] == BTEvent.BLE_SCAN_RESULT) { print( map["name"] ); print( map["address"] ); print( map["rssi"] ); } else if (map["event"] == BTEvent.BLE_CONNECTED) { print( map["address"] ); } else if (map["event"] == BTEvent.BLE_DISCONNECTED) { print( map["address"] ); } else if (map["event"] == BTEvent.BLE_SERVICES_CHARACTERISTICS) { print( map["address"] ); print( map["service"] ); print( map["characteristic"] ); } else if (map["event"] == BTEvent.BLE_DATA_AVAILABLE) { print( map["address"] ); print( map["service"] ); print( map["characteristic"] ); print( map["data"] ); } else if (map["event"] == BTEvent.BLE_RSSI) { print( map["address"] ); print( map["rssi"] ); } }

1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A bluetooth driver plugin project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on btlib