You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
extern crate rumble;
extern crate rand;
use std::thread;
use std::time::Duration;
use rand::{Rng, thread_rng};
use rumble::bluez::manager::Manager;
use rumble::api::{UUID, Central, Peripheral};
pub fn main() {
let manager = Manager::new().unwrap();
// get the first bluetooth adapter
let adapters = manager.adapters().unwrap();
let mut adapter = adapters.into_iter().nth(0).unwrap();
// reset the adapter -- clears out any errant state
adapter = manager.down(&adapter).unwrap();
adapter = manager.up(&adapter).unwrap();
// connect to the adapter
let central = adapter.connect().unwrap();
// start scanning for devices
central.start_scan().unwrap();
// instead of waiting, you can use central.on_event to be notified of
// new devices
thread::sleep(Duration::from_secs(2));
// find the device we're interested in
let sphero_mini = central.peripherals().into_iter()
.find(|p| p.properties().local_name.iter()
.any(|name| name.contains("SM-"))).unwrap();
println!("{:?}", sphero_mini);
// connect to the device
sphero_mini.connect().unwrap();
println!("Is sphero connected: {:?}", sphero_mini.is_connected());
// discover characteristics
sphero_mini.discover_characteristics().unwrap();
// find the characteristic we want
let chars = sphero_mini.characteristics();
for c in chars {
println!("{:?}", c);
}
}
I have this message:
$ ./test
C1:44:3B:21:3D:9C properties: PeripheralProperties { address: C1:44:3B:21:3D:9C, address_type: Random, local_name: Some("SM-3D9C"), tx_power_level: None, manufacturer_data: None, discovery_count: 2, has_scan_response: true }, characteristics: {}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Other("ECONNREFUSED: Connection refused")', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
If I write same code in Javascript using noble, it's working.
The difference is l2_bdaddr_type value. Rumble set to 1 (BDADDR_LE_PUBLIC) where Noble set to 2 (BDADDR_LE_RANDOM).
In peripheral.rs file if I change:
let addr = SockaddrL2 {
l2_family: libc::AF_BLUETOOTH as u16,
l2_psm: 0,
l2_bdaddr: self.address,
l2_cid: ATT_CID,
l2_bdaddr_type: 1,
};
to
let addr = SockaddrL2 {
l2_family: libc::AF_BLUETOOTH as u16,
l2_psm: 0,
l2_bdaddr: self.address,
l2_cid: ATT_CID,
l2_bdaddr_type: 2,
};
This change did allow me to be able to connect (indicator LED on my peripheral for connection came on), however I am still unable to discover characteristics.
Hi all,
Ubuntu 18.04.2 LTS (Bionic Beaver)
Linux 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
With this code:
I have this message:
If I write same code in Javascript using
noble
, it's working.The difference is
l2_bdaddr_type
value.Rumble
set to 1 (BDADDR_LE_PUBLIC
) whereNoble
set to 2 (BDADDR_LE_RANDOM
).In
peripheral.rs
file if I change:to
It's work nice.
Regards,
The text was updated successfully, but these errors were encountered: