A Very Simple WF with a background that talks BLE to the thingy52

a couple years back I did a thread about how to do simple backrounding in a watch face, and at that time, time, the background just returned a string with the time it ran.  This is similar, but here, the background uses BLE to talk to a Nordic Thingy52 and returns the temperature and the battery level, and shows some of the basics of the BLE interface in the new 3.1.0-beta1 SDK.  To run it in the sim, you must user the 3.1.0 SDK, ave the HW for the sim to "talk" ble, and a Thingy52.  For you have a f5+ with the speical CIQ FW, it will talk to the thingy52.

The ble stuff is all in BgBLE.mc and here's the basics:

A Temporal event starts things, and in onTemporalEvent, I create the profile manager, for the env and battery services and then pass that when I next set the Ble delegate.  Then I start scanning.

In the delegate, onScanResults is called when BLE devices are seen in the scan.  When a thingy is seen, I stop the scan and then pair the device.

When the device connects, I do a read of the battery level characteristic, and when that completes, I request notifications of  temperature changes.

When I see the temp, I unpair and return the temperature, battery and timestamp in an array.

Lot's of println's so you see when things happen.

I did this one request at a time, because doing reads etc is single threaded to BLE, so I couldn't do the read and start notify at the same time, and didn't want to implement a queuing scheme for simplicity..

The only tricky thing is the thing goes to sleep after about 3 minutes, and the background can only run every 5 so you may have to wake up the thingy at times. (just tap it if it's been 4 minutes or so since the last time the BG ran.)

vsBleWf.zip

  • Have you found in the code anything that indicates that the FR935 would be supporting this feature?

  • I think anything with CIQ 3.0.x will be getting CIQ 3.1.x, but for BLE, I don't know if there may be something with the specific BT hardware involved.

    So the answer is, I don't know.

  • Thank you for your answer!
    Regarding what kind of applications could derive from this new feature, do you think there could be a way to use this for presence detection for home automation (hass.io) in a way that woudnt drain the watch battery?

  • Former Member
    Former Member over 3 years ago in reply to jim_m_58

    Hi Jim, I was wondering if this could be applied to transmitting sensor data in the background to an android companion app through the BLE link instead of the Thingy52? Would a similar protocol be used in this case? Is pairing devices required? How does the transmit() work? I am sorry for asking a lot of questions, there isn't a lot of documentation on this. Your help is very much appreciated!

  • You want to look at the Communications module instead of BluetoothLowEnergy (as I'm using here)

    Remember a background service only runs at most every 5 minutes.