Mistake on this page? Email us

Controlling the device with Izuma Device Management

Now, the device is connected to Izuma Device Management. In the code sample in the previous section, you defined resources using calls to create_resource(). These resources are automatically exposed for device management, from which you can read and write to them, and any changes made are automatically synced with the device. That means that you already have a remote management interface for this device.

Seeing the status of a device

Each device that you connect to Device Management has an endpoint name. This is a long string, which is the unique identifier of your device. If you don't know the endpoint name of your device, check the serial output on your device for a line starting with 'Endpoint name'.

You need to know the endpoint's name to check the device's status in the Device Management Portal. The Device directory page lists all devices associated with your account and their current status. Click the Registered only toggle to only see registered devices.

Two connected devicesThe Device Management Portal device directory page, showing a list of registered and deregistered devices.

Controlling the device

You created four resources before (see main.cpp):

  • 3311/0/5706 - the color of the LED, encoded as three bytes.
  • 3311/0/5853 - the timeout (in seconds) after detection; lights are disabled when this period ends.
  • 3311/0/5850 - whether we should have the lights permanently on (status 1) or off (status 2), or just let the PIR sensor figure it out (status 0).
  • 3201/0/5700 - the number of times the PIR sensor was triggered. This is read only and shows notifications.

You can control these resources through the Device Management Portal. For instance, when you write the value 1 to 3311/0/5850, the lights stay on indefinitely.

Turning the lights on

To test this, click on your Device ID in the device directory in Device Management Portal. This gives you access to a management console where you can quickly test interactions with resources.

Viewing resources on the deviceThese tables show the available resources on this device.

To enable the lights:

  1. Click /3311/0/5850.

  2. Click Edit.

  3. Click Put.

  4. Enter value 1.

  5. Click Send.

    Updating the value of a resource

Now, your lights stay on until you change the status of this resource to 0 (listen to PIR sensor) or 2 (always off).

Setting the color

You can control the color of the lights the same way. The color is encoded in an integer that stores three channels: red, green and blue. Each of the channels can have a value between 0 (off) and 255 (completely on).

To encode the value of a color:

red = 0;
green = 255;
blue = 255;

// alternatively: encode the color as a hex value, via encoded = 0x00ffff

encoded = (red << 16) + (green << 8) + blue;
// 65380

Use the API Console to write this value to resource /3311/0/5706 and change the color of the LED to turquoise.

Other variables

You can also change the value of the timeout (3311/0/5853), in a real light system you probably want at least 30 seconds, and read the number of times the PIR sensor or user button is triggered (3201/0/5700).