Filter results by

Add device sharing to an application

In this article, we will show you how to add device sharing to your application on ARTIK cloud services. We will also illustrate the flow from the perspectives of an IoT device sharer and share recipient.

Using an IoT application that has device sharing capability, a device owner (sharer) can grant temporary access to the device to others (share recipients). This is very useful in smart home or smart building scenarios. For example, families or office coworkers can share smart appliances or lights; an apartment subletter or a car renter can be granted access to a smart lock.

This guide focuses on high-level steps. To implement the functionality, check out the source code for our sample sharing application.

Step 1: Create an application and request permissions

Create an application on the Developer Dashboard, then set permissions as follows:

  • Set the User Profile access to READ and WRITE permissions.
  • Set READ and/or WRITE permissions on the device types that your application will allow device owners to share.

Step 2: Obtain an access token and device info

After a device owner signs into ARTIK cloud services in your application, the application gets a user token that it uses to call share APIs. Typically, device owners should explicitly initiate the sharing.

To share a device, your application also needs its device ID. There are a few ways to retrieve a device ID. One way is to call the Get a user's devices API to present a list of devices to the user. The user then selects the device to share. At a result of this process, your application obtains the device ID, which will be used in the next step.

Step 3: Share a device

Now the application has an access token and device ID. Simply call Create a device share API to share the device with a recipient. The recipient's email is required for that API call.

Afterward, the recipient will receive a share invitation via email. Once the recipient accepts the share, s/he can read data from the shared device and/or control that device, using My ARTIK Cloud or any application that has READ (and/or WRITE) permissions on the device type.

Step 4: Manage the share

After sharing, your application can manage shares via API calls. The following are some examples:

  • Get device shares to see which recipients this device is shared with, status of the share (pending or accepted), and other details, such as when the sharing was initiated.
  • Delete a device share to revoke the share with a specific recipient.

The user experience

We'll use our sample share application to illustrate the sharing flow from the perspective of device owners and share recipients.

The device owner logs into their ARTIK Cloud Account using the application.

How to tk

The owner then clicks on the "Share Device" button and provides the recipient's email to share a specific device with a recipient. For simplicity, the shared device is a sample device created by this application. Step 3 describes how to specify devices in real-world scenarios.

How to tk How to tk

Click the "List Share Status" button to list the status of the share created above. In the below screenshot, the status is "PENDING", which means the recipient has not yet accepted the share.

How to tk

The recipient receives the email for a share invitation and accepts the invitation as follows:

How to tk

The next time the device owner clicks the "List Share Status" button, the status of the share will have changed to "ACCEPTED".

The device owner logs into My ARTIK Cloud. On the Devices page, s/he will see that the device has a "Sharing with Others" icon. Similarly, the recipient logs in to their account and sees the "Shared with Me" icon on the device.

How to tk

The recipient can now read or control the shared device as they wish until the owner revokes the share.

That's it!

It is that simple to add device sharing capability to your application. To learn more: