A couple of weeks ago, the ARTIK Cloud team found this cute device: LaMetric Time. It’s beautifully designed and looks very useful. There are not many physical connected objects, outside of the traditional watch/wristband, that can display information. We wanted to connect LaMetric Time to ARTIK Cloud and make it part of our big family of devices.
LaMetric Time has been launched by a Kickstarter campaign and is now readily available. We contacted the LaMetric team and received the device. It was time to play!
The investment is cheap and the reward is great. With LaMetric Time connected to ARTIK Cloud, owners of the device can now use ARTIK Cloud Rules to display messages on new events from their Fitbit, Samsung Gear S2, SmartThings devices, and hundreds of other devices. They can display different messages depending on multiple conditions. But they can also trigger Actions on other devices using the LaMetric Time button. Below are some examples of how we are using LaMetric Time with ARTIK Cloud and its Rules functionality.
Display heart rate
This Rule sends an Action to the LaMetric Time that prints the value of
heartRate, along with a cool animated icon!
Report the weather
Here, the LaMetric Time displays data from a weather station device, indicating the temperature when no rain is expected in the next hour.
Lock the door at night
This Rule checks the status of your door after 10:30 pm and sends a reminder if it is unlocked. Pressing the LaMetric Time button will cause ARTIK Cloud to lock the door.
ARTIK Cloud application
You can create an ARTIK Cloud application in LaMetric’s developer portal. When your application has been created, LaMetric will start polling your defined endpoint to know if there is something new to display on the device. LaMetric will call another endpoint when a button is pressed.
We built our application in Scala using the Play Framework.
LaMetric performs an OAuth 2 flow for us: when you install the ARTIK Cloud application inside the LaMetric mobile application, you can login/sign up to ARTIK Cloud. Now, your LaMetric device is linked to an ARTIK Cloud user. In the background, LaMetric starts polling our application LaMetric/ARTIK Cloud for a new text to display. The endpoint is called with the access token obtained during this authentication phase.
LaMetric device type in ARTIK Cloud
We created a device type in the ARTIK Cloud Developer Dashboard to represent the LaMetric Time device.
We wanted Actions that could send a text to the LaMetric Time display. We needed 3 types of Actions:
- simply send a text
- send a text with an icon
- send a text with an animated icon
We also wanted to declare fields that could receive the button status from the device:
- button pressed
Display message on LaMetric Time
When we receive a polling request from LaMetric’s servers, we extract, from the request, the access token sent in the Authorization header and use it to perform the following operations:
- If a LaMetric Time device exists in the ARTIK Cloud user account, we recover their device ID. If it does not exist in the user account, we create one automatically.
- We use the ARTIK Cloud subscription API to subscribe to Actions sent to this LaMetric Time device. For each notification received by our subscription API, we fetch the new Action from ARTIK Cloud and we store it in Redis.
- We return an HTTP 200 JSON result with the last Action stored in cache.
ARTIK Cloud’s user/application can send a text to display using an Action on the device.
We now need to link the reception of a new Action to an update of the text on the LaMetric Time. In this demo, we used LaMetric’s “poll” API.
The ARTIK Cloud application subscribes to be notified when a new Action is sent on the LaMetric Time ARTIK Cloud device, using a simple HTTP call on a predefined endpoint. The application stores when a new Action is received, and on the next polling from LaMetric, delivers the new text.
Receive button pressed
When a user presses the “action” button of their LaMetric Time, the LaMetric server calls us on a specified endpoint with the ARTIK Cloud access token in the request header.
We then translate this call into an Action for the ARTIK Cloud LaMetric Time device. The action is sent using our REST API. If this call succeeds, we return an HTTP 200 result to LaMetric’s initial call.
For devices that do not support an update of the embedded code, or do not have a cloud with a standard REST API, we can still support them with ARTIK Cloud using ARTIK Cloud applications. The integration described here was really easy and was done in just a couple of days, including the time to design the solution and host the service on a server.
Connecting LaMetric Time to ARTIK Cloud opens a whole new world of interaction between LaMetric’s device and all ARTIK Cloud devices and applications.
Welcome to the ecosystem, LaMetric
Looking to connect many devices to the cloud and build innovative IoT solutions? Click here to get started for free.