Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Anyone tried with Core Bluetooth?

in Questions Posts: 535
Havr anyone tried using Core Bluetooth with the ObjC api? Havent figured out how to do it yet. Any example would be appreciated :)

Comments

  • edited April 24 Posts: 535
    Can you get a list of methods in a objc class? I tried this, but the scan method is missing..

    ~~~

    CBD = objc.delegate("CBCentralManagerDelegate")

    function CBD:centralManagerDidUpdateState(central)
    print(central.state)
    end

    function setup()
    d = CBD()
    cm = objc.cls.CBCentralManager(d, nil)
    cm:scanForPeripherals_withServices_(nil)
    end

    ~~~
  • edited April 28 Posts: 535
    Ok, I made it so far. It wasn’t that obvious how to figure out the naming. Does it say in the documentation that the arguments must be named objClassName to work correctly. But fun to get it to discover BT-devices so far :)

    ~~~
    CBD = objc.delegate("CBCentralManagerDelegate")

    function CBD:centralManagerDidUpdateState_(central)
    print("did", central, central.state)
    print(cm.state)
    if cm.state == 5 then -- poweredOn
    print("scan")
    cm:scanForPeripheralsWithServices_options_(nil)
    end
    end

    function CBD:centralManager_didDiscoverPeripheral_advertisementData_RSSI_(central,objCBPeripheral,c,d)
    print("discovered name", objCBPeripheral.name)
    end

    function setup()
    s = Scene()
    d = CBD()
    CM = objc.cls.CBCentralManager
    cm = CM()
    cm:initWithDelegate_queue_(d,nil)
    end
    ~~~
  • edited May 9 Posts: 535
    I managed to get it working now. I had to convert the NSData to base64 to be able to read it.

    Now it reads the heartrate, steps, accelerometer from my watch and displays it. It also sends a message to it.
  • Posts: 1,795
    Should I be able to link this to my own watch?
  • edited May 9 Posts: 535
    I guess you have to figure out the api for your watch. I think the pinetime watch uses a standard api for heartrate, but I havent tested it with any other device.

    I’ve now rewritten it to read the step counter and motion sensor as well. And send a message to the watch.
Sign In or Register to comment.