Skip to content
Rachel edited this page Jun 22, 2017 · 2 revisions

Picture from Arduino.cc

The Ciao library is a glorious invention that makes interfacing with newer WiFi boards easy. It covers up all the yucky unique internet connection commands with uniform syntax. It's currently supported on Arduino Yun, Arduino Yun Mini, Linino One, Arduino Tian, and Arduino Industrial 101.

You have to install Ciao before you can use it, either in the Arduino IDE using the library manager or through the Arduino OS.

Once that's done, you can run arduinociaoexample.ino:

////////////////////////////
// Initial State Streamer //
////////////////////////////

// Data destination
// https can't be handled by most Arduinos, thus "insecure"
#define CONNECTOR     "rest" 
#define SERVER_ADDR   "insecure-groker.initialstate.com"

// Access key (the one you find in your account settings):
#define ACCESSKEY  "Your_IS_Access_Key"
// Bucket key (hidden reference to your bucket that allows appending):
#define BUCKETKEY  "ciao_stream"

The Initial State API endpoint is different from the usual (https://groker.initialstate.com/api/) because we can't use HTTPS, thus "insecure-groker.initialstate.com". You may be able to use "https://groker.initialstate.com" depending on your board. Your access key tells the API which account the data belongs to and the bucket key tells the API which data bucket the data should go to.

This sketch requires that you create a bucket inside of Initial State before your data will appear.

void loop() {
    
  // read temperature, pressure, altitude, humidity
  int number = random(18,25);
  String alert = "Alert";
  
  // Build HTTP request.
  String uri = "/api/events?accessKey=";
  uri += ACCESSKEY;
  uri += "&bucketKey=";
  uri += BUCKETKEY;
  uri += "&number=";
  uri += String(number);
  uri += "&alert=";
  uri += String(alert);

  
  Ciao.println("Send data to Initial State"); 
  
  // Send the raw HTTP request
  CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, uri);

  if (!data.isEmpty()){
    Ciao.println( "State: " + String (data.get(1)) );
    Ciao.println( "Response: " + String (data.get(2)) );
  }
  else{ 
    Ciao.println("Write Error");
  }    
 
  delay(300000); // wait 5 minutes between reads

}

Here we are building a URI utilizing Initial State's ability to accept URL parameters. The HTTP request looks like this:

rest, insecure-groker.initialstate.com, /api/events?accessKey=ACCESSKEY&bucketKey=BUCKETKEY&number=number&alert=alert

You can add as many key-value pairs at the end of the URI as you want so long as you use the format "&key=value".

It's that simple!

<< Ethernet Shield

Clone this wiki locally