var altitude = 188; // current altitude in m
var mode = 2; //resolution of sensor conversion (0-3)
var afdt = 1; //present numbers after dot
var press = 0; //pressure
var temp = 0; //temperature
var peri = 2; //period of reading sensor in sec.
var cl = 0; // SCL to GPIO0
var da = 2; // SDA to GPIO2
function aftDot(number,ad)//Formatting numbers.
{
return (number.toString()).substr(0,(number.toString()).indexOf('.')+1+ad);
}
function readBMP()//read BMP85 or BMP180 sensor
{
I2C1.setup({scl:cl,sda:da});
var bmp = require("BMP085").connect(I2C1,mode);
bmp.getPressure(function(d)
{
press = aftDot(bmp.getSeaLevel(d.pressure, altitude)/100,afdt);
temp = aftDot(d.temperature,afdt);
console.log("Sea level pressure: " + press+ " hPa");
console.log("Temperature: " + temp + " C");
}
);
return;
}
function repeat()
{readBMP(),setTimeout(repeat, peri*1000);}
repeat();