Filter results by

Introduction to ARTIK Cloud

Samsung ARTIK Cloud makes it easy to interact with your IoT devices. Once you have acquired data, it's a simple matter to send it off to ARTIK Cloud for viewing and archiving. ARTIK Cloud can also analyze the data and send back appropriate actions according to the rules you decide.

Prerequisites

You will be using the Node-RED setup and the board setup from the previous tutorial. You will also be using ARTIK Cloud.

  • Open and log into the following page in your browser to get ready to use ARTIK Cloud. If you haven't signed up for a free account, you will be given the chance to do so.

    Site Looks Like This Used for
    My ARTIK Cloud Connecting a device; obtaining access tokens; viewing data sent by the device

Creating a new Device

We will stream temperature data to ARTIK Cloud. In order to do this, we need to create a temperature device instance in ARTIK Cloud.

  1. Go to My ARTIK Cloud.

    • If this is your first device, you will be redirected to the screen below:

    • Otherwise, go to Devices to see all your connected devices. Click the “Add Another Device…” link.

  2. Search for “Temp Sensor” and select it. “Temp Sensor” is a public device type, so you can "inherit" its pre-configured information instead of entering it all. Name your instance “My Temp Sensor”.

  3. Click the “CONNECT DEVICE…” button. A new device will be created.

Getting the Device Token

Every call you make to ARTIK Cloud requires an access token. The Device Token is one of three types of access tokens, and is the one we'll use in this tutorial.

It's easy for any valid user to obtain the Device ID and Device Token needed to exchange information with ARTIK Cloud. In this case, the device of interest will be our newly created “My Temp Sensor”, but you'll follow this procedure any time you need to insert Device information into your code.

  1. Go to My ARTIK Cloud and log in (if you have not already).

  2. Click on the device of interest.

  3. When you see the Device Info pop-up, click GENERATE DEVICE TOKEN… to get a Device Token. You'll only see that link the first time; after that, the token will already be visible as shown below.

  4. Leave the Device Info page open. You'll be copying and pasting these codes:

    • Device ID – referred to as the sdid field in written code
    • Device Token – referred to as the accessToken field in written code.

Sending Node-RED data to ARTIK Cloud

Here we will again use the temperature circuit you set up in the previous tutorial. Go back to your Node-RED temperature sensor flow from that exercise.

Setting up an output node to ARTIK Cloud

  1. Drag an artik cloud out node into the existing flow.

  2. Connect the node so that the final flow looks like this.

  3. Double-click the new node and enter from the Device Info page:
    • Device ID
    • Device Token.

  4. Click Deploy.

  5. Go back to My ARTIK Cloud and CHARTS to see the streamed temperature data.

  6. Turn off the repeating interval to avoid hitting a rate limit.
    1. Double-click the inject node.
    2. Set Repeat interval to 'none'.
    3. Click Done.
    4. Click Deploy.

The no-fee version of ARTIK Cloud has per-device rate limits that you need to observe. With the repeat interval turned off, you can just click the inject node trigger to send data as needed.

Troubleshooting Tip. Not seeing data? If you created the device type yourself, you can look at the error log on the Developer Dashboard under Device Types (as shown below) for hints.

Linking an ARTIK Cloud Device to an ARTIK Module Output

We're going to need a physical indicator light that ARTIK Cloud can control. To prepare, let's add an LED Device on ARTIK Cloud, and a corresponding node on Node-RED.

  1. Create a new device instance of “ARTIK Smart Parking LED”. ARTIK Cloud will be able to send Actions to this device.
    • Find it by typing part of the name as you did for My Temp Sensor.
    • Change the name to “My ARTIK LED”.
    • Bring up the Device Info screen and generate Device Token; leave it open.
  2. On your Node-RED canvas, prepare an artik cloud in node.
    • Copy over your “My ARTIK LED” Device ID and Device Token.
    • It can receive both messages and actions, so set it to “Receive Actions”.
    • Name the node “ARTIK Cloud In”.
  3. For now, just connect a debug node to it.

    • Set its output to show the “complete msg object”.

