Skip to content

Instantly share code, notes, and snippets.

@CromFr

CromFr/main.rs Secret

Created April 6, 2017 19:02
Show Gist options
  • Save CromFr/7938362577028de485b8ca6d7029c6f7 to your computer and use it in GitHub Desktop.
Save CromFr/7938362577028de485b8ca6d7029c6f7 to your computer and use it in GitHub Desktop.
extern crate blurz;
use blurz::bluetooth_adapter::BluetoothAdapter as Adapter;
use blurz::bluetooth_device::BluetoothDevice as Device;
use blurz::bluetooth_gatt_service::BluetoothGATTService as GATTService;
use blurz::bluetooth_gatt_characteristic::BluetoothGATTCharacteristic as GATTCharacteristic;
fn main() {
let adapter: Adapter = Adapter::init().unwrap();
for dev_path in adapter.get_device_list().unwrap() {
let device = Device::new(dev_path);
let addr = device.get_address().unwrap();
//addr == "84:EB:18:7C:22:68" ||
if addr == "84:EB:18:7C:1C:F7" {
if device.is_connected().unwrap() == false {
println!("Connecting to {}", addr);
match device.connect() {
Ok(_) => {
println!("Connected to {}", addr);
}
Err(e) => {
println!("Could not connect to {}: {}", addr, e);
continue;
}
}
}
println!("Device {} - power: {}",
addr,
device.get_tx_power().unwrap_or_default());
for srv_path in device.get_gatt_services().unwrap() {
let service = GATTService::new(srv_path);
let service_uuid = service.get_uuid().unwrap();
if service_uuid == "a8b3fff0-4834-4051-89d0-3de95cddd318" {
for charac_path in service.get_gatt_characteristics().unwrap() {
let charac = GATTCharacteristic::new(charac_path.clone());
let charac_uuid = charac.get_uuid().unwrap();
if charac_uuid == "a8b3fff1-4834-4051-89d0-3de95cddd318" {
println!("Write={:?}",
charac.write_value(vec![0x55, 0x10, 0x01, 0x0d, 0x0a]));
std::thread::sleep(std::time::Duration::from_millis(200));
println!("Write={:?}",
charac.write_value(vec![0x55, 0x10, 0x00, 0x0d, 0x0a]));
}
}
}
}
device.disconnect();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment