kaegi / bluetooth-serial-port Goto Github PK
View Code? Open in Web Editor NEWRust library to interact with Bluetooth devices via RFCOMM channels
License: MIT License
Rust library to interact with Bluetooth devices via RFCOMM channels
License: MIT License
So I tried to use you library for connection to my headphones. But they to use custom uuid for RFCOMM service.
https://github.com/Toxblh/sony-headphones-control-rust-linux as real example.
So I also wrote python prototype, with use custom uuid. And that is log from python
Searching for 70:26:05:10:48:04...
service_matches [{'service-classes': ['96CC203E-5068-46AD-B32D-E316F5E069BA'], 'profiles': [('96CC203E-5068-46AD-B32D-E316F5E069BA', 256)], 'name': None, 'description': None, 'provider': None, 'service-id': None, 'protocol': 'RFCOMM', 'port': 15, 'host': '70:26:05:10:48:04'}]
When I tried to connect via your lib I saw that error:
Error: No RFCOMM service on remote device
Will be cool if will be possible to pass also and uuid if it is custom for device.
I want to connect with gps device via bluetooth on linux.
In console I did:
$ sudo rfcomm connect 0 10:C6:FC:FE:6D:D0 &
$ sudo cat /dev/rfcomm0
$GPGSA,A,3,08,27,11,69,14,18,77,32,,,,,2.5,1.6,1.9*35
$GPRMC,161659.5,A,5521.76350,N,03731.92747,E,000.57,058.2,040718,010.2,E,A*35
$GPGGA,161659.5,5521.76350,N,03731.92747,E,1,08,1.6,204.7,M,13.1,M,,*55
$GPVTG,058.2,T,048.0,M,000.57,N,0001.06,K,A*15
as you can see all data is is ascii, this is nmea protocol,
it is text based.
Then I modify example.rs:
extern crate bluetooth_serial_port;
extern crate mio;
use bluetooth_serial_port::{BtProtocol, BtSocket};
use std::io::Read;
fn main() {
// scan for devices
let devices = bluetooth_serial_port::scan_devices().unwrap();
if devices.len() == 0 {
panic!("No devices found");
}
let device = devices.iter().position(|x| x.name.contains("GLO")).unwrap();
let device = &devices[device];
println!("Connecting to `{}` ({})", device.name, device.addr.to_string());
// create and connect the RFCOMM socket
let mut socket = BtSocket::new(BtProtocol::RFCOMM).unwrap();
socket.connect(device.addr).unwrap();
loop {
let mut buffer: [u8; 20] = [0; 20];
let num_bytes_read = socket.read(&mut buffer[..]).unwrap();
if num_bytes_read == 0 {
println!("read nothing, retry");
}
let s = &buffer[0..num_bytes_read];
println!("raw bytes: {:?}", s);
}
}
and output is:
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
raw bytes: [192, 1, 22, 0, 3, 1, 0, 37, 1, 10, 1, 128, 0, 232, 3, 232, 3, 184, 207, 4]
raw bytes: [0, 19]
this looks completly wrong for me, byte with 0
value, bytes with value 1
and so on.
GPL-3 is quite restrictive for something as fundamental as RFCOMM. Please consider changing to MIT or BSD type license.
I'va started today work on win32 support,
so I create this issue to coordinate work on this issue.
Hello,
I am trying to implement an application that closes the connection if the other device does not send any data.
The problem I find myself in is that the BtSocket.read() is blocking if the other device does not send any data, and killing threads is not supported (and/or safe) in rust.
Do you have any ideas on how to implement safely connection reset in case of timeout?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.