Yandex Cloud
Search
Discuss with expertTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
    • Cloud Interconnect
    • Cloud Backup
    • Cloud Registry
    • Yandex AI Studio
    • Compute Cloud
    • Object Storage
    • Managed Service for Kubernetes®
    • Yandex BareMetal
    • Smart Web Security
    • Security Deck
    • Managed Service for PostgreSQL
    • Managed Service for ClickHouse®
    • Monium
    • Cloud CDN
    • Network Load Balancer
    • Virtual Private Cloud
    • Cloud DNS
    • Application Load Balancer
    • Yandex Cloud Video
    • Stackland
    • Yandex Cloud Router
    • Yandex Managed Service for Trino
    • Managed Service for MySQL®
    • Managed Service for Valkey™
    • Managed Service for Apache Spark™
    • Yandex StoreDoc
    • Managed Service for OpenSearch
    • Managed Service for Apache Kafka®
    • Data Transfer
    • Yandex MPP Analytics Engine for PostgreSQL
    • Yandex Managed Service for Apache Airflow®
    • Data Processing
    • Yandex MetaData Hub
    • Managed Service for YDB
    • Managed Service for Sharded PostgreSQL
    • Managed Service for YTsaurus
    • Yandex WebSQL
    • DataLens
    • Yandex Search API
    • SpeechSense
    • SpeechKit
    • DataSphere
    • Vision OCR
    • Translate
    • Yandex Identity Hub
    • Key Management Service
    • Certificate Manager
    • Yandex Lockbox
    • Audit Trails
    • SmartCaptcha
    • Cloud Desktop
    • Yandex SIEM
    • SourceCraft Code Assistant
    • Container Registry
    • Managed Service for GitLab
    • Managed Service for Prometheus®
    • Cloud Functions
    • API Gateway
    • Yandex Cloud Postbox
    • Message Queue
    • Serverless Integrations
    • IoT Core
    • Data Streams
    • Serverless Containers
    • Cloud Notification Service
    • Yandex Query
    • Identity and Access Management
    • Yandex Cloud Console
    • Resource Manager
    • Yandex Cloud Billing
    • Yandex Cloud Quota Manager
    • Cloud Apps
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex IoT Core
  • Service shutdown
    • All tutorials
      • Sending a message
      • Subscribing a device or registry to receive messages
    • Working with Yandex IoT Core from an Android device in Java
    • Working with Yandex IoT Core in C#
    • Working with Yandex IoT Core in Java
    • Writing device data to a database
    • Monitoring the status of geographically distributed devices
    • Monitoring sensor readings and event notifications
    • Testing message delivery
    • Emulating multiple IoT devices
    • Migrating from Yandex IoT Core to open-source MQTT solutions
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Connecting to an MQTT server
  • Subscribing a registry to device topics
  • Subscribing a device to registry topics
  1. Tutorials
  2. Working with Mosquitto
  3. Subscribing a device or registry to receive messages

Subscribing a device or registry to receive messages using Mosquitto

Written by
Yandex Cloud
Updated at August 6, 2026
View in Markdown
  • Getting started
  • Connecting to an MQTT server
  • Subscribing a registry to device topics
  • Subscribing a device to registry topics

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.

You can subscribe:

  • A registry to device events using the $devices/<device_ID>/events or $registries/<registry_ID>/events topics.
  • A registry to device events using the permanent topics: $devices/<device_ID>/state or $registries/<registry_ID>/state.
  • A device to registry commands using the $devices/<device_ID>/commands or $registries/<registry_ID>/commands topics.
  • A device to registry commands using the permanent topics: $devices/<device_ID>/config or $registries/<registry_ID>/config.

To learn more about messaging, see Sending a message using Mosquitto.

Warning

Registry topics and device topics are independent of each other. If a device sends data to a device telemetry topic, you can only receive this data by subscribing to that topic. The same applies to registry topics.

Getting startedGetting started

