Quantcast
Channel: m2mio
Viewing all articles
Browse latest Browse all 9

Examples using mqtt and the m2mIO API

$
0
0

m2m.io information and examples

The following examples show how to use the m2m.io MQtt broker and the api’s to retrieve that data.

Connecting to the broker

The first step is to acquire a username and password from http://help.m2m.io

Next using a compatible 3.1 MQtt client, configure the username and md5sum(password) for the client. You may use anything for the clientid. Every clientid will require a license for connecting to q.m2m.io. Licenses are automatically provisioned until your license limit is reached. The clientid may be prefixed with ‘<stuff>/’to automatically configure the client for this grouping. This is useful when retrieving information about your ‘thing’. See Topic Namespace for further info on this.

Topic Namespace

In order for m2m.io to properly store your data this namespace pattern must be followed.

<domain>/<stuff>/<thing>

By default the topic namespace for an m2m.io client must start with their ‘domain’. Domains are obtained during registration of a new user account. The next level of the namespace, ‘stuff’ is a logical grouping of related things. The third level of the namespace, ‘thing’ relates to the client’s unique identifier.

If you don’t follow our recommended namespace pattern messages will still be passed by the broker as long as you have rights to publish/subscribe on the given topic. Messages will not be stored if the topic space is different.

Payload

In order for m2m.io to store the payload data the client must send the data in standard json object form. Here is an multi nested object example:

{
  "report": {
    "gps": {
        "latitude": "39.702610038220882",
        "longitude": "-104.97231300920248"
        },
        "temp": {
        "celsius": "252",
        "fahrenheit": "76"
        }
    }
}

Using the m2m.io API

Use the m2m.io API to retrieve the client information and data that you have published over time.

API Url - http://api.m2m.io/1

These examples will use the curl command line tool to show how to get the date that was just published:

Get account info

curl --user user@m2m.io:xxxxxx http://apm2m.io/1/account

{
    domain = "io.m2m";
    email = "user@m2m.io";
    key = "user@m2m.io";
    ok = 1;
    password = xxxxxx;
}

Get domain info

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/domain/io.m2m

{
    active = 1;
    domain = "io.m2m";
    key = "io.m2m";
    licenselimit = 1000000;
    name = m2mIO;
    ok = 1;
    stuff =     [
        "io.mqtt",
        tests,
        test,
        things,
        examples,
        scala
    ];
}

Get stuff info

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/stuff/io.m2m

[
  {
    active = 1;
    domain = "io.m2m";
    key = "io.m2m:things:Ee6DR";
    licenseid = "uJ5ULi6YL8Flf0w:ba481581-2eb3-40af-af3e-75b86624694a";
    ok = 1;
    stuff = things;
    thing = Ee6DR;
  },
   {
    active = 1;
    domain = "io.m2m";
    key = "io.m2m:examples:publisher";
    ok = 1;
    stuff = examples;
    thing = publisher;
  }
]

To filter by ‘stuff’

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/stuff/io.m2m/examples

[
  {
    active = 1;
    domain = "io.m2m";
    key = "io.m2m:examples:publisher";
    ok = 1;
    stuff = examples;
    thing = publisher;
  }
]

Present

Shows last known data sent from client

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/present/io.m2m/examples/publisher

{
    domain = "io.m2m";
    key = "io.m2m:examples:publisher";
    "m2m_nestedkeys" =     [
        report
    ];
    "m2m_raw" = "{\n\t  \"report\": {\n    \t\"gps\": {\n      \t\t\"latitude\": \"39.702610038220882\",\n      \t\t\"longitude\": \"-104.97231300920248\"\n    \t\t},\n    \t\t\"temp\": {\n      \t\t\"celsius\": \"252\",\n      \t\t\"fahrenheit\": \"76\"\n    \t\t}\n  \t\t}\n\t}";
ok = 1;
stuff = examples;
thing = publisher;
ttl = 0;

}

MultiPresent

Shows all last known data from a client parsed

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/multipresent/io.m2m/examples/publisher

{
  "report:gps" =     {
    customFieldMap =         {
        latitude = "39.702610038220882";
        longitude = "-104.97231300920248";
    };
    domain = "io.m2m";
    key = "io.m2m:examples:publisher:report:gps";
    ok = 1;
    stuff = examples;
    thing = "publisher:report:gps";
    ttl = 0;
  };
  "report:temp" =     {
    customFieldMap =         {
        celsius = 252;
        fahrenheit = 76;
    };
    domain = "io.m2m";
    key = "io.m2m:examples:publisher:report:temp";
    ok = 1;
    stuff = examples;
    thing = "publisher:report:temp";
    ttl = 0;
  };
}

Past

Shows history of all data from a client in a time series

curl --user user@m2m.io:xxxxxx http://api.m2m.io/1/past/io.m2m/examples/publisher?whatevers=report:gps:latitude,report:gps:longitude,report:temp:celcius,report:temp:fahrenheit
{ 1340314565706000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320480805000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320484088000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320484855000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320485523000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320486135000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; 1340320486746000 = { "report:gps:latitude" = "39.702610038220882"; "report:gps:longitude" = "-104.97231300920248"; "report:temp:celsius" = 252; "report:temp:fahrenheit" = 76; }; }

Viewing all articles
Browse latest Browse all 9

Trending Articles