Close

How Bluetooth messagging works on WatchDuino

A project log for Watchduino2

Inexpensive Open Source BLE smartwach compatible with Arduino tooling

mar-bartolomeMar Bartolome 09/12/2015 at 16:210 Comments

Today we are going to explain what's the magic behind the Bluetooth communication between WatchDuino and the phone companion app.

Communications take place every time the WatchDuino needs some piece for info that it can't calculate by itself. Usually this involves querying data from the internet, such as tweets, bus statuses, or the weather. But also... time!

WatchDuino 2, as opposed to it's predecessor, can't actually know what's the current time, as it lacks an RTC module. Instead, when it's started, it asks the phone app for the time, and after that it'll keep track of it by itself. From time to time it also asks the phone again for the time, to make sure it doesn't get too desynchronized.

The communication via Bluetooth between WatchDuino and the phone is actually lightning fast!


When you press the synchronize button on WatchDuino, the following message is sent to the phone app:

!tm

This is the "command message format" that WatchDuino and the companion app can understand. A bang means the start of a command, and the next two characters identify the command type. In this case, it's a request for the time. Other commands include "!tw" for twitter, "!tf" for TFL, "!wt" for the weather, or "!nt" for a notification.

Upon receiving this message, the companion app will grab the current time, and send it the watch like so:

!tm:1442063976

This is a command message with some data attached to it. In this case, the data is the current time in epoch format. We are using a library for Arduino which will accept this format, and translate it to something more readable for humans "September 12th 2015, 14:19:36". All the watch does upon receiving the message, is parsing the data out of it and passing it to the library, which will set the new time.

As you see, the message format is both simple and flexible, and allows for future apps to pick their own command codes, and transfer any data as long as you can serialize it into a string.

Discussions