We've now set up a pathway from ARTIK Cloud to Node-RED that we can test with.

Receiving Actions from ARTIK Cloud

ARTIK Cloud can generate its own Actions based on Rules you write, which tell it how to analyze the data it has access to. (ARTIK Cloud can also forward Actions from other connected systems.)

Writing Rules

Using the temperature sensor circuit that we built in the Node-RED tutorial and the cloud data messaging we set up, let's write Rules for ARTIK Cloud to generate Actions.

  1. Add rules so that “My Temp Sensor” can turn on or off “My ARTIK LED” when certain conditions are met.

    1. Go to My ARTIK Cloud and log in.

    2. Click on

      Rules
      ^
    3. Click on

      + New Rule
      ^
    4. Set up two Rules as follows.

      • IF My Temp Sensor temperature is more than 80
        THEN Send to My ARTIK LED the action setOn
      • IF My Temp Sensor temperature is less than or equal to 80
        THEN Send to My ARTIK LED the action setOff
  2. Click Deploy.

  3. Warm up the temperature sensor, and verify that as the temperature fluctuates, you see messages like these in the Debug panel.

Not seeing any debug messages? Go back to the Rules page, hover over a rule until you see TEST, and click it to check whether a message is sent.

Setting up Cross-Device Actions

We just enabled ARTIK Cloud to use "My Temp Sensor" input messages to generate Action messages to the "My ARTIK LED" output device. You saw them arriving on the debug panel of Node-RED. Now turn those Action messages into real activity!

In our first Node-RED tutorial, we used Node-RED itself to generate a periodic message to toggle a GPIO output. This time, we'll use a PWM pin instead. That way, the ARTIK module is doing all the work – we just tell it the flash rate we want.

  1. Connect the LED to the PWM0 output as shown for ARTIK 5 or 10. You can select another as long as you configure Node-RED to correspond in a later step. For ARTIK 7, you'll be using PWM0 on pin 29 of the Test Header.

  2. Prepare a function node to check whether we received a “setOn” or “setOff” action.
    When LED is ‘setOn’, we define:

    • msg.payload.state to be 1 to turn on the PWM output
    • msg.payload.dutyCycle as 500000000 (500ms)
    • msg.payload.peroid as 1000000000 (1s).

    When LED is ‘setOff’, we define:

    • msg.payload.state to be 0 to turn off the PWM output.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    var actions = msg.actions;
    var action = actions[0].name;
    
    if (action === 'setOn') {
        msg.payload = {
            "state": 1,
            "dutyCycle": 500000000,
            "peroid": 1000000000,
        };
    } else if (action === 'setOff') {
        msg.payload = {
            "state": 0
        };
    }
    return msg;
  3. Connect the function node input to where the debug node is connected, so that it gets the same messages.

  4. Prepare an artik pwm node.
    • Connect it to the function node output.
    • Verify that its configuration is set to the PWM pin you chose when you set up the board. ARTIK 7 only has one, PWM0, called out by its sysfs name as pwm2.

  5. Click Deploy.

Now, when your temperature exceeds 80 degrees, you should see your LED blink.

Summary

You have experimented with one particularly easy way to send messages between an ARTIK module and ARTIK Cloud. You'll find in general that Node-RED is a fast way to prototype your development, and may even be appropriate for production.

In the Advanced Concepts series, we present Web REST API protocol and MQTT protocol as ways to send and receive messages. You may consider choosing MQTT protocol if your Wi-Fi bandwidth is limited. We'll provide you with both Node-RED and low-level coding methods for using either protocol.

Extra Credit

Node-RED isn't just for ARTIK modules; you can run it in the cloud, too! Sense Tecnic Systems has developed a cloud-hosted Node-RED service to complement ARTIK modules. Try out their FRED tutorial to see for yourself.

Last updated on: