7

I'd like to build a device that obtains the local time from a phone or laptop via BLE. My ideal interaction flow would be:

  1. push a "set time" button on the device to make it start advertising
  2. open Bluetooth settings or control panel on the phone/computer, find the device and tap to connect to it
  3. the device uses the current time service to request the time from the phone, then disconnects and stops advertising

The total scope of interaction is just to get the local time without needing manual adjustment, and without adding more complex connectivity like WiFi to use NTP.

Is this interaction flow possible with BLE? Can a peripheral, on its own, read from the current time service from the central? If not, does a companion app on the phone need to write to the current time service characteristic on the peripheral?

4
  • 2
    What is the desired precision? Do you want it to use as a general clock that shows you the time or you have some kind of other application which requires an accurate clock? Dec 22, 2017 at 13:51
  • In addition to Bence's question, have you considered using a radio clock signal instead of BLE synchronising to a device? Many consumer devices (such as digital clocks) use that to get an accurate time reading.
    – Aurora0001
    Dec 22, 2017 at 14:54
  • Yeah, within a seconds is fine.The same precision you'd expect from any other home appliance with a clock on them.
    – jmw
    Dec 22, 2017 at 15:07
  • Also, I looked at the LF radio clock systems, but receivers aren't integrated into any µC I know, and I couldn't find any discrete receivers either in casual searching, do you know any?
    – jmw
    Dec 22, 2017 at 15:09

3 Answers 3

6

Since you don't intend to further communicate with the partner device I guess the precision of the set time is okay for you in a precision range of a few seconds. If you want to get more precise you'll have to take a lot more into consideration (delays, latency, lower level protocols and the like).

In general BLE is a communications protocol, you can access every functionality that the end device provides. So if you have a computer/phone which allows NTP requests you can pose an NTP request over BLE. That certainly requires some sort of configuration or additional program.

You could use the scan request and scan response to deliver the time during the advertising process. Of course, to do that you'd have to provide a minimal BLE counterpart. The advantage would be that you don't even have to do a complete pairing. That requires of course a certain access to the BLE behavior on both sides which you probably don't have on a smartphone, if you're getting the time from a Pi or some other more controllable instance that might work.

If you are not shy of rooting an Android you could also use Cheepsync, where they did exactly that. Here it's on Github.

6

Have you looked at Web Bluetooth? This can be used to write to the the device without needing a native client app just to set the time.

There is support in Chrome on most platforms and other browsers are adding support.

I've been working on a device that uses Web Bluetooth to set the wifi details (the device is a clock that will use NTP to remain accurate and support some other features)

2

Is this interaction flow possible with BLE?

Yes.

Can a peripheral, on its own, read from the current time service from the central?

Only if the central is running a Current Time Service.

If not, does a companion app on the phone need to write to the current time service characteristic on the peripheral?

Depends whether the central is already running a Current Time Service. For example iOS has one built in that will write to the current time characteristic on the the peripheral every minute.

If there is no built-in Current Time Service, you can either add one or provide the current time some other way (eg. generic app and custom protocol, or website and Web Bluetooth).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.