Interpret Characteristic Properties (iOS and BLE) - ios

I am reading characteristic properties from a BLE device from my iPhone.
However, some of the properties I am seeing (like 0xA, 0x22) are not in the enumerated list that Apple provides. Are these properties a combination of 2 or more enumerated values? Or are these custom properties from the manufacturer? Need guidance on this.

As you can read in the documentation:
Values representing the possible properties of a characteristic. Since
characteristic properties can be combined, a characteristic may have
multiple property values set.
In other words, a characteristic may have more than one property. That makes sense as you can, for example, have a characteristic which can be read (CBCharacteristicPropertyRead) and written to (CBCharacteristicPropertyWrite).
In this case the value of CBCharacteristic's properties would be the bitwise OR of CBCharacteristicPropertyRead and CBCharacteristicPropertyWrite, which is 0xA.

Related

What's the difference between .setPreferredInput(...) and .setPreferredDataSource(...)?

What's the difference between .setPreferredInput(_ inPort: AVAudioSessionPortDescription?) and .setPreferredDataSource(_ dataSource: AVAudioSessionDataSourceDescription?)?
Both functions can be used to determine the active or preferred microphone.
By calling:
import AVFoundation
let availableInputs = AVAudioSession.sharedInstance().availableInputs
I have an array containing built-in microphones, maybe an earphone microphone if connected, and so on. Each value in this array can be passed as a single argument to both functions. In the Data Source situation, you can pass it as an argument by calling availableInputs![0].dataSources, for example.
Is there any difference between them? How and when using they? .setPreferredDataSource(...) is more generic and can be called for input and output devices, but besides it, I can't see much difference between them.
I got an explanation here in the documentation, but it doesn't help much:
Setting a Preferred Input:
To discover built-in or connected input
ports, use the audio session’s availableInputs property. This property
returns an array of AVAudioSessionPortDescription objects that
describe the device’s available input ports. Ports can be identified
by their portType property. To set a preferred input port (built-in
microphone, wired microphone, USB input, and so on) use the audio
session’s setPreferredInput:error: method.
Setting a Preferred Data Source:
Some ports, such as the built-in
microphone and some USB accessories, support data sources. Apps can
discover available data sources by querying the port description’s
dataSources property. In the case of the built-in microphone, the
returned data source description objects represent each individual
microphone. Different devices return different values for the built-in
mic. For instance, the iPhone 4 and iPhone 4S have two microphones:
bottom and top. The iPhone 5 has three microphones: bottom, front, and
back.
Individual built-in microphones may be identified by a combination of
a data source description’s location property (upper, lower) and
orientation property (front, back, and so on). Apps may set a
preferred data source by using the setPreferredDataSource:error:
method of an AVAudioSessionPortDescription object.

It is possible that CAN bus node have multiple identifiers?

I want to use CANopen, and by the preconfigured set a device can have more than one COB-ID(as it has different function codes)
I want to know if the CAN bus frame identifier uses CANopen's COB-ID as it is.
A CANopen node cannot use multiple identifiers at the same time, but it's technically possible to reconfigure the node-ID. According to CiA301 - CANopen application layer and communication profiles, during NMT state initialization the parameters of the manufacture specific profile area and of the standardized device profile area are set to their power-on values.
One way to implement this is to assign a default node-ID for the CANopen node. Then reserve a SDO object in the object dictionary to modify the node-ID after reset or power-on. Note that if you want to fully follow CANopen standard, when you change the node-ID, the CAN-ID allocation modify the IDs for the other NMT states and communication objects such as SDO, PDO, etc.
Check this link for further information.

iOS swift BLE read multiple characteristics

I am trying to design an app that read several temperatures. Is it true that one characteristic UUID can only handle 1 value? If so, how can I read multiple values?(For instance, temperature 1, temperature 2, temperature 3...) Do I need to declare multiple characteristic UUIDs myself? But if I only declare those in my app, how would the peripheral know what UUID corresponds to what value then? Most of the example only read one value (temperature, heart rate,etc)
You can get different values from the same characteristic. For that, you may have to write different values to the write characteristic. For example, say your write characteristic is A and your read characteristic B.
You can write a value to A like this
[self.discoveredPeripheral writeValue:data
forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
where data varies as per the request that you would like to make.
For your read characteristic B, the indication property should be set to YES as follows in the didDiscoverCharacteristicsForService delegate callback
if (c.properties & CBCharacteristicPropertyIndicate) {
[peripheral setNotifyValue:YES forCharacteristic:c];
}
Now whenever you write a value to A, you will get a callback on the delegate method didUpdateValueForCharacteristic. You will have to handle the response properly.
Of course, for all of this to work, your ble device should be programmed accordingly.
Note that the code is written in Objective-C

Differences between CBUUID and NSUUID in swift

Where are the differences between the CBUUID and the NSUUID object?
I have seen to fill the scanForPeripheralsWithServices with both objects in different cases... Apple expect an CBUUID object so I would prefer to use this type or?
My example:
let MY_SERVICE_UUID = CBUUID(string: "hdl83h6sd-gl95-bn4f-37gd-jd73hd0tn8za")
func scanForPeripheralsWithServices(serviceUUIDs: MY_SERVICE_UUID,nil)
An NSUUID is a 128 bit number that is used to uniquely identify objects, types and other items. It can be accessed as bytes or is commonly used in a string form - 68753A44-4D6F-1226-9C60-0050E4C00067. The class includes methods for creating both random UUIDs and instances initialised with a specialised value.
Bluetooth also uses 128 bit identifiers for characteristics and services. The Bluetooth SIG has defined many "well known" services and characteristics. These are represented as a 16 bit value which is combined with the Bluetooth base UUID to get the full 128 bit value.
The CBUUID methods are aware of these well known values and can automatically transform the 16 bit values into their 128 bit equivalent. A CBUUID can also be initialised with a 128 bit value if you aren't using well known values (I.e. You have created your own private services and characteristics)
For example initialising a CBUUID with CBUUID(string:"180F") is ok (this is the battery service) but NSUUID(string:"180F") would fail because it needs all 128 bits.
When working with Core Bluetooth you will use CBUUID for services and characteristics. An NSUUID is used for the peripheral identifier since that is just a MAC with no special values defined.

How to store and update past RSSI values in iOS app?

I've developed an iOS app that can read RSSI values from the surrounding Estimote Beacons. These RSSI values are fluctuating and to get a smooth value I need to use a filter. I am trying to use [Kalman filter] which needs some past RSSI values. Now, I am able to get the current RSSI values but cannot store them in database for filtration purpose. How can I store these RSSI values in database? I am using Objective-C for coding.
Thank you.
At the line before you store the current RSSI value, take that value and store it in a similar variable called previousValue or something similar. Then you can do what you wish with it. As it's an NSNumber type, just invoke previousValue.intValue or similar to be able to store the type you need (or just store the NSNumber itself).
If you need more values just add each previousValue to an array variable. You shouldn't need that many previous values though for a Kalman filter, surely.
If you do need to store the data, CoreData or using SQLite directly are two possibilities. Or store the data in a UIDocument. If your question is really asking how to do these things, I would re-state your question. Otherwise there are countless resources for those techniques...

Resources