Set up the following:

  1. Registry.
  2. Registry certificate.
  3. Device.
  4. Device certificate.
  5. Mosquitto, an open source MQTT message broker. This guide uses it for sending messages and subscribing to devices. Download and install it to work with commands provided in this guide.

Connecting to an MQTT serverConnecting to an MQTT server

To connect to the MQTT server, use the following settings:

  • CA certificate.
  • Server address: mqtt.cloud.yandex.net.
  • Server port: 8883.
  • Protocol: TLSv1.2.

Subscribing a registry to device topicsSubscribing a registry to device topics

You can subscribe a registry to topics of one, multiple, or all devices added to it. Let's look at all the options.

Subscribe a registry to a device or devices using the following parameters:

  • -h: MQTT server address.
  • -p: MQTT server port.
  • --cafile: Path to the certificate from the certificate authority.
  • --cert: Path to the public part of the registry.
  • --key: Path to the private part of the registry certificate.
  • -t: Device topics.
  • -q: Quality of service (QoS) level.

Note

If you encounter an error while running a command, add the --debug flag and retry the command. This flag outputs a debug log when running the command, which helps troubleshoot the issue.

Mosquitto
  • Subscribe a registry to a single device's topic:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$devices/<device_ID>/events' \
      -q 1
    
  • Subscribe a registry to a device's permanent topic:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$devices/<device_ID>/state' \
      -q 1
    
  • Subscribe a registry to the topics of multiple devices:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$devices/<device_1_ID>/events' \
      -t '$devices/<device_2_ID>/events' \
      -q 1
    
  • Subscribe a registry to the permanent topics of multiple devices:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$devices/<device_1_ID>/state' \
      -t '$devices/<device_2_ID>/state' \
      -q 1
    
  • Subscribe a registry to the topics of all devices:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$registries/<registry_ID>/events' \
      -q 1
    
  • Subscribe a registry to the permanent topics of all devices:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert registry-cert.pem \
      --key registry-key.pem \
      -t '$registries/<registry_ID>/state' \
      -q 1
    

    The registry will only receive data from devices that send messages to the $registries/<registry_ID>/events or $registries/<registry_ID>/state topic.

Subscribing a device to registry topicsSubscribing a device to registry topics

Commands from a registry can be given to a specific device or all devices in the registry. This involves using different topics.

Subscribe a device to a registry using the following parameters:

  • -h: MQTT server address.
  • -p: MQTT server port.
  • --cafile: Path to the certificate from the certificate authority.
  • --cert: Path to the public part of the certificate.
  • --key: Path to the private part of the device certificate.
  • -t: Device topic.
  • -q: Quality of service (QoS) level.

Note

If you encounter an error while running a command, add the --debug flag and retry the command. This flag outputs a debug log when running the command, which helps troubleshoot the issue.

Mosquitto
  • Subscribe a device to topics that are commands for a specific device:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert device-cert.pem \
      --key device-key.pem \
      -t '$devices/<device_ID>/commands' \
      -q 1
    
  • Subscribe a device to permanent topics that are commands for a specific device:

    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert device-cert.pem \
      --key device-key.pem \
      -t '$devices/<device_ID>/config' \
      -q 1
    
  • Subscribe a device to topics that are commands for all devices:

    ```bash
    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert device-cert.pem \
      --key device-key.pem \
      -t '$registries/<registry_ID>/commands' \
      -q 1
    ```
    
  • Subscribe a device to permanent topics that are commands for all devices:

    ```bash
    mosquitto_sub -h mqtt.cloud.yandex.net \
      -p 8883 \
      --cafile rootCA.crt \
      --cert device-cert.pem \
      --key device-key.pem \
      -t '$registries/<registry_ID>/config' \
      -q 1
    ```
    
    Only devices subscribed to the `$registries/<registry_ID>/commands` or `$registries/<registry_ID>/config` topic will receive commands.
    

Was the article helpful?

Previous
Sending a message
Next
Working with Yandex IoT Core from an Android device in Java
© 2026 Direct Cursus Technology L.L.C.