LaMetric & local push
UPDATE: This doesn’t work with firmware 1.6.0 – see updated article here: LaMetric Firmware 1.6.0 and local push
With the latest firmware upgrade (1.50) the LaMetric finally got support for local push – allowing you to sent messages to the LaMetric without needing an internet connection. Because some people in the support forums asked how to use local push I decided to write a tutorial (I do this on OS X).
Creating the app
First step is to create the app for the LaMetric which later will show the information. If you don’t have a developer account, create one and log in.
You will see a list of all the apps you have created so far. Click on “Create New App”.
In this case we want to create an indicator app, so choose “Create” on the left side. We’re now in the editor and can add and edit frames. A frame can be compared to a page in a book and every app can have multiple frames. In this tutorial we will create two frames. The first one shows an icon and a text string and the second frame shows a chart.
At the moment there are four types of frames – “Name”, “Metric”, “Goal” and “Sparkline”. Each type can display different kind of information and you can choose what you want for your needs. In this tutorial we will stick with “Name” and “Sparkline”.
Every frame has a number assigned to it. This number (or index) is used to address the frame and it starts at 0 not 1.
When you create a new app it already has one frame of type “Name”. Change the text to what you want and choose an icon. Next add a new frame by clicking the small +-sign next to the list of frames. Change the type of this frame to “Sparkline” and enter some arbitrary numbers.
At the top of the page there is a simulator that shows you how every frame looks, just hit the play button.
Scroll down and change the communication type from “Poll” to “Push”.
Scroll to the bottom and click “Next”. You see the store information. Choose a name and a description and activate “Private app”. This way only you will be able to install the app.
Click “Save” and your app is ready. For now it’s in draft mode and before you can use it you have to publish it. On this page you also see the URLs that you can use for local and remote push to your LaMetric. For now we’re ready, so click on “Publish” and keep the tab open since we need the information on this page later. After a few minutes you will get an email telling you that your app was published.
Install the app
Head to your LaMetric app on your smartphone and add your app the LaMetric. Change the filter to only show private apps and add your new app.
Now your LaMetric is ready and we can write some code to send data directly from your PC to it.
Pushing data
I’ll use PHP to write a short piece of code that will send data to the local address of the LaMetric. For this to work you need a PHP interpreter on your system. You also need the local push url and your access token (which can be found on the page we left open – if not head back to the developer center and select your app and choose the “Published” tab). Paste this code into a text file and replace LOCAL_PUSH_URL with the url and ACCESS_TOKEN with the access token.
Your code should now be similar to this:
The part of the code that contains the data that is sent to the LaMetric is the $frames variable. For each frame we created in the editor it has an array. Each of those arrays contains the index – this way the LaMetric knows which data belongs where. For a simple name frame you can also sent the text and the icon. For the sparkline you just send the y-values of the line. For a goal frame you have other parameters – those can be found on the developer page after you created an app.
Before we can go on there are two small changes necessary, that I’ve already done in the image: Change the “https” to “http” and “4343” to “8080”. This will sent your data without any encryption to your LaMetric device, but for now this is how we will do it. If you know how to trust the certificate you can do this and leave the url. Save the PHP file (mine is name curl.php) and open a terminal window.
Send the data
After installing and selecting the app your LaMetric shows you the default values that you entered in the editor.
In the code you see the text string “Hello” and the numbers used for the Sparkline. Change those and call your run your php script.
Your LaMetric should show the new data (it may take 1-2s).
Now you’re done. You can modify this script the way you want. On a linux machine you can use cron to call this script periodically if you have to. On OS X use launchd.