Publish
Publishes message on behalf of specified device
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const PublishDeviceDataRequest =
cloudApi.iot.devices_device_data_service.PublishDeviceDataRequest;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.DeviceDataServiceClient);
const result = await client.publish(
PublishDeviceDataRequest.fromPartial({
deviceId: "deviceId",
topic: "topic",
// data: Buffer.from([])
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.iot.devices.v1.device_data_service_pb2_grpc import DeviceDataServiceStub
from yandex.cloud.iot.devices.v1.device_data_service_pb2 import PublishDeviceDataRequest
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(DeviceDataServiceStub)
response = service.Publish(
PublishDeviceDataRequest(
device_id="deviceId",
topic="topic",
# data = b''
)
)
print(response)
PublishDeviceDataRequest
deviceId
: string
ID of device publishing message
topic
: string
Topic where message should be published
data
: bytes
Content of the message