Last active
March 20, 2020 22:51
-
-
Save mmontes11/e11a220901c20af024debecb6ef75dbc to your computer and use it in GitHub Desktop.
DHT sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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