BLE control from Widgets? - ios

I know very well how to directly connect to BLE hardware, and send/recieve data using CBCentralManagerfrom an iOS app.
I am trying to find a way to create a BLE connection and data exchange from Today's view (Extension?).
That means creating a widget with buttons , where each button send some BLE data, for example turn on/off a light.
I couldn't find any example online. Can I manipulate my Swift BLE code to do so?

Related

How to send data through central mode to peripheral?

I'm developing an application where Client App starts BLE scanning in "Central" mode and there is a scanner App which Acts as "Peripheral",client will keep scanning for Scanners (Beacons) with specific id (where the Scanners are advertising the same id) when that both id match data is sent over BLE to the scanner app I have an example code which works perfectly from peripheral to central but i don't have idea about my case how it work.
The Demo which you are following is the correct one for a beginner. In this Demo, app is sending text data from TextView. The text data is passed in octet form, in iOS it is considered as Data (.utf8).
Now, question is, which type of data you want to send from Central to Peripheral.
The General flow is:
1. Central will proximate peripheral so that other Bluetooth manager can scan it.
2. Once anyone try to connect with that peripheral, then on successful connection, it will return available Services and Characteristics inside of those each services.
3. Based on characteristic, you can write your own logic to send text, images, audio, video or anyother data from Central to Peripheral.
Just follow the Demo link which you are following. Thanks.

How to retrive data from Bluetooth when app in background iOS?

My scenario is:
Another (whatever app it is) try to retrieve the value from a Bluetooth device, But Bluetooth device doesn't send data other than our application.
Another application wants Bluetooth data it needs to call our app in background mode to perform an operation also in the background.
In short:
Retrieve data from Bluetooth in the background and share that content to another application.
If I tried using Custom URL it's open our application into the foreground. So, this one not covers our expectation.
Is that possible with Widget kind of? or any other method.
If any info missed let me know to understand my scenario.

Sensor to iOS connection

We're looking to build a small device connected to a sensor that transmits data to an iPhone, which subsequently takes the data, stores it and graphs it. However we want the iPhone to be able to change the polling data on the device by sending small amounts of data. I've been doing some reading and it seems like bluetooth LE does not allow for this type of streaming connection. Is this correct? Would switching to an Android platform be better? What would you all suggest?
With Bluetooth LE, you have complete control over the flow, even on iOS.
That said, there are a couple of things to know:
BTLE devices only have read-only "characteristics" (but can be dynamic)
There is no way to "push" data, only notify a change to the listening devices
So instead of saying - "Hey, 'streaming_type' should change from 'wind' to 'temperature'", you would say - "Hey, 'streaming_type' has changed, come read it".
It is not specific to iOS, it is the way BTLE works. So if you want an iPhone to be able to control your device, your application simply needs to setup a BTLE "streaming_type" characteristic, and then update it when the user wants to change the type of data being streamed.
Your BTLE device would then look for this specific "streaming_type" characteristic, and go read it when it receives a update notification.

How to make two way communication using ibeacons in ios?

I want to send data from one iPhone device to another iPhone device, in that one device work as transmitter and other work as receiver. Receiver can also send data to transmitter(server).
So is there any way using code to do this ?
iBeacon is a transmit-only proximity technology, that's why it's found in the Core Location framework. It is not designed, nor does it support, bi-directional communication. An iBeacon advertises its presence and that is all.
If you want to perform data transfer over Bluetooth, have a look at the Core Bluetooth framework and its samples, such as the CoreBluetooth Temperature Sensor sample.

Transmitting data with CoreBluetooth

I'm developing an iOS app with an accompanying Bluetooth LE peripheral. The one step I don't seem to be able to solve is how to actually transmit the data from my app to the peripheral or vice versa.
What I've built so far is a test app that can connect to my sample Bluetooth peripheral, and read all of its services/characteristics/descriptors. It can toggle notifications for a given characteristic, and write to given characteristics. It is just this last step of "transmit n bytes to the peripheral, and receive m bytes from the peripheral" that I can't seem to figure out.
Looking at the External Accessory Framework (what I would use if Apple would actually give me MFi approval for this project), they give you input and output streams on a given session to communicate with the accessory, but no such object exists for CoreBluetooth.
Is this simply an oversight on Apple's part on the functionality of CoreBluetooth? Or do I simply need to develop my own Bluetooth service profile to handle the inflow/outflow of data to and from the peripheral?
LE is fundamentally designed to work with these GATT based profiles, which are suited for monitoring sensors, not for data streams. While LE does allow for additional L2CAP streams to be opened for custom protocols, Apple's CoreBluetooth doesn't provide access to do so.
You can build a custom profile with private services and characteristics and have it work kind of like SSP; that's the way I'm using my BLE module to get data from some sensors to my app. The module I bought (Microchip's RN-4020) already has a custom profile made specifically for this known as MLDP (Microchip Low-energy Data Profile).
The way I get the data in my iOS app is by subscribing to the private characteristic, thus being notified when the values are updated. So far it has been working great, and the data rate can go up to 20 kbps according to Microchip (I haven't tested its limits, since I don't need much speed). Here's a link to Microchip's product page: http://www.microchip.com/wwwproducts/Devices.aspx?product=RN4020
Good luck!
You can use the bluetooth.org 'Immediate Alert Service' uuid=1802 with characteristic uuid=2A06 with property=write_no_response to send one byte values to your peripheral device from your iPhone. The peripheral device must be programmed to act on the data that is sent. For example, you might use a button on an iPhone app to send a hex address that causes one or more port pins to turn on or off on the peripheral. While this is not using the Alert Service as it was intended, it does provide an easy way to test out data transfer to a peripheral device. The same process could be used to send sequential data bytes similar to a serial data stream. I have not yet tried sending more complex data streams. The write_no_response does not provide any feedback to the app as to whether the data was received by the peripheral.
The IOS TemperatureSensor.xproj is an example of code for reading temperature data from a peripheral. The OSX HealthThermometerClient.xproj has the code needed to decode the somewhat complex thermometer data structure. The IOS TI-BLE-Demo.xproj TIBLECBKeyfob.m has code for reading and writing characteristic values, such as, reading temperature or battery levels from a peripheral device.

Resources