BLE Swift écrire characterisitc

Je suis en train dur pour obtenir mon TI sensortag capteur de température de l'en informer. Selon http://processors.wiki.ti.com/images/a/a8/BLE_SensorTag_GATT_Server.pdf j'ai besoin de régler la valeur de la caractéristique avec l'UUID de la F000AA02-0451-4000-B000-000000000000 à "01:00". Voici ce que je fais:

import UIKit
import CoreBluetooth
class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate{
var centralManager:CBCentralManager!
var blueToothReady = false
var connectingPeripheral: CBPeripheral!
@IBOutlet weak var textField: UITextView!
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidLoad() {
super.viewDidLoad()
startUpCentralManager()
}
func startUpCentralManager() {
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func discoverDevices() {
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: (NSDictionary), RSSI: NSNumber!) {
output("Discovered", data: peripheral.name)
self.connectingPeripheral = peripheral
centralManager.stopScan()
self.centralManager.connectPeripheral(peripheral, options: nil)
}
func centralManagerDidUpdateState(central: CBCentralManager!) { //BLE status
        var msg = ""
switch (central.state) {
case .PoweredOff:
msg = "CoreBluetooth BLE hardware is powered off"
println("\(msg)")
case .PoweredOn:
msg = "CoreBluetooth BLE hardware is powered on and ready"
blueToothReady = true;
case .Resetting:
var msg = "CoreBluetooth BLE hardware is resetting"
case .Unauthorized:
var msg = "CoreBluetooth BLE state is unauthorized"
case .Unknown:
var msg = "CoreBluetooth BLE state is unknown"
case .Unsupported:
var msg = "CoreBluetooth BLE hardware is unsupported on this platform"
}
output("State", data: msg)
if blueToothReady {
discoverDevices()
}
}
func centralManager(central: CBCentralManager!,didConnectPeripheral peripheral: CBPeripheral!)
{
peripheral.delegate = self
peripheral.discoverServices([CBUUID.UUIDWithString("F000AA00-0451-4000-B000-000000000000")])
output("Connected", data: peripheral.name)
}
func peripheral(peripheral: CBPeripheral!, didDiscoverServices error: NSError!)
{
if let servicePeripherals = peripheral.services as? [CBService]
{
for servicePeripheral in servicePeripherals
{
output("Service", data: servicePeripheral.UUID)
peripheral.discoverCharacteristics(nil, forService: servicePeripheral)
}
}
}
@IBAction func refreshBLE(sender: UIButton) {
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func peripheral(peripheral: CBPeripheral!, didDiscoverCharacteristicsForService service: CBService!, error: NSError!) {
if let charactericsArr = service.characteristics  as? [CBCharacteristic]
{
for charactericsx in charactericsArr
{
peripheral.setNotifyValue(true, forCharacteristic: charactericsx)
//               *************************
            if charactericsx.UUID.UUIDString == "F000AA02-0451-4000-B000-000000000000"{
output("Characteristic", data: charactericsx)
let data: NSData = "01:00".dataUsingEncoding(NSUTF8StringEncoding)!
peripheral.writeValue(data, forCharacteristic: charactericsx, type: CBCharacteristicWriteType.WithResponse)
output("Characteristic", data: charactericsx)
}
//               *************************

peripheral.readValueForCharacteristic(charactericsx)
}
}
}
func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
if var data :NSData = characteristic.value {
output("Data", data: characteristic.value)
}
}
func output(description: String, data: AnyObject){
println("\(description): \(data)")
textField.text = textField.text + "\(description): \(data)\n"
}
}

Problème est que les périphériques.writeValue... ne semble pas changer quoi que ce soit. J'ai regardé l'objective-c exemple trouvé ici http://www.ti.com/tool/sensortag-sw et pense que les lignes correspondantes à

let data: NSData = "01:00".dataUsingEncoding(NSUTF8StringEncoding)!
peripheral.writeValue(data, forCharacteristic: characteric, type: CBCharacteristicWriteType.WithResponse)

sont ces:

uint8_t data = 0x01;
[BLEUtility writeCharacteristic:self.d.p sCBUUID:sUUID cCBUUID:cUUID data:[NSData dataWithBytes:&data length:1]];

Ce qui me manque?

InformationsquelleAutor gimba | 2014-10-15