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