sendMqttMessage(params: Object)

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);
}

Description

Send a message via the MQTT channel.

Parameters

PropertyTypeRequiredDescription
YesMessage content
deviceIdstringYesdevice ID
protocolnumberYesProtocol number
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)
NoCallback 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);
  },
});