drama999 / littlebluetooth Goto Github PK
View Code? Open in Web Editor NEWA simple library that helps you in connecting with BLE devices
License: MIT License
A simple library that helps you in connecting with BLE devices
License: MIT License
There is a fix for that but it hasn't been released: NordicSemiconductor/IOS-CoreBluetooth-Mock#37
Otherwise, SwifUI previews don't work now because of this in Xcode 12.5. Probably, tests, too.
Not really an issue; but more on the usage.
How do you use this to discover services and characteristics after finding the peripheral with discovery?
Thanks!
Can you add a demo app?
I neee more details :)
First of all, great work on the library. I've just started with it and it's looking great!
I have a question though. When using LittleBlueTooth#startListen
, I don't receive an initial value. Is this by design?
For example:
littleBT.read(from: Self.BATTERY_CHARACTERISTIC)
will publish a value as soon as I subscribe
but
littleBT.startListen(from: Self.BATTERY_CHARACTERISTIC)
will not publish anything as soon I subscribe
I have something like this
func getSpeed() -> AnyPublisher<SpeedState, LittleBluetoothError> {
littleBT.startListen(from: Self.SPEED_CHARACTERISTIC)
.prepend(littleBT.read(from: Self.SPEED_CHARACTERISTIC))
.handleEvents(receiveCompletion: { completion in
switch completion {
case .finished:
break
case .failure(let error):
log.error("SPEED_CHARACTERISTIC read/listen failed with error: \(error)")
}
})
.eraseToAnyPublisher()
}
func getBattery() -> AnyPublisher<BatteryState, LittleBluetoothError> {
littleBT.startListen(from: Self.BATTERY_CHARACTERISTIC)
.prepend(littleBT.read(from: Self.BATTERY_CHARACTERISTIC))
.handleEvents(receiveCompletion: { completion in
switch completion {
case .finished:
break
case .failure(let error):
log.error("BATTERY_CHARACTERISTIC read/listen failed with error: \(error)")
}
})
.eraseToAnyPublisher()
}
If I subscribe to just one of these (no matter which one) at once, it works just fine. If, on the other hand, I do something like
Publishers.CombineLatest(
bikeRepository.getSpeed(),
bikeRepository.getBattery()
)
And subscribe to that, one of the subscriptions will immediately fail with characteristicNotFound
I was thinking of using the flow similar to what kable does (https://github.com/JuulLabs/kable). There, you can easily do:
override fun getBattery(): Flow<Metric> = peripheral
.observe(BATTERY_CHARACTERISTIC)
.map { it.asBatteryMetric() }
override fun getSpeed(): Flow<Metric> = peripheral
.observe(SPEED_CHARACTERISTIC)
.map { it.asSpeedMetric() }
And then
override fun getMetrics(): Flow<List<Metric>> = combine(
getSpeed(),
getBattery
) { speed, battery ->
// do something, like create a model containing all the metrics
}
This library actually has iOS support through KMM, so this is what observe does: https://github.com/JuulLabs/kable/blob/main/core/src/appleMain/kotlin/Peripheral.kt
Hello!
how can i scan the list of available services?
Thank you
For some reason when i use your library i cant send data to esp32. using pure corebluetooth i could send data so characteristics etc are correct. I noticed you use peripheral.write instead writeValue. could this be issue?
` @objc func onTapWriteCharacteristic(_ sender: Any) {
let data = HeartRateSensorPositionRequest(position: HRMSensorPosition(rawValue: 1)!)
StartLittleBlueTooth
.write(for: self.littleBT, to: hrmControlPointChar, value: data, response: false)
.sink(receiveCompletion: { completion in
self.appendLog("Completion \(completion)")
}) { (answer) in
self.appendLog("Answer \(answer)")
}
.store(in: &disposeBag)
}`
When I use LittleBlueTooth to communicate with a device periodically, the combine debug print fills up the console.
Is it possible to turn on/off the debug output?
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.