CloudPlugs REST Library  1.0.0
for Arduino
CloudPlugs Arduino Client Library

CloudPlugs REST Client for Arduino is a library to perform HTTP requests to CloudPlugs servers. The official repository is: https://github.com/cloudplugs/rest-arduino

The Cloudplugs IoT Platform

CloudPlugs is a cloud based IoT platform to enable the fast prototyping, connection, deployment and management of smart "Things" (sensors, smartphones, home appliances, etc.). Different objects can interact with each other by publishing and/or reading any type of data on shared channels through simple communication protocols. You can learn more at http://www.cloudplugs.com/how-it-works/ and you can sign-up on http://www.cloudplugs.com/register to start connecting your Things.

Library Guide

Dependencies

Requires the new Ethernet library API (with DHCP and DNS) which is in Arduino 1.0 and later

Installation

  1. Download the latest version of the library from https://github.com/cloudplugs/arduino and save the file somewhere
  2. In the Arduino IDE, go to the Sketch -> Import Library -> Add Library... menu option
  3. Find the zip file that you saved in the first step, and choose that
  4. Check that it has been successfully added by opening the Sketch -> Import Library menu. You should now see CloudPlugs listed among the available libraries.

Usage

In normal usage, handles the outgoing request and Host header. The returned status code is parsed for you, as is the Content-Length header (if present). Because it expects an object of type Client, you can use it with any of the networking classes that derive from that. Which means it will work with EthernetClient, WiFiClient and GSMClient.

  • include dependencies. Example:
    #include <SPI.h>
    #include <Ethernet.h>
    #include "CloudPlugs.h"
  • Create new istance of the client:
    CloudPlugs client;
  • Define your own setup() function. Example:
    void setup() {
    // initialize serial communications at 9600 bps:
    Serial.begin(9600);
    Serial.println("connect to network");
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    while (Ethernet.begin(mac) != 1) {
    Serial.println("Error getting IP address via DHCP, trying again...");
    delay(5000);
    }
    }
  • Configure your client and define your own loop() function to perform HTTP requests. See the examples for more details on how the library is used.

Configuration

There are a few configuration parameters available for customization (if needed) before invoking any HTTP request. This parameters are:

  • auth id: the authentication identifier
  • auth pass: the authentication password
  • auth master: true to authenticate using the main account password
  • host: the base URL for HTTP requests

    Example:
    // setAuth( authId, authPass, isAuthMaster)
    client.setAuth("your_plugid", "your_password", false);

Execute Rest HTTP requests

After configuration, you can execute HTTP requests to the server by invoking any of the request functions. All the requests are synchronous and are performed according to CloudPlugs Rest API documentation. Example:

String response = "";
boolean result = client.publishData("foo", "{\"data\":{\"temp\":7}}", response);