Integrate with Message Service

Last Updated on : 2024-09-11 08:39:29

Tuya Cube provides the Pulsar SDK for Java. In this topic, the Java development tool IntelliJ IDEA is used to receive messages.

Step 1: Download the demo source code

Go to the GitHub Pulsar SDK repository, click Code, download the package to the local computer, and then decompress the package.

Step 2: Set up the test environment

  1. Open IntelliJ IDEA, click Open, and then find the downloaded and decompressed file in the previous step to open the source code project.

    Integrate with Message Service
  2. Modify parameters in open-mq-sdk/src/main/java/com.tuya.open.sdk/mq/MqConsumer.java. Modify the Java project to a test environment.

    private MqEnv	env = MqEnv.TEST;
    
    Integrate with Message Service
    • MqEnv.TEST represents the test environment.

    • MqEnv.PROD represents the production environment.

      For more information about the parameters, see mq/MqEnv.java.

Step 3: Configure project parameters

Modify parameters in open-mq-sdk/src/main/java/com.tuya.open.sdk/mq/MqConsumer.java.

String url = MqConfigs.CN_SERVER_URL;
String accessId = "xt*****ff**n1****8ufo";
String accessKey = "479bcb7345******582d9c******4ef7";

The parameters are described as follows.

  • accessId: Enter the value of Access ID in the Authorization Key section of the cloud project on the Tuya IoT Development Platform.

  • accessKey: Enter the value of Access Secret in the Authorization Key section of the cloud project on the Tuya IoT Development Platform.

  • url: For more information about the parameters, see mq/MqConfigs.java. Be sure to use the domain name URL of the private cloud.

    Integrate with Message Service

Step 4: Receive messages in the test environment

  1. Configure a test device.

    1. On the page of Message Service, after your subscription is ready, Subscribed appears in the Status column. Then, click the Message Test tab.

      Integrate with Message Service
    2. Enter the associated device ID in the search box, click the magnifier icon, and then double-click the selected device.

      Integrate with Message Service
    3. If an associated device is specified as a test device, the test device will report a message to the test channel for you to debug device features.

  2. On the IntelliJ IDEA, right-click the ConsumerExample.java file and select Run to run the program.

    Integrate with Message Service
  3. Control the device with a mobile app, such as the Smart Life app.

    1. Turn on the test light.
    2. Adjust the brightness of the light.
  4. Automatically get the push messages on IntelliJ IDEA.

    Integrate with Message Service

Description of data properties

For more information about message types, see Message Types.

Parameter
Data type
Description
protocol Integer The protocol number.
pv String The version of the communication protocol.
t Long The timestamp.
sign String The signature.
data String The data body.
{
   "protocol": 4,
   "pv": "2.0",
   "t": 146052438362,
   "data":"4FDEE3FE59Fxxxx***",
   "sign": "58285279b5b5790c7d917dxxxxx***"
}

Practices of push messages