Skip to content

Instantly share code, notes, and snippets.

@mmontes11
Last active March 20, 2020 22:51
Show Gist options
  • Save mmontes11/e11a220901c20af024debecb6ef75dbc to your computer and use it in GitHub Desktop.
Save mmontes11/e11a220901c20af024debecb6ef75dbc to your computer and use it in GitHub Desktop.
DHT sensor
import Promise from "bluebird";
import dhtSensorLib from "node-dht-sensor";
export class DHTSensor {
constructor(dhtType, gpio, measurementLocation) {
this.dhtType = dhtType;
this.gpio = gpio;
this.measurementLocation = measurementLocation;
}
toString() {
return `DHT${this.dhtType}_${this.measurementLocation} @ GPIO${this.gpio}`;
}
read() {
return new Promise((resolve, reject) => {
dhtSensorLib.read(this.dhtType, this.gpio, (err, temperatureValue, humidityValue) => {
if (err) {
reject(err);
} else {
resolve({
temperatureValue,
humidityValue,
});
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment