/
nova.js
37 lines (27 loc) · 1.07 KB
/
nova.js
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
30
31
32
33
34
35
36
37
'use strict';
const SDS = require("hazyair-nova");
class Nova {
constructor(model, options) {
this.model = model;
this.sensor = new SDS(options.device);
}
dust() {
return new Promise((resolve, reject) => {
Promise.all([this.sensor.setReportingMode('active'), this.sensor.setWorkingPeriod(0)]).then(() => {
this.sensor.on('measure', (data) => {
let result = { 'concentration_pm2.5_normal': { 'value': data['PM2.5'], 'unit': 'µg/m^3' },
'concentration_pm10_normal': { 'value': data.PM10, 'unit': 'µg/m^3' },
'model': this.model, 'timestamp': Date.now() };
this.sensor.setWorkingPeriod(30).then(() => {
return resolve(result);
}).catch((error) => {
return reject(error);
});
});
}).catch((error) => {
return reject(error);
});
});
}
}
module.exports = Nova;