Code Monkey home page Code Monkey logo

bluetoothkit's People

Contributors

barelyreal avatar calebkleveter avatar daij-djan avatar douglowder avatar ericwastaken avatar hamzaozturk avatar jinsasaki avatar mariusc avatar nick-the-uncharted avatar rhummelmose avatar ricobeck avatar yas375 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  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  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

bluetoothkit's Issues

Merging Swift 3

Now that Xcode 8 and Swift 3 have been officially released, should we merge the swift-3 branch into master?

Question: how to find out when a BKRemotePeripheral is ready for send/receive

Hi,
I wonder about how to find out when a BKRemotePeripheral is ready for send/receive.

I scanned and discovered it, connected but AFAICS I need to wait for the discovery of its services and characteristics before I sendData..

I wonder if there already is a mechanism or if I should provide a delegate function on BKRemotePeripheralDelegate for it?

Warning for CBPeripheral delegate re: didModifyServices

I'm getting a CoreBluetooth warning:

[CoreBluetooth] WARNING: The delegate for <CBPeripheral: 0x1740ede00, identifier = 11897F77-4927-47DC-BDE6-B4F9707530C5, name = iPhone, state = connected> does not implement -[peripheral:didModifyServices:]

Looks like it just needs an implementation in the BKCBPeripheralDelegateProxy

Multiple characteristics per service

If I'm reading things correctly, it looks like BluetoothKit as written only supports a single characteristic per service. Is that correct?

If so, that's a rather crippling limitation on an otherwise well-designed library. I'm working on a project designing a new BLE device and app, with a complex custom BLE service with multiple read/write characteristics.

Background scanning

Hi,
I tested BluetoothKit background scanning and I could not make it work. The issue I have encountered is that scanContinuouslyWithChangeHandler actually scans for 3 seconds, pauses for inBetweenDelay of 3 seconds and starts again. Scanning and pause interval are implemented using timers that do not work in background with phone locked.
Info.plist has correct keys since after changes I have made it worked as expected.
In BKScanner.swift I have cloned scanWithDuration function with different name and did not initialised durationTimer. Then I used new function when/where needed (several other changes had to be made to original code).
However I appreciate all help since BluetoothKit is very good library and I didn't had to write all the code myself (-:

If appoint service uuid, it could't find real devices.

Use "centralManager.scanForPeripheralsWithServices(nil, options: nil)", can discovery all device, but use "centralManager.scanForPeripheralsWithServices(configuration.serviceUUIDs, options: nil)", nothing.

This should be the bug of the official.

InternalError

I try out BluetoothKit. I encounter that I always get InternalError(BKError) in callback after trying to scan Peripheral. I have no idea where it goes wrong? Can anyone help? Below code is in UIViewController

`

let peripheral : BKPeripheral = BKPeripheral()
let central : BKCentral = BKCentral()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func server(){
    
    self.peripheral.delegate = self
    
    do {
        let serviceUUID = NSUUID(uuidString: "6E6B5C64-FAF7-40AE-9C21-D4933AF45B23")!
        let characteristicUUID = NSUUID(uuidString: "477A2967-1FAB-4DC5-920A-DEE5DE685A3D")!
        let localName = "My Cool Peripheral"
        let configuration = BKPeripheralConfiguration(dataServiceUUID: serviceUUID as UUID, dataServiceCharacteristicUUID:  characteristicUUID as UUID, localName: localName)
        try self.peripheral.startWithConfiguration(configuration)
        // You are now ready for incoming connections
    } catch let error {
        // Handle error.
        
        NSLog(error as! String)
    }
}

@IBAction func client(){
    
    
    self.central.delegate = self
    central.addAvailabilityObserver(self)
    do {
        let serviceUUID = NSUUID(uuidString: "6E6B5C64-FAF7-40AE-9C21-D4933AF45B23")!
        let characteristicUUID = NSUUID(uuidString: "477A2967-1FAB-4DC5-920A-DEE5DE685A3D")!
        let configuration = BKConfiguration(dataServiceUUID: serviceUUID as UUID, dataServiceCharacteristicUUID: characteristicUUID as UUID)
        try central.startWithConfiguration(configuration)
        // Once the availability observer has been positively notified, you're ready to discover and connect to peripherals.
    } catch let error {
        // Handle error.
        NSLog(error as! String)
    }
}

func peripheral(_ peripheral: BKPeripheral, remoteCentralDidConnect remoteCentral: BKRemoteCentral) {
    
}

func peripheral(_ peripheral: BKPeripheral, remoteCentralDidDisconnect remoteCentral: BKRemoteCentral) {
    
}

func central(_ central: BKCentral, remotePeripheralDidDisconnect remotePeripheral: BKRemotePeripheral) {
    
}

func availabilityObserver(_ availabilityObservable: BKAvailabilityObservable, availabilityDidChange availability: BKAvailability) {
    
    if availability == .available{
        self.central.scanContinuouslyWithChangeHandler({ changes, discovers in
            
            NSLog("\(discovers)")
            }, stateHandler: { newState in
                
            }, errorHandler: { error in
                
                NSLog("error \(error)")
        })
    }else{
        
        self.central.interruptScan()
    }
}

`

