I'm working on a tracker iOS app to track the (GPS) position of a device (the device is currently an Arduino Uno with Adafruit Bluefruit LE UART Friend for Bluetooth connection and a Ublox GPS module for GPS coordinates). I've set up the Arduino and an iOS app and I successfully receive longitude and latitude through separate characteristics via a one service.
To add/update an Annotation in a MapkitView with the location of my tracker device I need to access the longitude and latitude in one function. However the BLEHandler and BLEHandlerDelegate both only send a values from one characteristic (latitude or longitude). I therefore think I need some function or adjustment where I can join these two values (latitude & longitude) to access in the ViewController.
Can you give some guidance or show some example code on how to make this work?
I'm kind of new in the programming world so forgive me of any naivety.
Many thanks in advance.
Here is some code sample: BLEHandler
func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
var dataStrLat : String?
var dataStrLong : String?
if characteristic.UUID == UUID_CHAR_LAT {
var charValue : NSData = characteristic.value
dataStrLat = NSString(data: charValue, encoding: NSASCIIStringEncoding) as? String
//var dataStrLat : String? = NSString(data: charValue, encoding: NSASCIIStringEncoding) as? String
if(dataStrLat == nil){
dataStrLat = "blank"
}
NSLog("%@: Characteristic (gps lat) changed for %@ with value %@", TAG, peripheral.name, dataStrLat!)
delegate.receivedStringValue(peripheral.name, dataStr: dataStrLat!)
}
if characteristic.UUID == UUID_CHAR_LONG {
var charValue : NSData = characteristic.value
dataStrLong = NSString(data: charValue, encoding: NSASCIIStringEncoding) as? String
//var dataStrLong : String? = NSString(data: charValue, encoding: NSASCIIStringEncoding) as? String
if(dataStrLong == nil){
dataStrLong = "blank"
}
NSLog("%@: Characteristic (gps long) changed for %@ with value %@", TAG, peripheral.name, dataStrLong!)
delegate.receivedLongitudeValue(peripheral.name, dataStr: dataStrLong!)
}
}
BLEHandlerDelegate
func receivedStringValue(deviceName: String, dataStr : String)
func receivedLongitudeValue(deviceName: String, dataStr : String)