Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Created September 8, 2017 10:15
Show Gist options
  • Save Antoinebr/cc5f2938ea3630df6b607a0de12efee7 to your computer and use it in GitHub Desktop.
Save Antoinebr/cc5f2938ea3630df6b607a0de12efee7 to your computer and use it in GitHub Desktop.
espruino-DHT22.js
var pin = NodeMCU.D2;
var dht = require("DHT22").connect(pin);
var data = {};
setInterval( () =>{
dht.read(function (a) {
data.temperature = a.temp;
data.humidity = a.rh;
});
console.log(
'Temperature is : ', data.temperature,
'Humidity is : ',data.humidity
);
},5000);
function onPageRequest(req, res) {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(data));
}
function onInit(){
require("http").createServer(onPageRequest).listen(80);
}
onInit();
save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment