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
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?
Can you add a demo app?
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.
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
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
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!
Hello!
how can i scan the list of available services?
Thank you
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.