Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Last active July 8, 2018 20:34
Show Gist options
  • Save Antoinebr/65a5bbdf6ed5af22ff0923d2c1aaf7b0 to your computer and use it in GitHub Desktop.
Save Antoinebr/65a5bbdf6ed5af22ff0923d2c1aaf7b0 to your computer and use it in GitHub Desktop.
function onPageRequest(req, res) {
res.writeHead(200, {
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*"
});
res.end(JSON.stringify(
{
moisture : percentage()
}
));
}
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',
'Access-Control-Allow-Origin': '*'
});
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