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
- 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.
- The user checks the room temperature and humidlty on a mobile app.
- 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)
- 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
- Step 2: Onboard the thing
- Step 3: Report the thing state
- Step 4: Send commands to remote control the thing
- Step 5: Read the thing state
- Step 6: Browse the command result
- Step 7: Set triggers
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:
- 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.
- 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.
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:
The basic flow is as follows:
- The thing sends its vendorThingID and password to the mobile app.
- 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.
- The mobile app sends the thingID and access token to the thing.
- The thing finalizes the onboarding process with the given thingID and access token.
The basic flow is as follows:
- The thing onboards itself with its vendorThingID and password. Thing Interaction Framework will generate the thingID and access token for the thing.
- The thing sends either its vendorThingID or the thingID and password to the mobile app.
- The mobile app starts the onboarding process with the given vendorThingID/thingID and password.
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.
Once the onboarding is done, the mobile app can start remote controlling the thing.
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:
1. TurnPower (true)
2. SetPresetTemperature (25)
3. SetFanSpeed (5)
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.
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.
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.
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.
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".