I'm new to iOS and BLE. I've been following a tutorial to connect and send data to a BLE receiver board on an Arduino. The tutorial was designed for a different board, and I'm using the (the BLE board is the Adafruit nrf8001 if that might help).
The following code sets up the UUIDs...
let BLEServiceUUID = CBUUID(string: "6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
let PositionCharUUID = CBUUID(string: "6E400002-B5A3-F393-E0A9-E50E24DCCA9E")
let BLEServiceChangedStatusNotification = "kBLEServiceChangedStatusNotification"
And this code connects my iOS device to the BLE board.
central.connectPeripheral(peripheral, options: nil)
I then have a slider set up in my ViewController, and I want to send the value of that slider to the BLE board. Here's my writePosition
function:
func writePosition(position: UInt8)->NSData {
let currentValue = NSUserDefaults.standardUserDefaults().floatForKey("sliderValue")
var currentValueString=NSString(format: "%.5f", currentValue)
var writeType:CBCharacteristicWriteType
let newString:NSString = currentValueString
let data = NSData(bytes: newString.UTF8String, length: newString.length)
peripheral?.writeValue(data, forCharacteristic: self.positionCharacteristic, type: writeType)
return data
}
Note that both my arduino AND my app confirm that they are indeed connected. However, if I change the slider value in the app, it does not send its value to the BLE board. What am I doing wrong??
Thanks in advance!