Last Updated on : 2024-06-18 06:20:12download
The Smart Industry Platform actively pushes event data to you through Pulsar, which meets your demands for real-time and persistent messages.
If you need to subscribe to device messages, you need to develop the client through the OEM app or App SDK. Devices that are paired by the Jizhi Lighting Control app do not support pushing messages.
Pulsar is a multi-tenant, high-performance solution for server-to-server messaging. Pulsar was originally developed by Yahoo and now is under the stewardship of the Apache Software Foundation. Tuya’s message service is customized and modified based on Apache Pulsar. Message service integration can be achieved with the Pulsar SDK provided by Tuya.
As a message broker, Pulsar is built on the Pub/Sub pattern. In this pattern, producers publish messages to topics. Consumers subscribe to those topics, process incoming messages, and send an acknowledgment when processing is completed.
When a subscription is created, Pulsar retains all messages, even if the consumer is disconnected. Retained messages are discarded only when a consumer acknowledges that those messages are processed successfully.
Moreover, multiple consumers can subscribe to one topic. When messages are processed successfully, consumers need to send acknowledgments to brokers, so brokers can discard these messages. The Pulsar brokers provided by Tuya allocate multiple partitions for each topic and send messages to the specified partitions and consumers.
Authentication security:
Tuya’s Pulsar message service adopts a highly customized authentication algorithm and dynamic tokens to enhance security. You can ignore the implementation details and accomplish the authentication based on the provided SDK.
Data security:
You can submit your account and clientId
(accessId
) to the technical support of the Smart Industry Platform to subscribe to messages.
The following data must be provided:
username
: Enter the Access ID of cloud API authorization that you get from the Tuya Developer Platform.password
: Enter the Access Secret of cloud API authorization that you get from the Tuya Developer Platform.url
(You can choose the desired URL to be accessed):
pulsar+ssl://mqe.tuyacn.com:7285/
pulsar+ssl://mqe.tuyaus.com:7285/
pulsar+ssl://mqe.tuyaeu.com:7285/
String url = "";
String accessId = "";
String accessKey = "";
MqConsumer mqConsumer = MqConsumer.build()
.serviceUrl(url)
.accessId(accessId)
.accessKey(accessKey)
.maxRedeliverCount(3)
.messageListener(new MqConsumer.IMessageListener() {
@Override
public void onMessageArrived(Message message) throws Exception {
//write your own message processing logic
}
});
mqConsumer.start();
Before you get the real data
, you can set the tamper-proof MD5 signature verification. The signature algorithm is processed in the following procedure:
sign
and the parameters with an empty value) into key=val
.key
. Format example of the assembled string: k1=v1||k2=v2
.k1=v1||k2=v2...kn=vn||key
.sign
value, it means the data is not tampered. Otherwise, the data is tampered.The data is decrypted after the signature is checked.
accessKey
through the AES (ECB mode) to get the real device status data.Parameter | Type | Description |
---|---|---|
encryptPayload | String | The ciphertext of the message body. |
sign | String | The signature that is generated by the specified signature algorithm. |
encryptType | String | The encryption type. |
t | Long | The 13-digit standard timestamp. |
v | String | The version number. |
{
"encryptType": "aes_ecb",
"v": "1.0",
"t": 1588918073598,
"encryptPayload":"4FDEE3FE59FCD76E260******33A478EB2C2004EF4289276****",
"sign": "4b7084b3b87b550c0d967f7736e9****"
}
Parameter | Type | Description |
---|---|---|
bizCode | String | The business type. |
eventType | String | The event type. |
data | JSON | The message data. |
Description of business type
bizCode | Description |
---|---|
device | Push device events. |
voice | Push voice-enabled services. |
construction | Push construction services. |
{
"bizCode": "device",
"eventType": "dp_report",
"data": {}
}
eventType | Description |
---|---|
bind | Bind a device. |
unbind | Unbind a device. |
reset | Reset a device. |
online | Put a device online. |
offline | Put a device offline. |
dp_report | Report the device status. |
name_update | Rename a device. |
{
"data":{
"devId":"02200434dc4f221a****",
"deviceName":"****socket****(wifi)_0",
"gwId":"",
"location":{
"child":{
"id":"1256152666585710592",
"name":"****room where the test is carried out****"
},
"id":"1256148753241358***",
"name":""
},
"namespace":"BgdBXzUhIg5x77770LL1OfpD****",
"ownerId":"139960xx",
"position":"****study room****",
"productId":"qCY4YFq02AP0i***",
"sub":false,
"uid":"bay1588324079695k***",
"uuid":"02200434dc4f221a6***"
},
"bizCode":"device",
"eventType":"bind"
}
{
"data":{
"devId":"02200434dc4f221***",
"namespace":"****Your****namespace"
},
"bizCode":"device",
"eventType":"unbind"
}
{
"data":{
"devId":"02200434dc4f221***",
"namespace":"****Your****namespace"
},
"bizCode":"device",
"eventType":"reset"
}
{
"data":{
"devId":"02200434dc4f221a***",
"namespace":"****Your****namespace",
"time":1589019224062
},
"bizCode":"device",
"eventType":"online"
}
{
"data":{
"devId":"02200434dc4f221a6***",
"namespace":"****Your****namespace",
"time":1589019224062
},
"bizCode":"device",
"eventType":"offline"
}
{
"data":{
"devId": "002dj00118fe34***",
"productId": "The product ID defined on the Tuya Developer Platform",
"dataId": "145************",// The global unique ID, indicating the reporting of single data
"namespace":"Your namespace",
"status": [
{
"code": "switch_1",
"value": "true",
"time": 1589767589137
}
]
},
"bizCode":"device",
"eventType":"dp_report"
}
{
"data":{
"devId":"02200434dc4f221a***",
"deviceName":"****socket****",
"namespace":"****Your****namespace"
},
"bizCode":"device",
"eventType":"name_update"
}
eventType | Description |
---|---|
voice_nlu | Push the speech recognition result. |
voice_room_bind | Push the binding result of a speaker and a room. |
{
"data":{
"devId":"6cd40b4ed084ac264bm***",
"namespace":"BgdBXzUhIg5x77770LL1OfpDw*****",
"nlu":"[{\"entities\":[{\"value\":\"TV\",\"entity\":\"deviceName\"}], \"domain\":\"mediaControl\",\"confidence\":1,\"text\":\"Pause the TV\",\"intent\":\"pause\"}]",
"productId":"fabze***",
"uid":"bay1588324079695k***",
"uuid":"f572ecc09e19d***"
},
"bizCode":"voice",
"eventType":"voice_nlu"
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback