sendMqttMessage

Requires:
DeviceKit≥3.3.0@ray-js/ray≥1.4.21
Platforms:
iOSAndroid
import { device } from '@ray-js/ray';

const { sendMqttMessage } = device;

// Promise usage
try {
  const res = await sendMqttMessage({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Method signature
sendMqttMessage(params: )
Minimum SDK versions
iOSThingSmartDeviceKitBizBundle
≥ 5.2.0
Androidcom.thingclips.smart:thingsmart-bizbundle-devicekit
≥ 5.2.0

Description

Send a message via the MQTT channel.

Parameters

PropertyTypeRequiredDescriptionMinimum SDK versions
messageRecord<string, Record<string, any>>YesMessage content—
deviceIdstringYesdevice ID—
protocolnumberYesProtocol number—
optionsRecord<string, Record<string, any>>YesReserved marker for issuing-logic configuration; can be extended later (e.g., issuing sounds, follow-up actions after an operation).—
complete() => voidNoCompletion callback (executed on both success and failure)—
success(params: boolean) => voidNoCallback on successful API call—
fail(params: Object) => voidNoFailure callback—
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

import { device } from '@ray-js/ray'

device.sendMqttMessage({
  message: { "xx": {} },
  deviceId: "xx",
  protocol: 1,
  options: { "xx": {} },
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});