Timetric

Information

This example uses the old HTTP Client, you should be able to port it quite easily to the new one, though.

Go to timetric.com and click register.

Once you are registered, you need to create an empty data series, which you'll post to later. Go to your http://timetric.com/dashboard/, and click "Create Series"; then "Create By Hand". Fill in a title; along with any other information you want - but no value or timestamp.

When you hit Create, you'll be redirected to the new, empty series. Note its URL - this is the address you need to talk to in your client.

Now go to http://timetric.com/settings, and choose Applications. Create for yourself a new API token, in the Developer side of the screen; name it 'mbed' or similar. This will generate for you an opaque API token - a username/password pair you can use for authentication.

Create a new Project in the Compiler and add the HTTPClient Library from [wiki:HTTPClient here].

In the listing below, replace `APITOKEN_KEY` and `APITOKEN_SECRET` with the Key and Secret from Timetric; and `SERIES_URL` with the URL you've created above.

This program will read data from the `DigitalIn` port on pin 19, and post its value, every minute, to the series we created on Timetric above. Note that, before we start transmitting data, we write a "null" value to the series; this is not compulsory, but it provides an indicator to terminate each set of measurements you send.

#!cpp
#include "mbed.h"
#include "HTTPClient.h"
#include "string.h"

#define APITOKEN_KEY "insert_key_here"
#define APITOKEN_SECRET "insert_secret_here"
#define SERIES_URL "http://timetric.com/series/CrIWmUtiTz23mVzxZ4zP1w/"


DigitalIn poti(p19);
DigitalOut led(LED1);
HTTPClient http;

int main() {
    char data[30];
    float value;
    http.auth(APITOKEN_KEY, APITOKEN_SECRET);
    http.post(SERIES_URL, "value=null");
    while(1) {
        value = poti.read();
        snprintf(data, 30, "value=%f", value);
        http.post(SERIES_URL, data);

        printf("%f\n", value);
        
        led = !led;
        wait(1);
    }
}

All wikipages