Reading a bluetooth characteristic value on an Iphone

  • I am trying to read the characteristic value from the LoPy on an Iphone with the example code from the Pycom documentation.

    from network import Bluetooth

    bluetooth = Bluetooth()

    def conn_cb (bt_o):
    events =
    if events & Bluetooth.CLIENT_CONNECTED:
    print("Client connected")
    elif events & Bluetooth.CLIENT_DISCONNECTED:
    print("Client disconnected")

    bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)




    char1_read_counter = 0
    def char1_cb_handler(chr):
    global char1_read_counter
    char1_read_counter += 1

    events =
    if  events & Bluetooth.CHAR_WRITE_EVENT:
        if char1_read_counter < 3:
            print('Read request on char 1')
            return 'ABC DEF'


    I can get the phone to connect to the LoPy and receive the characteristic data from it. However, I cannot figure out how to read the data to get the characteristic's value of 5. I am using Xcode with the Swift programming language and its Core Bluetooth framework. When reading a value on the LoPy, there is a simply a read() function. How does this function work and is there a way to get the code behind it, so I could set up a similar implementation in Swift?

Pycom on Twitter