[Yandex Cloud documentation](../../index.md) > [Tutorials](../index.md) > Application solutions > Internet of Things (IoT) > Emulating multiple IoT devices

# Emulating multiple IoT devices

{% note warning %}

Yandex IoT Core is no longer available to new users. 

Current users can create resources until November 1, 2026. Afterwards, the service will go read-only and cease to operate on December 1, 2026. For more information on the timing and procedure, see [Service shutdown](../../iot-core/sunset.md).

{% endnote %}


In this scenario, you will learn to emulate multiple [devices](../../iot-core/concepts/index.md#device) that send messages to MQTT [topics](../../iot-core/concepts/topic/index.md). The example shows the emulation of air sensors that measure the following parameters:
* Temperature
* Humidity
* Pressure
* CO<sub>2</sub> level

Each sensor sends its readings in JSON format. Here is an example:

```json
{
  "DeviceId":"0e3ce1d0-1504-4325-972f-55c961319814",
  "TimeStamp":"2020-05-21T22:53:16Z",
  "Values":[{
    "Type":"Float",
    "Name":"Humidity",
    "Value":"25.281837"
  },
  {
    "Type":"Float",
    "Name":"CarbonDioxide",
    "Value":"67.96608"
  },
  {
    "Type":"Float",
    "Name":"Pressure",
    "Value":"110.7021"
  },
  {
    "Type":"Float",
    "Name":"Temperature",
    "Value":"127.708824"
  }]
}
```

To emulate the operation of multiple devices:
1. [Get your cloud ready](#before-begin).
1. [Install Terraform](#install-terraform).
1. [Describe the infrastructure](#set-configuration).
1. [Deploy the cloud resources](#deploy).

If you no longer need the resources you created, [delete them](#clear-out).

## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).

## Install Terraform {#install-terraform}

Using Terraform in Yandex Cloud, you can create cloud resources of any type, such as [VMs](../../compute/concepts/vm.md), [disks](../../compute/concepts/disk.md), or [images](../../compute/concepts/image.md). For more information about the resources you can create with Terraform, see [this provider guide](../../terraform/index.md).

### From a mirror {#from-yc-mirror}

{% note alert %}

The mirror may be unavailable.

{% endnote %}

You can download a Terraform distribution for your platform from a [mirror](https://hashicorp-releases.yandexcloud.net/terraform/). When the download is complete, add the path to the folder with the executable to the `PATH` variable:

```bash
export PATH=$PATH:/path/to/terraform
```

### From the HashiCorp website {#from-hashicorp-site}

{% list tabs group=operating_system %}

- Windows {#windows}

   Use one of the following methods:
   * [Download the Terraform distribution](https://www.terraform.io/downloads.html) and follow [this guide](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) to install it.
   * Install Terraform using the [Chocolatey](https://chocolatey.org/install) package manager and the command below:

      ```bash
      choco install terraform
      ```

- Linux {#linux}

   [Download the Terraform distribution](https://www.terraform.io/downloads.html) and follow [this guide](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) to install it.

- macOS {#macos}

   Use one of the following methods:
   * [Download the Terraform distribution](https://www.terraform.io/downloads.html) and follow [this guide](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) to install it.
   * Install Terraform using the [Homebrew](https://brew.sh) package manager and the command below:

      ```bash
      brew install terraform
      ```

{% endlist %}

## Describe the infrastructure {#set-configuration}

1. Create the `iot-terraform` folder. It will store the Terraform configuration files.
1. [Download](https://storage.yandexcloud.net/doc-files/emulator_publish.zip) an archive with the files you need for this scenario and unpack it to the `iot-terraform` directory.

   The archive contains:
   * `common.tf`: Terraform provider settings.
   * `files.tf`: Parameters for publishing code files from the local directory.
   * `function.tf`: Parameters of the [function](../../functions/concepts/function.md) used to write emulated messages to devices.
   * `iot_core.tf`: Parameters of the [registry](../../iot-core/concepts/index.md#registry) where the devices are located.
   * `output.tf.tf`: Output variables.
   * `publish`: Files required to create a function.
   * `service_account.tf`: Parameters of the [service account](../../iam/concepts/users/service-accounts.md) being created in this scenario.
   * `trigger.tf`: Parameters of the [trigger](../../functions/concepts/trigger/index.md) to invoke a function with a specified timeout.
   * `variables.tf`: Applicable variables and their values.
1. Edit the `variables.tf` file specifying the following emulation parameters:
   * `token`: [OAuth token](../../iam/concepts/authorization/oauth-token.md) for Yandex Cloud access.
   * `cloud_id`: [Cloud ID](../../resource-manager/operations/cloud/get-id.md).
   * `folder_id`: [Folder ID](../../resource-manager/operations/folder/get-id.md).
   * `zone`: [Availability zone](../../overview/concepts/geo-scope.md).
   * `device_count`: Number of emulated devices.

     {% note info %}

     To emulate the operation of over 1000 devices, you need to increase [quotas](../../iot-core/concepts/limits.md) by making a request to technical support.

     {% endnote %}

   * `subtopic_for_publish`: [Subtopic](../../iot-core/concepts/topic/subtopic.md) in `$devices/<device_ID>/events/<subtopic>` format.
   * `publish_execution_timeout`: Timeout for sending messages in seconds.
   * `publish_cron_expression`: Schedule for sending messages to an MQTT topic as a cron expression. By default, messages are sent every minute.

   You can leave the remaining files unchanged.

## Deploy cloud resources {#deploy}

1. Go to the `iot-terraform` folder and check the configuration using the following command:

   ```bash
   terraform validate
   ```

   Result:

   ```text
   Success! The configuration is valid.
   ```

1. Format the configuration files in the current folder and subfolders:

   ```bash
   terraform fmt
   ```

   Result:

   ```text
   main.tf
   variables.tf
   ```

1. After checking the configuration, run the command:

   ```bash
   terraform plan
   ```

   You will see a list of resources and their properties. This is a verification step: no resources will be created. Otherwise, Terraform will show any detected errors.

   {% note alert %}

   You will be charged for all the resources created with Terraform. Check the pricing plan carefully.

   {% endnote %}

1. To create resources, run the command:

   ```bash
   terraform apply
   ```

1. Confirm creating the resources by typing `yes` and pressing **Enter**.

   Result:

   ```text
   Outputs:

   function = "d4erep.......aq085f0"
   iot_core = "are.......ht10enkb3u"
   service_account = "ajestqfepa.......0l6"
   trigger = "a1sva8sse.......7kf6"
   ```

   Terraform will create all the required resources, and the terminal will display the IDs of the resources created. You can check the new resources and their settings using the [management console](https://console.yandex.cloud).

## Delete the resources you created {#clear-out}

{% list tabs group=instructions %}

- Management console {#console}

  1. Delete the registry:
     1. Go to your working [folder](../../resource-manager/concepts/resources-hierarchy.md#folder).
     1. Navigate to **IoT Core**.
     1. To the right of the registry you created, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
     1. Click **Delete**.
  1. Delete the devices:
     1. Navigate to your working folder.
     1. Navigate to **IoT Core**.
     1. Select the registry.
     1. Navigate to the **Devices** tab.
     1. To the right of the device you created, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
     1. Click **Delete**.
  1. Delete the function:
     1. Navigate to your working folder.
     1. Navigate to **Cloud Functions**.
     1. To the right of the function you created, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
     1. Click **Delete**.
  1. Delete the trigger:
     1. Navigate to your working folder.
     1. Navigate to **Cloud Functions**.
     1. Navigate to the **Triggers** tab.
     1. To the right of the trigger you created, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
     1. Click **Delete**.
  1. Delete the service account:
     1. Navigate to your working folder.
     1. Navigate to **Identity and Access Management**.
     1. In the left-hand panel, select ![FaceRobot](../../_assets/console-icons/face-robot.svg) **Service accounts**.
     1. In the row with the name of the service account you created, click ![ellipsis](../../_assets/console-icons/ellipsis.svg) and select **Delete**.
     1. Click **Delete**.

{% endlist %}