fatal error

internal func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) {
    failConnectionAttempt(connectionAttemptForPeripheral(peripheral)!, error: .Internal(underlyingError: error))
}

Optional("Optional(TPMS.BKError.InternalError(Optional(TPMS.BKConnectionPool.Error.TimeoutElapsed)))")
fatal error: unexpectedly found nil while unwrapping an Optional value

Occurs when the connection is bad bluetooth.

qq20160616-0 2x

Example wrong SnapKit project path

Could not easily look at your sample project while the SnapKit project is included with a wrong path reference: There's a ../ too much. I had to copy the SnapKit into the directory above in order to be able to build. Could you resolve this?
Thanks a lot, cheers,
Thomas

tvos support

tvOS is pretty new and as far as I figured out some feature are not available (yet), but do you plan to add support for it next releases even for cocoapods auto install?

Introduce a combined peer (possibly BKCombinedPeer)

A combined peer will take on both the peripheral and central roles and thereby allow for connected devices serving as combined peers to pass data both in-between them, both ways, at the best possible transfer rates.

OS X to iOS

May I ask some questions?
I want my iPhone connect to my mac.which one do you think should be my Peripheral?
And I want to keep running in background,so my mac app could connect with my iPhone(From a distance to close),how can I deal with this? thank you.

peripheral.sendData very slow if NSData is larger than a few bytes

Hi there - love the library so far.

Using the example application, I have been experimenting with reading a file to NSData, then sending the NSData using the "sendData" method.

However, if the NSData I'm sending is even a few KB, the transmission takes a very, very long time. For a 250KB NSData, I'm seeing times around 1-1.5 minutes to do the transfer. Am I doing something wrong, or is this a limitation of the library? Thanks!

Scanning false when config with CBUUID example: "0xCBBB"

instead of configuration with NSUUID 128 bit (example : "**6E6B5C64-FAF7-40AE-9C21-**D4933AF45B23"), i want to set up with CBUUID like "0xCBBB" but the Central scanning interrupted many times. and can not sending data.
Please help

Delay of Sending or Receiving data to BLE Device?

I am using the BLE CC2541 module to interact with my arduino device.

For testing, I connected the TxD pin and RxD pin directly for that I can get the same data when I send data in iOS App.

Like this:

First, I used the Example of this repository. After I modified the UUID of service and characteristic, I successfully scanned my BLE device. But when I send multiple data, it only received one.

And then I created a simple project, It has a button for sending data, a textfield for what to send and a textview for displaying the received data.

The code is like this:

    @IBAction func onSendBtnClicked(_ sender: Any) {
        
        let data: Data = (inputTextField.text?.data(using: String.Encoding.utf8))!
        
        
        central.sendData(data, toRemotePeer: remotePeripheral) { data, remotePeripheral, error in
            guard error == nil else {
                print("Failed sending to \(remotePeripheral)")
                return
            }
            print("Sent to \(remotePeripheral)")
        }
    }

    func remotePeer(_ remotePeer: BKRemotePeer, didSendArbitraryData data: Data) {
        print("Recieved: \(String(data: data, encoding: String.Encoding.utf8) ?? "error")")
        
        receivedTextView.text = receivedTextView.text + String(data: data, encoding: String.Encoding.utf8)!
    }

I filled the TextField with "gghh", after multiple clicking on sendBtn, what it returned like this:

Previously, I used a objective-c library: SerialGATT.h, SerialGATT.m
which can receive the data at real time when I tap the button.
I am using pod 'BluetoothKit', '~> 0.4.0'.

2 way communication

Hi there,

As far as I can tell there is no way to have 2 way communication with BluetoothKit today. Is this possible and on the roadmap?

Thanks, enjoying BK so far! Just ran into a road block though with the 2 way communication.

BKPeer sendData, tasks get stuck when the sendDataTasks array hold more than 1 task.

The code in BKPeer.swift, sendData is as follows after a task is added to the sendDataTasks array

if sendDataTasks.count == 1 {
            processSendDataTasks()
        }

This processes the tasks if there's exactly 1 task in that array. Unfortunately, when you have multiple peers and/or you're sending a several data tasks, the array will grow past 1 and the processSendDataTasks() is never called.

The code should be:

if sendDataTasks.count >= 1 {
            processSendDataTasks()
        }

I'll follow this with a PR to address it.

Thanks,

Eric.

Two potential bugs.

Thank you for writing this repo which save me a lot of time.
Here are two potential bug I came across:
First, Core Bluetooth seems to have a slight chance to call func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) twice for a single connecting behavior.
Code following may output core bluetooth bug? when keeping switching on and off bluetooth.

internal func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {
        if self.connectionAttempts.count == 0 {
            print("core bluetooth bug?")
        }
        succeedConnectionAttempt(connectionAttemptForPeripheral(peripheral)!)
    }

