Count meeting attendees

Updated at:
Copy as MD

This example shows how to create a business service that counts meeting attendees using a global variable. The service then pushes a message with the count to a DingTalk group.

Prerequisites

You have created a project, such as project_space. For more information, see Project.

Step 1: Create a card reader device

  1. Log on to the IoT Platform development console. In the upper-left corner, select an instance. In the navigation pane on the left, click Project Management, and then click the project_space project card.

  2. On the project details page, click Products in the navigation pane on the left. Click Create Product. Configure the parameters and click Save.

    In this example, name the product Card Reader, select Custom Category, and use the default values for the other parameters.

    For more information about the parameters, see Create a product.

  3. In the product list, find the Card Reader product and click View in the Actions column. Then, click Function Definition. Define a custom property for the product and name it Card Number. Set the identifier to CardID, the data type to String, and the access mode to Read/Write.

  4. On the product details page, click Manage next to the device count. On the Devices page, click Add Device to add a card reader device named reader. For more information, see Device.

Step 2: Create a business service

  1. Create a business service. For more information, see Create a business service.

  2. In the business logic editor, add a numeric global variable named count. Set its default value to 0.

    For more information, see Configure variables.

  3. In the business logic editor, in the left-side pane, click Nodes. Drag the Device Trigger, Numeric Calculation, Set Variable, and DingTalk Robot nodes to the canvas. Then, connect and configure them.

    Node

    Configuration

    Device Trigger

    Select the property reporting type for the Card Reader product and the reader device.

    Numeric Calculation

    Set the global variable count as the data source. After the device is triggered, the value of the variable is incremented by 1.

    The Numeric Calculation node outputs the final result using the calcul_result parameter.

    Set Variable

    Click +Variable. Set the value of the count variable to the calcul_result value from the Numeric Calculation node. This action increments the count.

    Note

    The output parameter field of the Set Variable node is the same as the output parameter field of the preceding node.

    DingTalk Robot

    Configure the webhook URL for the DingTalk group robot. For more information, see Create a DingTalk robot.

    Set the configuration method to custom text.

    {
      "msgtype": "text",
      "text": {
        "content": "Number of check-ins: {{payload.calcul_result}}"
      }
    }
    Note

    payload.calcul_result represents the output result from the preceding Set Variable node.

  4. In the upper-right corner of the page, click the Save icon 保存.

Step 3: Debug and publish

  1. On the business service editor page, click the Deploy & Debug icon 部署 in the upper-right corner to deploy and start the service.

  2. After the deployment is complete, click the Deploy & Debug icon 部署 again to debug the service.

    1. Click Debug > Go to to open the product's Device Emulator page.

    2. Click Start Emulated Device.

    3. Select Uplink Command Debugging > Property Reporting.

    4. In the default module, push the debug command.

      In this example, simulate a user swiping a card three times to check in. This action pushes the CardID value three times.

      On the Uplink Command Debugging tab, go to Property Reporting. Enter 1234, 5678, and 91011 as CardId values one by one and push each value. The device log on the right shows three successful property reports.

      The DingTalk group receives a notification message.

  3. Click the Publish icon 发布 to publish the service.

  4. You must publish the service to the cloud before it can be called.