Skip to content

Part 4. Initial State

Elizabeth Adams edited this page Nov 27, 2018 · 7 revisions

We want to stream all of our sensor data to a cloud service and have that service turn our data into a nice dashboard that we can access from our laptop or mobile device.

That cloud service is Initial State.

Step 1: Register for Initial State Account

Go to https://api.init.st/auth/#/register/ and create a new account.

Step 2: Include the Initial State Library

Include the Initial State library at the top of your Imp's Agent code:

#require "InitialState.class.nut:1.0.0"

Step 3: Initialize the Streamer

In order to actually use the Initial State library, you'll have to initialize it with your account information. This is very easy, you just need your Initial State Access Key.

Association with your Initial State account happens because of the Access Key parameter. If you go to your Initial State account in your web browser, click on your username in the top right, then go to “my account”, you will find your access key at the bottom of the page under “Streaming Access Keys”. It's the long series of letters and numbers.

Access Keys

Every time you create a data stream, that access key will direct that data stream to your account (so don’t share your key with anyone).

Initialize the streamer with the following line (Agent):

is <- InitialState("Your_Access_Key","impStreamTest",":smiling_imp: Electric Imp Test");

The first parameter must be replaced with your unique access key and is required. The second parameter is the Bucket Key, a hidden reference that tells us which bucket to send your data to. It is optional. The third parameter is the Bucket Name, the name of the bucket that you will actually see pop up in your Initial State account. It is also optional.

Step 4: Run an Example Stream

Run the test script to make sure we can create a data stream to your Initial State account. Add the following to your Agent code:

// Send an event
is.sendEvent("temperature", 72, function(err, data) {
    if (err != null) server.error("Error: " + err);
});

Your complete Agent code should look like this:

#require "InitialState.class.nut:1.0.0"

is <- InitialState("Your_Access_Key,"impStreamTest",":smiling_imp: Electric Imp Test");

// Send an event 
is.sendEvent("temperature", 72, function(err, data) {
    if (err != null) server.error("Error: " + err);
});

Build and Run!

Step 5: Profit

screen shot 2016-01-22 at 10 58 52 am Go back to your Initial State account in your web browser. A new data bucket called “:smiling_imp: Electric Imp Test” should have shown up on the left in your log shelf (you may have to refresh the page). Click on this bucket and you'll see a tile that says "temperature" with a value of 72!

You are now ready to start streaming real data from the Env Tail!

<< Part 4: Putting it All Together - Part 4: The Device Code >>