The second one is that if an timeOut error occur . failConnectionAttempt will be called, which call cancelPeripheralConnection and cancelPeripheralConnection lead to call of didFailToConnectPeripheral, and when didFailToConnectPeripheral happen, the corresponding connectionAttempt is already removed and the program will crash .

IMO, both of those two bug can be avoided by avoiding force unwrap result of connectionAttemptForPeripheral.

PS: There is a good chance that I mistake something .

Scanning for identifier other than UUID

Hi

Would it be possible to scan for an identifer other than the device UUID? For example, I was thinking about keying off of the user's phone number. Would this be problematic due to security issues?

Thank you for all the help!

Peripheral switches off, Central doesn't react correctly

My Peripheral is a Mac app and my Central is an iOS app. I would think that when my central is connected to a peripheral, if that peripheral is switched off (i.e I quite the Mac app) the central should recognise the peripheral has disconnected.

In fact the following is logged in my Xcode console when I'm debugging my Central

2016-11-15 19:01:39.337791 MyApp[5707:2457596] [CoreBluetooth] WARNING: The delegate for <CBPeripheral: 0x1742e2d00, identifier = , name = <name, state = connected> does not implement -[peripheral:didModifyServices:]

I have removed my UIUID and my name from the message

I'm using MacOS Sierra, Xcode 8.1 and Swift 3

fail to build with carthage

Hi,

using this line, in my cart file
github "rasmusth/BluetoothKit" ~> 0.2.0
using carthage v 0.18.1, Xcode 8.1, Sierra 10.12.1

fail, with a dependency error code 65.
the log is long, I can provide it, if needed.

I noticed that in the checkout folder, the bluetooth project seem to be in swift 2...

if I download the project, manually, from github : it compile straight away.

thanks for any help
Olivier

Update Readme

For cocoapods, your short useful note on how to specify BluetoothKit in the Podfile specifies version 0.2.0 — I believe it should be 0.4.0.

Support for Beacon Advertising

I couldn't find support for starting a Peripheral that advertises with iBeacon data.
Maybe there could be a BKPeripheralConfiguration for advertising iBeacon.

Also, is it currently possible to start advertising and already set the data for certain characteristics? I'm considering using this in my app, but in my scenario the peripheral doesn't send the data to the centrals, but rather makes available certain data via characteristics that centrals can read at any time.

Thanks!

CBCentralManager is always poweredOff on iOS 11

I have installed the latest update of the code but I am facing a serious problem when I try to connect on iOS 11.0+ devices.

Every time I receive a message that says: 'Please turn on Bluetooth to connect to the device'. I have traced the code and it seems that the CBCentralManager state is always poweredOff.

I tested BLE connection on the same iOS 11 device with other apps and it works fine. Sometimes it just needed to turn off then turn on the Bluetooth from settings to be able to connect. Other apps works after turning off then on the Airplane mode. But neither works with my app and its Bluetooth kit code.

Any solution please ?

Bluetooth LE not available or calling scan and/or connect before available

I really appreciate that you share this amazing looking library. I downloaded the example project and ran it on a real device. But there is an issue with the bluetooth "Unsupported" or "Unavailable". The bluetooth on the device is active and the error says:
Error from scanning: InternalError(Optional(BluetoothKit.BKCentralStateMachine.Error.Transitioning(BluetoothKit.BKCentralStateMachine.State.Unavailable(BluetoothKit.BKUnavailabilityCause.Unsupported), [BluetoothKit.BKCentralStateMachine.State.Available])))

If you can help me, I would be thankful
tastyapp

Cleaner access to Characteristics & Changes

Would be great if we could access the characteristics and get change notifications via the BKRemotePeerDelegate. Right now it looks like the configuration is locked down. This would help greatly with more advanced devices that switch characteristics based on the mode they're in.

BKPeriphial Protocol

I am following the example of setting up a peripheral, and I am stuck when adding the BKPeriphial to my view controller class. How do I implement the BKPeriphialController Protocol?

ios10: CBCentralManagerState and CBPeripheralManagerState merged to CBManagerState

Hi

on ios10 apple merged CBCentralManagerState and CBPeripheralManagerState into CBManagerState
they basically renamed the enum... I added a workaround... I use the rawValue and then create the enum again

e.g.
let newCause = BKUnavailabilityCause(centralManagerState: CBCentralManagerState(rawValue: central.state.rawValue)!)

Couldn't work properly on iOS 10.

I'd like to use this framework for my app, but I faced following issue on IOS10 with Swift3.0.

Error from scanning: The operation couldn't be completed. (BluetoothKit.BKError error 3.)

Also I checked this on iOS 9(XCode 7.3, iPhone 5s, Gimbal Beacon Series 21) , but occurred the same issue.
(I tried with this framework https://github.com/tinydream12/Bluetoothkit, but the same result.)

Does anyone know how to avoid this?
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.