Data Point Transmission

Last Updated on : 2024-05-17 02:58:16download

This topic describes how the beacon mesh device reports and receives data point (DP) data. Mains-powered products typically only receive DP data, such as from mobile phones. Generally, DP data reporting is not used because it has specific requirements for devices.

Overview

Concepts

Concepts Description
DP A DP is an abstract representation of a feature you want to apply to a physical device. It can be defined using six data types: Boolean, value, string, raw, enum, and fault. A device is described with a set of DPs.
Upstream transmission A device reports information to a mobile phone or gateway.
Downstream transmission A mobile phone or gateway sends information to a device.

Features

  • Receive DP data: When receiving a DP message from the mobile phone or gateway, the device sends it to the application layer through a callback. You receive and process the DP data in the callback.

  • Report DP data: When the DP status changes, such as temperature and humidity, the device sends the updated status to the mobile phone or gateway. It reports DP data through advertising packets without acknowledgment.

Data structure

No external data structure.

API description

Receive DP data

Implement the following beacon mesh DP receiving callback at the application layer to monitor the DP commands from the mobile phone, gateway, or remote.

void app_dps_download(u8 dpid, u8 dpty, u8 dplen, u8 *dpvalue, beacon_frame_s *p_frame){
    PR_DEBUG("dpid=%d dpty=%d, dplen=%d, dpvalue=[",dpid,dpty,dplen);
    PR_DEBUG_HEX_ARRAY(dpvalue,dplen);
    PR_DEBUG_RAW("]\n");
    switch(dpid){
        case 0x01://onoff
        case 101:
            app_led_onoff(dpvalue[0]);
            break;
        case 0x02://mode: white,color,scene,music
            break;
        default:
            break;
    }
}

Report DP data

Function u8 frame_send(u8 head, u16 dst, u8 subcmd,
u8* payload, u8 *key, u8 ttl);
Packet
Purpose Send the payload data to the destination address, with the time to live (TTL) up to 3.
  • The demo application describes how to use this basic DP data sending function to encapsulate application functions for transmitting different types of DP data and heartbeats.
  • When there is an ongoing transmission, calling this function will interrupt the current packet transmission and initiate a new one.
-
Request parameter u8 head The head.
-> u16 dst The destination address.
-> u8 subcmd The subcommand.
-> u8* payload The payload.
-> u8 *key The secret key.
-> u8 ttl The TTL.

Example

Report DP status.

u8 payload[16];
memset(payload,0,16);
payload[0] = 1;//dp id = 1
payload[1] = 0x11;//dp kind = 1; dp len = 1 (each 4 bits)
payload[2] = led_onoff;//dp value
frame_send(0x08, 0x8000, 0x0A, payload, beacon_dev.beaconkey, 3);

Note: The mobile phone stays in the receiving window for a specified period after sending a command to the device. If reporting to the gateway is not supported, the device will be restricted by a timed reporting window. There is no such limitation for the gateway.

Support and help

If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.