rhummelmose / bluetoothkit Goto Github PK
View Code? Open in Web Editor NEWEasily communicate between iOS/OSX devices using BLE
License: Other
Easily communicate between iOS/OSX devices using BLE
License: Other
Now that Xcode 8 and Swift 3 have been officially released, should we merge the swift-3 branch into master?
is it have plan for swift3?
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?
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
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.
How i can send data from central?
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 (-:
From my understanding, it doesn't support multiple services UUIDs. Do you have any plans to support this in the future?
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.
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()
}
}
`
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.
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 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?
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.
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.
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!
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
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.
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'
.
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.
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.
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 .
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!
Is it possible with BluetoothKit to vend a bluetooth service from desktop to mobile to use the mac as a keyboard?
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
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
I'm thinking in a project that connects multiple Bluetooth devices like Tile or Tracker.
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.
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!
Is is possible read RSSI value of scanned peripheral multiple times before connecting to it?
Thanks.
Hi,
Is it possible to print qr code/barcode using this library? If so, can you please guide me 'cause we are planning to make an app which has feature like qr code/barcode printing. Or it's a pleasure if you can provide an example?
Many thanks!
Hey, great work as it seems!
Unfortunately, it seems to me that you integrated Swift 3 support, but you didn't release it to CocoaPods yet, is there a specific reason for that?
Cheers!
Excuse me, Only supports Peripheral to send data to Central?
Create Mac as Central and iPhone app as peripheral but app can not connect.
Add support for chunking of data. Currently read/writes of data that is too long silently fail
I just came across this typo (or what seems to be a typo). Just FYI.
You're passing the oldCause
as the newCause
and vise versa.
BluetoothKit/Source/BKPeripheral.swift
Line 210 in bfd0fc1
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 ?
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
Is there any reason for this?
Hi,
for ios10: removed willRestoreState delegate so we get no warning about missing restorationID
// internal func peripheralManager(peripheral: CBPeripheralManager, willRestoreState dict: [String : AnyObject]) {
// // print("peripheralManager: (peripheral) willRestoreState: (dict)")
// }
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.
Swift can work well. Can you use the object-c to rewrite it?
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?
Hi
the pod 0.4.0 isn't available via cocoapods
plz add it :)
Hi,
is there a way to subscribe to a characteristic?
thanks.
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)!)
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.
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.