# Mini Program device message

# Capacity Introduction

Mini Program device messageIs a long-term subscription type ofMini Program Subscription Message, and needs to be completedDevice accessBefore it can be used.

In the process of using the device, users need to pay attention to some events triggered by the device and need human intervention. For example, security cameras detect anomalies, insufficient equipment supplies, equipment failure and so on.

Mini Program device messageThe ability is that as long as the user subscribes to notifications within the Mini Program, the developer can send these events to the user in the form of subscription messages. Message in the WeChat product form, currently inService NotificationForm presented.

# Development process

# 1. Device access

If the Mini Program wants to use the device messaging capability, it first needs to access the device, seeDevice accessDocumentation.

Upon completion of the access, the developer has access to the model_id 。model_id Corresponding to a device type, it is also an important certificate to invoke the interface related to the device capability of the Mini Program.

# 2. Get the template ID

log inMini Program management backgroundfunctionSubscribe MessagePublic Template LibraryLong term subscriptionTo view the optional device message templates.

Select the required keywords in the device message template and submit.

Note: The keyword content of the Device Message Template is generated by the platform and is an enumeration value. Developers cannot customize the content.

After submission, it can be found atMy templateFind the template corresponding to the template in ID , Each template is template_id Mark.

# 3. Get Equipment Tickets

Obtain SnTicket Used forInitiate a subscriptionSteps.

See Server Device Ticket Interface hardwareDevice.getSnTicket

# 4. Initiate a subscription

call wx.requestSubscribeDeviceMessage The interface will have the following authorization pop-up window, the user agrees to subscribe to the message, the device message will be sent to the user's WeChat session.

Complete device message subscription in Mini Program

When users subscribe to the device message, they need to manually click "Add Reminder," and the device will trigger the message before the strong reminder state of "ring + vibration," and the developer can guide it in the front-end interface.

# sample code

wx.requestSubscribeDeviceMessage({
    sn: 'xxxx',
    snTicket:  'xxxxx', 
    modelId: 'xxxxx', 
    tmplIds: ['xxxxx' ],
    success(res) {
        console.log('[wx.requestSubscribeDeviceMessage success]: ', res)
        // { 'QCpBsp1TGJ1ML-UIwAIMkdXpPGzxSfwJqsKsvMVs3io':  'accept' }
    },
    fail(res) {
        console.log('[wx.requestSubscribeDeviceMessage fail]: ', res)
    }
})

# 5. Send Device Messages

Developers push device messages to users through the WeChat server interface.

See Server Device Message Sending Interface hardwareDevice.send

Service Notification - Device Message

Device message specific form