I might try turning this into a full-blown tutorial for the pages, but in case that never gets started, here's the code I've copy-pasted together:
var temperature;
var humidity;
var dht = require("DHT22").connect(D2);
function onPage(req, res){
var page = temperature + "," + humidity;
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(page);
}
function writeScreen(){
g.clear();
g.drawString(temperature, 0, 0);
g.drawString(humidity, 0, 30);
g.flip();
}
// I2C
I2C1.setup({scl:D5,sda:D4});
var g = require("SSD1306").connect(I2C1, writeScreen);
g.setFont("4x6", 5);
function readDHT(){
dht.read(function(a) {
temperature = a.temp.toString();
humidity = a.rh.toString();
console.log("Temp is "+a.temp.toString()+" and RH is "+a.rh.toString());
});
writeScreen();
}
setInterval(readDHT, 2000);
require("http").createServer(onPage).listen(80);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I might try turning this into a full-blown tutorial for the pages, but in case that never gets started, here's the code I've copy-pasted together:
My node.red asks http://esp_hostname.local for the page, and parses it as csv.