chenyc
2025-12-09 545c24c6a711d71b65f3d4e8122fee3837fb1edc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const aliyunIot = require('../../');
 
const device = aliyunIot.device({
  productKey: '<productKey>',
  deviceName: '<deviceName>',
  deviceSecret: '<deviceSecret>'
});
 
device.on('connect', () => {
  console.log('connect succesfully!');
  let count = 3;
  const interval = setInterval(() => {
    const t = Math.floor(Math.random() * 32);
    console.log(`Post current temperature: ${Math.floor(Math.random() * 32)}`);
    device.postProps({
      CurrentTemperature: t
    });
    if (--count <= 0) {
      console.log('Report filterChange event');
      device.postEvent('changeFitler', {
        PM25Value: 20
      });
    }
  }, 1000);
});
 
device.on('error', (err) => {
  console.log(err);
});