Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env node
- var net = require('net');
- var fs = require('fs');
- var pconfig = require('./weatherstation/bmp085-pressure');
- var w1config = require('./weatherstation/w1-temperature');
- var cosmconfig = require('./weatherstation/cosm');
- var temperature = 20;
- var pressure = 1020;
- var w1temperature = 20;
- var tempArray = {0: temperature, 1: temperature, 2: temperature};
- var pressureArray = {0: pressure, 1: pressure, 2: pressure};
- var w1tempArray = {0: w1temperature, 1: w1temperature, 2: w1temperature};
- var pscale = pconfig.pressureConfig.scale;
- var pfileData = pconfig.pressureConfig.file;
- var tscale = pconfig.tempConfig.scale;
- var tfileData = pconfig.tempConfig.file;
- var w1tscale = w1config.w1tempConfig.scale;
- var w1tfileData = w1config.w1tempConfig.file;
- var n = 0;
- try {
- fs.writeFileSync('/sys/class/i2c-adapter/i2c-3/new_device', 'bmp085 0x77', encoding = 'ascii');
- }
- catch (ex) {
- console.log('bmp085 driver load failed.');
- }
- function readWeather(n) {
- pressureArray[n] = fs.readFileSync(pfileData) / pscale;
- tempArray[n] = fs.readFileSync(tfileData) / tscale;
- w1data = fs.readFileSync(w1tfileData);
- w1data = '' + w1data;
- w1Breakdown = w1data.split("\n");
- w1tempArray[n] = w1Breakdown[1].split("t=")[1] / w1tscale;
- console.log(n + ': ' + pressureArray[n] + ' ' + tempArray[n] + ' ' + w1tempArray[n]);
- n++;
- if(n>2)
- return
- setTimeout(function() { readWeather(n); }, 3000);
- }
- readWeather(n)
- // Average the 3 readings and round to 1 decimal
- temperature = Math.round((tempArray[0] + tempArray[1] + tempArray[2])/0.3)/10;
- pressure = Math.round((pressureArray[0] + pressureArray[1] + pressureArray[2])/0.3)/10;
- w1temperature = Math.round((w1tempArray[0] + w1tempArray[1] + w1tempArray[2])/0.3)/10;
- console.log(pressure + ' ' + temperature + ' ' + w1temperature);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement