Created
September 8, 2017 10:15
-
-
Save Antoinebr/cc5f2938ea3630df6b607a0de12efee7 to your computer and use it in GitHub Desktop.
espruino-DHT22.js
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
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