Hi all,
- Linux distro :
Ubuntu 18.04.2 LTS (Bionic Beaver)
- Kernel version:
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
dmesg | grep -i bluetooth
[ 2.750304] Bluetooth: Core ver 2.22
[ 2.750318] Bluetooth: HCI device and connection manager initialized
[ 2.750320] Bluetooth: HCI socket layer initialized
[ 2.750322] Bluetooth: L2CAP socket layer initialized
[ 2.750326] Bluetooth: SCO socket layer initialized
[ 2.771778] Bluetooth: hci0: using rampatch file: qca/rampatch_usb_00000302.bin
[ 2.771780] Bluetooth: hci0: QCA: patch rome 0x302 build 0x3e8, firmware rome 0x302 build 0x111
[ 2.851976] Bluetooth: hci0: using NVM file: qca/nvm_usb_00000302.bin
[ 4.933220] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 4.933221] Bluetooth: BNEP filters: protocol multicast
[ 4.933223] Bluetooth: BNEP socket layer initialized
[ 21.849736] Bluetooth: RFCOMM TTY layer initialized
[ 21.849741] Bluetooth: RFCOMM socket layer initialized
[ 21.849744] Bluetooth: RFCOMM ver 1.11
With this code:
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,
};
It's work nice.
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: 7, has_scan_response: false }, characteristics: {}
SockaddrL2 { l2_family: 31, l2_psm: 0, l2_bdaddr: 9C:B6:D0:E7:F3:64, l2_cid: 4, l2_bdaddr_type: 0 }
Bind socket ok
Cfg socket ok
Connect socket ok
Is sphero connected: true
Characteristic { start_handle: 2, end_handle: 65535, value_handle: 3, uuid: 2A:00, properties: READ }
Characteristic { start_handle: 4, end_handle: 65535, value_handle: 5, uuid: 2A:01, properties: READ }
Characteristic { start_handle: 6, end_handle: 65535, value_handle: 7, uuid: 2A:04, properties: READ }
Characteristic { start_handle: 9, end_handle: 65535, value_handle: 10, uuid: 2A:05, properties: INDICATE }
Characteristic { start_handle: 13, end_handle: 65535, value_handle: 14, uuid: 00:02:00:03:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: WRITE_WITHOUT_RESPONSE }
Characteristic { start_handle: 15, end_handle: 65535, value_handle: 16, uuid: 00:02:00:02:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: WRITE | NOTIFY }
Characteristic { start_handle: 18, end_handle: 65535, value_handle: 19, uuid: 00:02:00:04:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: READ }
Characteristic { start_handle: 20, end_handle: 65535, value_handle: 21, uuid: 00:02:00:05:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: WRITE_WITHOUT_RESPONSE | WRITE }
Characteristic { start_handle: 23, end_handle: 65535, value_handle: 24, uuid: 2A:19, properties: READ | NOTIFY }
Characteristic { start_handle: 27, end_handle: 65535, value_handle: 28, uuid: 00:01:00:02:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: WRITE_WITHOUT_RESPONSE | WRITE | NOTIFY }
Characteristic { start_handle: 30, end_handle: 65535, value_handle: 31, uuid: 00:01:00:03:57:4F:4F:20:53:70:68:65:72:6F:21:21, properties: WRITE_WITHOUT_RESPONSE | WRITE | NOTIFY }
Regards,
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/LinuxWith this code:
I have this message:
If I write same code in Javascript using
noble, it's working.The difference is
l2_bdaddr_typevalue.Rumbleset to 1 (BDADDR_LE_PUBLIC) whereNobleset to 2 (BDADDR_LE_RANDOM).In
peripheral.rsfile if I change:to
It's work nice.
Regards,