kumoh national institute of technology
Networked Systems Lab.

NUC Project Open Source

NSL > Researches> Industrial IoT> NUC Project Open Source
About Bluetooth data process
By :
Date : 2017-05-29
Views : 38

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

let data = characteristic.value

guard data != nil else { return }


delegate.serialDidReceiveData(data!)

if let str = String(data: data!, encoding: String.Encoding.utf8) {

let str1:NSString = str as NSString

let arr = str1.components(separateBy: ".")


let msg1 = arr[0]

let msg2 = arr[1]

let msg3 = arr[2]


if msg1 == "temp"{

if msg2=="+" 

courrent_temp = "(msg3)"

else

courrent_temp = "-(msg3)"

}

else if msg1 == "rec" {

if msg2 == "+"

courrent_weight = msg3

else

courrent_weight = msg3

}

}

}