Thursday, January 3, 2013

Cosm, a good first stop for things

Cosm - a data exchange platform for the Internet of Things

For me Cosm was an early stop in my exploration of sensors and Internet-connected devices. As I prototyped a remote sensing device using the Arduino open-source hardware development platform, quickly the question arose question: "I built in Internet protocol connectivity, but how do I web-enable the device?" The immediate and easiest answer was Cosm which changed it's name from Pachube after being acquired by LogMeIn, an information technology remote access solution provider.

Cosm  provides a web-based platform to which you can connect your Internet-connected device. Cosm includes a web API so your device can easily send and receive data to/from the Cosm servers. Using Cosm with your device is as simple as signing up for a free Cosm account via their website, then using the API to send data to your Cosm account. An a Cosm client example using Arduino shows just how easy it is to send data to Cosm; the actual C code for the connection is shown at bottom.

Cosm supports JSON, XML and CSV data formats and leverages a flexible REST API so that any web-enabled device can store and manage data on Cosm. Compare this to say If This Then That, which serves as an application level central dispatch, in which application events from one of your services can send events to other services (when I post to my blog, send a tweet). Cosm provides a general purpose HTTP-based foundation to store your device and sensor data as well as a central point in which you can build out your own network.

// this method makes a HTTP connection to the server:
void sendData(int thisData) {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    // send the HTTP PUT request:
    client.print("PUT /v2/feeds/");
    client.println(".csv HTTP/1.1");
    client.print("X-PachubeApiKey: ");
    client.print("User-Agent: ");
    client.print("Content-Length: ");

    // calculate the length of the sensor reading in bytes:
    // 8 bytes for "sensor1," + number of digits of the data:
    int thisLength = 8 + getLength(thisData);

    // last pieces of the HTTP PUT request:
    client.println("Content-Type: text/csv");
    client.println("Connection: close");

    // here's the actual content of the PUT request:

No comments:

Post a Comment