-
-
Save thbar/65dc7e6434e12fa6a35b519ce06428ff to your computer and use it in GitHub Desktop.
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
function onPageRequest(req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'application/json', | |
"Access-Control-Allow-Origin": "*" | |
}); | |
res.end(JSON.stringify( | |
{ | |
moisture : percentage() | |
} | |
)); | |
} |
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', | |
'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