Coder Social home page Coder Social logo

drama999 / littlebluetooth Goto Github PK

View Code? Open in Web Editor NEW
79.0 79.0 16.0 1.43 MB

A simple library that helps you in connecting with BLE devices

License: MIT License

Swift 96.77% Objective-C 0.23% Shell 3.01%
bluetooth-low-energy combine ios macos react state-restoration swift

littlebluetooth's Introduction

Hello there ๐Ÿ‘‹

  • โ˜ ๏ธ Biomedical Engineer
  • ๐Ÿง‘โ€๐Ÿ’ป Self taught Programmer
  • ๐Ÿค“ Tinkerer โšก๏ธ๐Ÿช›โš™๏ธ๐Ÿ–ฅ
  • ๐Ÿ“ฑ More than 4 apps on AppStore as Indie Developer
  • ๐Ÿ“ I also write on Medium
  • ๐Ÿ”ญ Iโ€™m currently working on a device to improve boxers ๐ŸฅŠ reflexes

littlebluetooth's People

Contributors

drama999 avatar rolandhordos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

littlebluetooth's Issues

Can I suppress debug output?

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?

Using startListen on more than 1 characteristic at once fails with characteristicNotFound

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

LittleBlueTooth#startListen behavior

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

Discovering services

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!

List of services

Hello!
how can i scan the list of available services?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.