Development Steps

This page presents how to get started in IoT solution development with the Thing-IF SDK.

Let us assume that you want to implement the following IoT scenario.

Sample IoT Scenario: Hooking an air conditioner to Thing Interaction Framework

State Management:
- The air conditioner reports the current room temperature and humidity to Thing Interaction Framework.
- The air conditioner reports the current settings (preset temperature and fan speed) to Thing Interaction Framework.

Remote Surveillance:
- The user checks the room temperature and humidlty on a mobile app.

Remote Control:
- The user checks the current settings of the air conditioner on the mobile app.
- The user manipulates the air conditioner from the mobile app (e.g., turning the power on/of, change the preset temperature and fan speed)

Trigger Control:
- The user sets triggers to auto-operate the air conditioners (e.g., turn on the air conditioner if the room temperature goes over 30 degrees in Celsius).

Here is the walkthrough on how to start implementing the IoT solutions. We will refer to our sample IoT scenario to exemplify each step.


Step 1: Define the schema for your thing

First, you need to describe the capability of the thing as a schema. See Schema for more information.

For our IoT sample scenario, for example, the schema can be something like this:

State:
- power (boolean): if the air conditioner is powered on or off.
- current temperature (int): the current temperature in the room..
- current humidity (int): the current humidity in the room.
- preset temperature (int): the preset temperature.
- fan speed (int); the fan speed.
Actions:
- TurnPower (boolean): Turn on/off the power
- SetPresetTemperature (integer): Set the preset temperature to the specified value.
- SetFanSpeed (integer): Set the fan speed to the specified value.

See Defining Schema to learn how you reflect your schema into your Android code. If you are implementing on iOS, you do not need to reflect your schema explicitly; you just need to send commands based on the schema.

Step 2: Onboard the thing

The next step is onboarding. Onboarding the thing will "hook" it with a mobile app and makes it ready for the service operations. See Onboarding for more information.

The onboarding process can be made in one of the following ways:

Onboarding from the mobile app

The basic flow is as follows:

  1. The thing sends its vendorThingID and password to the mobile app.
  2. The mobile app onboards the thing with the given vendorThingID and password. Thing Interaction Framework will generate the thingID and access token for the thing.
  3. The mobile app sends the thingID and access token to the thing.
  4. The thing finalizes the onboarding process with the given thingID and access token.

See the related topics in the development guides for Android, iOS, and JavaScript for the sample code on the mobile app side. See Onboarding from the mobile app for the implementation on the thing side.

Onboarding from both the thing and the mobile app

The basic flow is as follows:

  1. The thing onboards itself with its vendorThingID and password. Thing Interaction Framework will generate the thingID and access token for the thing.
  2. The thing sends either its vendorThingID or the thingID and password to the mobile app.
  3. The mobile app starts the onboarding process with the given vendorThingID/thingID and password.

See the related topics in the development guides for Android, iOS, and JavaScript for the sample code on the mobile app side. See Onboarding from both the thing and the mobile app for the implementation on the thing side.

Step 3: Update the thing state

Once the onboarding is done, the thing can start uploading (updating) its state to Thing Interaction Framework. The state updating is executed periodically at the specified interval. The interval is to be specified when you initialize the SDK. See State Registration and Retrieval for more information.

In our IoT sample scenario, the air conditioner can periodically upload its settings and the current temperature/humidity.

See Updating State for sample code.

Step 4: Send commands to remote control the thing

Once the onboarding is done, the mobile app can start remote controlling the thing.

Sending a command from the mobile app

The mobile app controls the thing by sending commands. See Action and Command Execution for more information.

A command includes one or more actions. By putting multiple actions in a command, you can request the thing to execute a sequence of the actions.

In our IoT sample scenario, for example, we can send the following commands:
Command "MySetting-1":
1. TurnPower (true)
2. SetPresetTemperature (25)
3. SetFanSpeed (5)

See the related topics in the development guides for Android, iOS, and JavaScript to learn how to send commands from a mobile app.

Receiving the command on the thing

The command sent from the mobile app is first delivered to Thing Interaction Framework. Thing Interaction Framework then relays the command to the corresponding thing.

After receiving the command, the thing interprets it and executes the requested operation based on the actions defined in the command.

In our example, the air conditioner will interpret the Command "MySetting-1" and execute the actions (i.e., turning the power on, setting the preset temperature to 25 degrees in Celsius, and setting the fan speed to 5).

See Executing Commands to learn how to receive and interpret the command.

Reporting the command result

After the thing executes the requested operation, it reports the result to Thing Interaction Framework.

In our example, the air conditioner will report if the requested actions (i.e., turning the power on, setting the preset temperature, and setting the fan speed) succeeded.

See Action Result to learn how to upload the command result.

Step 5: Read the thing state

The thing can read the state recorded in Thing Interaction Framework. The mobile app can also browse the state, provided that the thing owner is logged in.

In our sample scenario, the user will be able to browse the current state and settings of the air conditioner on the mobile app.

See the related topics in the development guides for Android, iOS, and JavaScript to learn how to browse the thing state.

Step 6: Browse the command result

When the thing reports the command result to Thing Interaction Framework, the Cloud will send a notification to the mobile app with the command ID. The mobile app can use this ID to browse the command result.

See the related topics in the development guides for Android, iOS, and JavaScript to learn how to browse the command result.

Step 7: Set triggers

By setting triggers from the mobile app, you can auto-execute the commands when the designated conditions are met. See Auto Execution with Triggers for more information.

In our example scenario, for example, we can set a trigger to "turn the power on" when "the state of the 'current temperature' field goes over 30 degrees".

See the related topics in the development guides for Android, iOS, and JavaScript to learn how to set triggers from the mobile app.