0

I want to control my HM-11 BLE module from phone. My code works when I want to send string to the BLE module. But now I need to send AT commands and I'm lost. Here is part of the code:

@IBAction func sendButton(_ sender: AnyObject) {
    //writeValue("AT")  Its work, but send string
    let mydata = "AT"
    //let bytes : [UInt8] = [ 0x41, 0x54 ]
    //let data = Data(bytes:bytes)
    let directAttay : [UInt8] = Array(mydata.utf8)
    writeValue(directAttay)
}

I tried many options but allways get error, cannot.

If I try to send the data (in this code part up commented out) I get this:

ViewController.swift:36:20: Cannot convert value of type 'Data' to expected argument type 'String'

When I try to send directArray, I get this error:

ViewController.swift:36:20: Cannot convert value of type '[UInt8]' to expected argument type 'String'

Bista
  • 7,869
  • 3
  • 27
  • 55
imi79
  • 9
  • 1
  • Where does the `writeValue` function come from? How is it defined? You probably need another function which takes a Data or Array argument instead of a String. – Martin R Sep 09 '16 at 05:04
  • check this: http://stackoverflow.com/questions/32769929/convert-bytes-uint8-array-to-int-in-swift – Bista Sep 09 '16 at 05:10

0 Answers0