---
name: "SmartDeviceModel.onDpDataChange"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.0.0" }
---

## SmartDeviceModel.onDpDataChange

> [VERSION] @ray-js/panel-sdk >= 1.0.0

### Description

Listen for smart device DP change events

### Parameters

`(listener: Function)`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `listener` | `(data: DpsChanged) => number` | Yes | Event callback that receives parameters containing deviceId, dps (changed DP ID→value mapping), etc. |

### Return Value

None


### Referenced Types

##### `type` DpsChanged

DP change event callback parameters (single device)

| Property | Type | Description |
| --- | --- | --- |
| `deviceId` | `string` | Device ID |
| `gwId` | `string` | Gateway device ID for a sub-device; absent for non-sub-devices |
| `dps` | `Record<string, any>` | Changed DP data, where the key is the DP ID and the value is the DP value |
| `dpsTime` | `Record<string, number>` | Timestamp of the DP data change (may be empty) |


### Examples

#### Example

```typescript
const id = device.onDpDataChange((data) => {
  console.log('DP change:', data.dps);
});
// Unsubscribe
device.offDpDataChange(id);
```
